lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


"..." has two related meanings.  If used in a function's
list of formal parameters, it allows the function to take an
indefinite number of arguments (up to 200):

return function(...)

Such a function is called a vararg function.

"..." can also be used as an expression (but not a variable,
which is another kind of expression).  "..." used in this
way is called a vararg expression:

          return f1(f2(...)) --...treated as a variable! is it maze!

Vararg expressions were introduced in Lua 5.1.  They can
only be used if the enclosing function is a vararg function.

Like function calls, but unlike other expressions, vararg
expressions can evaluate to more -- or less -- than one
value, and are adjusted to one value in certain contexts.

function foo(...)
  print(type((...)))
  print(type(...))
end
foo(42, "ignored")
number
number
foo()
nil
stdin:3: bad argument #1 to 'type' (value expected)
stack traceback:
       [C]: in function 'type'
       stdin:3: in function 'foo'
       stdin:1: in main chunk
       [C]: ?

For more detail on multiple-valued expressions and their
adjustment, and on vararg functions and vararg expressions,
see:

 http://www.lua.org/manual/5.1/manual.html#2.5
 http://www.lua.org/manual/5.1/manual.html#2.5.9

--
Aaron
Beginning Lua Programming: http://www.amazon.com/gp/product/0470069171/