[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table.pack()
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 8 Feb 2010 19:17:42 -0200
> The table-argument-saving-in function that I'd like to see is the function
> that returns a table that is the equivalent of several tables in its
> argument concatenated.
Try this.
local function flatten(t,k,a)
for i=1,#a do
local v=a[i]
if type(v)=="table" then
k=flatten(t,k,a[i])
else
t[k]=v
k=k+1
end
end
return k
end
function table.flat(...)
local t={}
local n=select("#",...)
local k=1
for i=1,n do
k=flatten(t,k,select(i,...))
end
return t,k
end
local t=table.flat(
{
{10},
{21,22,23},
{31,32,{331,332,333},34},
{40}
})
for i=1,#t do
io.write(t[i] or i,' ')
end