lua-users home
lua-l archive

Re: Using unpack() twice in a single function call

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


Hugo wrote:
 F(unpack(a), unpack(b))
Is there any way to use more than one unpack() in a single
function call?
As Andreas pointed out, everything but the last expression
gets adjusted to one value.
You might find something like this useful:
-- Like unpack, but accepts multiple arguments:
function multunpack(...)
 local ret = {}
 for i = 1, select("#", ...) do
 for _, rec in ipairs(select(i, ...)) do
 ret[#ret + 1] = rec
 end -- _, rec
 end -- i
 return unpack(ret)
end -- multunpack
print(multunpack({23, 45}, {-1, -2}))
23 45 -1 -2
--
Aaron

AltStyle によって変換されたページ (->オリジナル) /