My question is how (or if) you can insert two values into a lua table.
I got a function that returns (a variable number of values)
function a(x, y)
return x, y
end
and another function that inserts that points into a table,
function b(x, y)
table.insert(myTable, x, y)
end
So how can i make, that i can call function b with a variable number of arguments and insert them all into my table?
If the last parameter for your function is
...(called a vararg function), the Lua interpreter will place any extra arguments into.... You can convert it to a table using{...}and copy the keys/values into your global table namedmyTable. Here’s what your function would look like:You should tweak the function depending on whether you want to replace, merge or append elements into
myTable.