Vertical bar removed from syntax of vararg table

The syntax 'function foo (a, b, ...arg)' is already used by JavaScript
for this same semantics, so it seems natural to use the same notation in
Lua.
This commit is contained in:
Roberto I
2025-10-30 11:07:01 -03:00
parent 0149b781d4
commit d342328e5b
5 changed files with 20 additions and 22 deletions

View File

@@ -126,13 +126,13 @@ testamem("coroutine creation", function()
end)
do -- vararg tables
local function pack (... | t) return t end
local function pack (...t) return t end
local b = testamem("vararg table", function ()
return pack(10, 20, 30, 40, "hello")
end)
assert(b.aloc == 3) -- new table uses three memory blocks
-- table optimized away
local function sel (n, ...|arg) return arg[n] + arg.n end
local function sel (n, ...arg) return arg[n] + arg.n end
local b = testamem("optimized vararg table",
function () return sel(2.0, 20, 30) end)
assert(b.res == 32 and b.aloc == 0) -- no memory needed for this case