Functions with a variable number of arguments
Posted: Thu Oct 08, 2015 2:03 am
So in Lua, if I want to make a function accept a variable number of arguments, the way I learned to do this was by using ... in the function heading and using the variable "arg" to reference all the arguments in a table. For instance, a completely redundant print function:
function print2(...)
print(unpack(arg))
end
However, within Love it seems that the variable "arg" is by default defined as the location of the main.lua file, even when the ... isn't used anywhere. When I set arg = nil, it remains nil even within a function with the ... . Is there any way to get around this and be able to define a function with a variable number of arguments in Love with ..., or is there an entirely different way to do this by chance?
function print2(...)
print(unpack(arg))
end
However, within Love it seems that the variable "arg" is by default defined as the location of the main.lua file, even when the ... isn't used anywhere. When I set arg = nil, it remains nil even within a function with the ... . Is there any way to get around this and be able to define a function with a variable number of arguments in Love with ..., or is there an entirely different way to do this by chance?