lua-users home
lua-l archive

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


--- Andy Bushnell wrote:
> Say I have a table t = {6,7,8} and this is what I want to pass to
a function.
> This func will pass t on to another func and so on (ie a number
of times).
> 
> How do I get one of the funcs to modify its passed-in vararg
tables so that
> it sets arg[2] from (what was) 7 to (say) 9. Having done this
when it passes
> the arg table onto another func - the called func should get a
table with {
> 6,9,8 } as a param.

This is where you would use that 'unpack' function you were
wondering about earlier. Unpack simply returns every value in a
list:

t = {6, 7, 8}
a, b, c = unpack(t)
print(a, b, c) -- output:  6   7   8

So you can pass a vararg list to another vararg function by
unpacking it:

function a(...)
  print(unpack(arg))
end

function b(...)
  arg[2] = 9
  a(unpack(arg))
end

b(6,7,8)


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com