aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2025-09-16 13:26:24 -0300
committerRoberto I <roberto@inf.puc-rio.br>2025-09-16 13:26:24 -0300
commit140b672e2ee2ac842661ece4b48e1a64f0cd11ea (patch)
treeb925cd1e40712ab09a75ef2c0e30095aac0af0aa /testes
parent9ea06e61f20ae34974226074fc6123dbb54a07c2 (diff)
downloadlua-140b672e2ee2ac842661ece4b48e1a64f0cd11ea.tar.gz
lua-140b672e2ee2ac842661ece4b48e1a64f0cd11ea.tar.bz2
lua-140b672e2ee2ac842661ece4b48e1a64f0cd11ea.zip
Vararg table
Not yet optimized nor documented.
Diffstat (limited to 'testes')
-rw-r--r--testes/vararg.lua11
1 files changed, 7 insertions, 4 deletions
diff --git a/testes/vararg.lua b/testes/vararg.lua
index 10553de2..4320684e 100644
--- a/testes/vararg.lua
+++ b/testes/vararg.lua
@@ -3,9 +3,12 @@
3 3
4print('testing vararg') 4print('testing vararg')
5 5
6local function f (a, ...) 6local function f (a, ...=t)
7 local x = {n = select('#', ...), ...} 7 local x = {n = select('#', ...), ...}
8 for i = 1, x.n do assert(a[i] == x[i]) end 8 assert(x.n == t.n)
9 for i = 1, x.n do
10 assert(a[i] == x[i] and x[i] == t[i])
11 end
9 return x.n 12 return x.n
10end 13end
11 14
@@ -17,7 +20,7 @@ local function c12 (...)
17 return res, 2 20 return res, 2
18end 21end
19 22
20local function vararg (...) return {n = select('#', ...), ...} end 23local function vararg (...=t) return t end
21 24
22local call = function (f, args) return f(table.unpack(args, 1, args.n)) end 25local call = function (f, args) return f(table.unpack(args, 1, args.n)) end
23 26
@@ -99,7 +102,7 @@ assert(a==nil and b==nil and c==nil and d==nil and e==nil)
99 102
100 103
101-- varargs for main chunks 104-- varargs for main chunks
102local f = load[[ return {...} ]] 105local f = assert(load[[ return {...} ]])
103local x = f(2,3) 106local x = f(2,3)
104assert(x[1] == 2 and x[2] == 3 and x[3] == undef) 107assert(x[1] == 2 and x[2] == 3 and x[3] == undef)
105 108