[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Bugs and questions
- From: "Luiz Carlos Silveira" <luiz@...>
- Date: Fri, 12 May 2000 17:15:32 -0300
try this example.
i don?t know if concatenating all these strings is faster than recursion, but...
tbl = {'param1', 'param2', 'param3', 'param4', 'param5'}
_unpack = nil
function unpack(t)
local unpack_str
for i=1,getn(t) do
if (unpack_str) then
unpack_str = unpack_str..", _unpack["..i.."]"
else
unpack_str = "_unpack["..i.."]"
end
end
_unpack = t
return dostring("return "..unpack_str)
end
a, b, c, d, e = unpack(tbl)
print(a, b, c, d, e)
-----Original Message-----
From: lua-l@tecgraf.puc-rio.br [mailto:lua-l@tecgraf.puc-rio.br]On
Behalf Of Roberto Ierusalimschy
Sent: Friday, May 12, 2000 3:13 PM
To: Multiple recipients of list
Subject: Re: Bugs and questions
> Is there a better way to do this ? (I would like to avoid the
> recursion's overhead and to destroy the table)
I don't know how to avoid the recursion, but you can keep the table intact:
function unpack (t, i)
i = i or 1
if (i <= getn(t)) then
return t[i], unpack(t, i+1)
end
end
-- Roberto