Reputation: 270
I've been searching through the documentation and through various questions, but I have not seen a plain answer to this question. What types of values can be passed to Lua functions as arguments?
I believe the answer is:
What I am looking for is a comprehensive list of what all can be passed into a function.
Upvotes: 2
Views: 148
Reputation: 20772
In addition to passing any value as an argument, there is also an argument that is not a value: ...
, the "vararg expression."
It can only be used in the body of a function where it is a formal parameter. When used at the end of a list, it expands the list with all of the actual arguments it represents. When used before the end of a list, it expands the list only with the first actual argument it represents.
local function f(a, b, ...)
print("f", a, b, ..., "end")
end
local function g(x, y, ...)
print( "g", x, y, ...)
end
f()
f(1)
f(1,2)
f(1,2,3)
f(1,2,3,4)
f(1,2,3,4,5)
g()
g(1)
g(1,2)
g(1,2,3)
g(1,2,3,4)
g(1,2,3,4,5)
Upvotes: 1
Reputation: 72312
From the Lua reference manual:
All values in Lua are first-class values. This means that all values can be stored in variables, passed as arguments to other functions, and returned as results.
Upvotes: 4