From d342328e5b24c9b3c6c5b33bfcf9f8534210b8e6 Mon Sep 17 00:00:00 2001 From: Roberto I Date: Thu, 30 Oct 2025 11:07:01 -0300 Subject: 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. --- testes/locals.lua | 4 ++-- testes/memerr.lua | 4 ++-- testes/vararg.lua | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'testes') diff --git a/testes/locals.lua b/testes/locals.lua index 5222802f..6cd10547 100644 --- a/testes/locals.lua +++ b/testes/locals.lua @@ -310,7 +310,7 @@ do -- testing presence of second argument local function foo (howtoclose, obj, n) local ca -- copy of 'a' visible inside its close metamethod do - local a = func2close(function (... | t) + local a = func2close(function (...t) assert(select("#", ...) == n) assert(t.n == n and t[1] == ca and (t.n < 2 or t[2] == obj)) ca = 15 -- final value to be returned if howtoclose=="scope" @@ -910,7 +910,7 @@ do local extrares -- result from extra yield (if any) - local function check (body, extra, ...|t) + local function check (body, extra, ...t) local co = coroutine.wrap(body) if extra then extrares = co() -- runs until first (extra) yield diff --git a/testes/memerr.lua b/testes/memerr.lua index 69d2ef85..2cc8f481 100644 --- a/testes/memerr.lua +++ b/testes/memerr.lua @@ -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 diff --git a/testes/vararg.lua b/testes/vararg.lua index 840c3eee..a01598ff 100644 --- a/testes/vararg.lua +++ b/testes/vararg.lua @@ -3,7 +3,7 @@ print('testing vararg') -local function f (a, ...|t) +local function f (a, ...t) local x = {n = select('#', ...), ...} assert(x.n == t.n) for i = 1, x.n do @@ -20,7 +20,7 @@ local function c12 (...) return res, 2 end -local function vararg (... | t) return t end +local function vararg (... t) return t end local call = function (f, args) return f(table.unpack(args, 1, args.n)) end @@ -153,8 +153,8 @@ end do -- vararg parameter used in nested functions - local function foo (... | tab1) - return function (... | tab2) + local function foo (...tab1) + return function (...tab2) return {tab1, tab2} end end @@ -165,11 +165,11 @@ do -- vararg parameter used in nested functions end do -- vararg parameter is read-only - local st, msg = load("return function (... | t) t = 10 end") + local st, msg = load("return function (... t) t = 10 end") assert(string.find(msg, "const variable 't'")) local st, msg = load[[ - local function foo (... | extra) + local function foo (...extra) return function (...) extra = nil end end ]] @@ -179,19 +179,19 @@ end do -- _ENV as vararg parameter local st, msg = load[[ - local function aux (... | _ENV) + local function aux (... _ENV) global a a = 10 end ]] assert(string.find(msg, "const variable 'a'")) - local function aux (... | _ENV) + local function aux (..._ENV) global a; a = 10 return a end assert(aux() == 10) - local function aux (... | _ENV) + local function aux (... _ENV) global a = 10 return a end @@ -200,7 +200,7 @@ end do -- access to vararg parameter - local function notab (keys, t, ... | v) + local function notab (keys, t, ...v) for _, k in pairs(keys) do assert(t[k] == v[k]) end @@ -216,7 +216,7 @@ do -- access to vararg parameter assert(m == collectgarbage"count") -- writing to the vararg table - local function foo (... | t) + local function foo (...t) t[1] = t[1] + 10 return t[1] end -- cgit v1.2.3-55-g6feb