lua-users home
lua-l archive

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


Use call
Foo (var1, unpack({var2, "var3"}))

or use
function Foo( firstvar, tablevar)
local v1, v2 = tablevar[1], tablevar[2]


----- Original Message ----- From: Colm Sloan
To: Lua list
Sent: Sunday, September 20, 2009 12:00 AM
Subject: Passing table as vararg ( newbie question )


I just want to get access to var2 and var3.


Foo ( var1,
{ var2, "var3" }
)


function Foo( firstvar, ... )
local v1, v2 = ... -- says that v1 (var2) is a table :(


-- test to see how deep this table goes
-- causes infinite loop
local table1 = ...
while ( type( table1 ) == "table" ) do
local x, y = table1
table1 = x
print( "\nanother table" )
end
end


What's going on here? Why can't I access var2 and var3? I'm sure I'm making some simple mistake. I tried {{table1}} but that made no difference. Any ideas?