3

Possible Duplicate:
in Lua, how can I use a table as varargs (…)?

I'd like to do something similar to the following and I was wondering if it is at all possible with lua?

fun = function()
    some_table = {1,2,3}
    -- some dark magic here
    return 1,2,3
end

a, b, c = fun()

How to convert {1,2,3} to 1,2,3 for just returning from the function?

Thanks

Community
  • 1
  • 1
aignas
  • 1,044
  • 12
  • 19

1 Answers1

8

Use unpack() (renamed to table.unpack in Lua 5.2):

fun = function()
  some_table = {1,2,3}
  return (table.unpack or unpack)(some_table)
end
print(fun())

will print 1 2 3.

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56