lua-users home
lua-l archive

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

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.."]"
			unpack_str = "_unpack["..i.."]"
	_unpack = t
	return dostring("return "..unpack_str)

a, b, c, d, e = unpack(tbl)
print(a, b, c, d, e)

-----Original Message-----
From: []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)

-- Roberto