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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user