lua-users home
lua-l archive

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

>From the manual / basic library:

unpack (list)
Returns all elements from the given list. This function is equivalent to
  return list[1], list[2], ..., list[n]

except that the above code can be written only for a fixed n. The number n
is the size of the list, as defined for the table.getn function.

It looks like you cannot write it yourself with a variable size of the
However you can use unpack since it does what you want anyways.

----- Original Message ----- 
From: "Ariel Manzur" <>
To: <>
Sent: Sunday, August 24, 2003 7:46 AM
Subject: turning a table into a list?

> Hi..
> Is it possible to turn a table into a list, from within lua? I have a lot
> of functions that take 3 or 4 numbers as parameters, and a lot of data on
> tables like {1, 2, 3}, so I made a function that turns the table into a
> list, like this:
> function list(t)
>          return t[1], t[2], t[3]
> end
> to be able to call the functions using list, like 'function(list(t))'
> listead of 'function(t[1], t[2], t[3])' (yes, this works). Anyway, is it
> possible to do the same, but with a tables of variable size? I suppose
> wouldn't be too hard to do using the C API, but is it possible to do from
> Thanks..
> Ariel.
> Ariel.
> snm