[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: what is the syntax of DOTS?
From:       Roberto Ierusalimschy <roberto () inf ! puc-rio ! br>
Date:       1997-03-17 13:37:32
Message-ID: 9703171335.AA19168 () exu ! inf ! puc-rio ! br
[Download RAW message or body]

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
end

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic