lua-users home
lua-l archive

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

Being more specific about variable argument lists:

A function declared like "function f(a1, a2, ...)" has, besides a1 and a2,
an extra 'parameter' called "arg". The value of "arg" is always a table,
which has in fields 1,2,... the values of any extra arguments passed to
f, and a field 'n' with the number of extra arguments. For instance:

function f (a1, ...)
  -- control point xx

f(3, 5, 7)  -- at point xx, a1=3, arg={5, 7; n=2}
f()         -- at point xx, a1=nil, arg={n=0}
f('a')      -- at point xx, a1='a', arg={n=0}

There is also a pre-defined function "call", that receives a function and
a table, and calls the given function with the parameters given in the
table. More specifically, the expression

  call(f, {a1, a2, [...], an})    -- the [...] is meta-language

is equivalent to

  f(a1, a2, [...], an)  

And a declaration like

function f(...) return call(g, arg) end    -- the ... is language

makes 'f' equivalent to 'g'.

  These facilities are fully implemented in version 2.5, but still
undocumented. Probably they will become oficial in next release
(but please note, "probably").

-- Roberto