Altering values in passed variable number of arguments in functions

The only place where a literal value can be used is as a value to be assigned to a variable. Think

local a, b, c, d, e = {...}, {1, 2}, "test", 10, nil

That means you can’t e.g. call functions on or index literal values. This is nothing specific to varargs or the ... operator. E.g.:

"swag":len()
{1, 2, 3}[1] = nil

errors because they’re not valid expressions, while

local a = "swag"
a:len()
local t = {1, 2, 3}
t[1] = nil

works fine.

If you want to dig deeper into the “why” rabbithole, check out the precise grammar of the language at

Lua 5.1 Reference Manual and
Lua 5.1 Reference Manual

1 Like