aboutsummaryrefslogtreecommitdiff
path: root/testes/vararg.lua
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2025-10-30 11:07:01 -0300
committerRoberto I <roberto@inf.puc-rio.br>2025-10-30 11:07:01 -0300
commitd342328e5b24c9b3c6c5b33bfcf9f8534210b8e6 (patch)
tree033163b79dc14b69fc8d7160ae38cf3d9181533d /testes/vararg.lua
parent0149b781d438091ce086449101a916e9b4456b4e (diff)
downloadlua-d342328e5b24c9b3c6c5b33bfcf9f8534210b8e6.tar.gz
lua-d342328e5b24c9b3c6c5b33bfcf9f8534210b8e6.tar.bz2
lua-d342328e5b24c9b3c6c5b33bfcf9f8534210b8e6.zip
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.
Diffstat (limited to 'testes/vararg.lua')
-rw-r--r--testes/vararg.lua22
1 files changed, 11 insertions, 11 deletions
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 @@
3 3
4print('testing vararg') 4print('testing vararg')
5 5
6local function f (a, ...|t) 6local function f (a, ...t)
7 local x = {n = select('#', ...), ...} 7 local x = {n = select('#', ...), ...}
8 assert(x.n == t.n) 8 assert(x.n == t.n)
9 for i = 1, x.n do 9 for i = 1, x.n do
@@ -20,7 +20,7 @@ local function c12 (...)
20 return res, 2 20 return res, 2
21end 21end
22 22
23local function vararg (... | t) return t end 23local function vararg (... t) return t end
24 24
25local 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
26 26
@@ -153,8 +153,8 @@ end
153 153
154 154
155do -- vararg parameter used in nested functions 155do -- vararg parameter used in nested functions
156 local function foo (... | tab1) 156 local function foo (...tab1)
157 return function (... | tab2) 157 return function (...tab2)
158 return {tab1, tab2} 158 return {tab1, tab2}
159 end 159 end
160 end 160 end
@@ -165,11 +165,11 @@ do -- vararg parameter used in nested functions
165end 165end
166 166
167do -- vararg parameter is read-only 167do -- vararg parameter is read-only
168 local st, msg = load("return function (... | t) t = 10 end") 168 local st, msg = load("return function (... t) t = 10 end")
169 assert(string.find(msg, "const variable 't'")) 169 assert(string.find(msg, "const variable 't'"))
170 170
171 local st, msg = load[[ 171 local st, msg = load[[
172 local function foo (... | extra) 172 local function foo (...extra)
173 return function (...) extra = nil end 173 return function (...) extra = nil end
174 end 174 end
175 ]] 175 ]]
@@ -179,19 +179,19 @@ end
179 179
180do -- _ENV as vararg parameter 180do -- _ENV as vararg parameter
181 local st, msg = load[[ 181 local st, msg = load[[
182 local function aux (... | _ENV) 182 local function aux (... _ENV)
183 global <const> a 183 global <const> a
184 a = 10 184 a = 10
185 end ]] 185 end ]]
186 assert(string.find(msg, "const variable 'a'")) 186 assert(string.find(msg, "const variable 'a'"))
187 187
188 local function aux (... | _ENV) 188 local function aux (..._ENV)
189 global a; a = 10 189 global a; a = 10
190 return a 190 return a
191 end 191 end
192 assert(aux() == 10) 192 assert(aux() == 10)
193 193
194 local function aux (... | _ENV) 194 local function aux (... _ENV)
195 global a = 10 195 global a = 10
196 return a 196 return a
197 end 197 end
@@ -200,7 +200,7 @@ end
200 200
201 201
202do -- access to vararg parameter 202do -- access to vararg parameter
203 local function notab (keys, t, ... | v) 203 local function notab (keys, t, ...v)
204 for _, k in pairs(keys) do 204 for _, k in pairs(keys) do
205 assert(t[k] == v[k]) 205 assert(t[k] == v[k])
206 end 206 end
@@ -216,7 +216,7 @@ do -- access to vararg parameter
216 assert(m == collectgarbage"count") 216 assert(m == collectgarbage"count")
217 217
218 -- writing to the vararg table 218 -- writing to the vararg table
219 local function foo (... | t) 219 local function foo (...t)
220 t[1] = t[1] + 10 220 t[1] = t[1] + 10
221 return t[1] 221 return t[1]
222 end 222 end