I'm trying to call a function in Lua that accepts multiple 'number' arguments
function addShape(x1, y1, x2, y2 ... xn, yn)
and I have a table of values which I'd like to pass as arguments
values = {1, 1, 2, 2, 3, 3}
Is it possible to dynamically 'unpack' (I'm not sure if this is the right term) these values in the function call? Something like..
object:addShape(table.unpack(values))
Equivalent to calling:
object:addShape(1, 1, 2, 2, 3, 3)
Apologies if this is a totally obvious Lua question, but I can't for the life of me find anything on the topic.
UPDATE
unpack(values)
doesn't work either (delving into the method addShape(...)
and checking the type of the value passed reveals that unpack
is resulting in a single string
.
unpack
but this does not work either - the type of the argument being passed becomes a singlestring
– Fascinate