lua-users home
lua-l archive

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


Matthias Gall wrote:
> 
> I just asked myself whether it's possible to have something like the vararg
> function for function results: a function returns a variable number of
> values. I would be happy about a short code snippet, if this feature is
> supported. I am using LUA 4.0.

Is this short enough? *g*

  function pack(...)
    return arg
  end


Example:

  function func1() return end
  function func2() return 1,"foo",3 end
  function func3() return {} end

  x = pack(func1())
  foreach(x, print)	--> n=0

  x = pack(func2())
  foreach(x, print)	--> n=3  [1]=1  [2]="foo"  [3]=3

  x = pack(func3())
  foreach(x, print)	--> n=1  [1]=table:xxx

Ciao, ET.