diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2025-10-30 11:07:01 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2025-10-30 11:07:01 -0300 |
| commit | d342328e5b24c9b3c6c5b33bfcf9f8534210b8e6 (patch) | |
| tree | 033163b79dc14b69fc8d7160ae38cf3d9181533d /testes/vararg.lua | |
| parent | 0149b781d438091ce086449101a916e9b4456b4e (diff) | |
| download | lua-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.lua | 22 |
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 | ||
| 4 | print('testing vararg') | 4 | print('testing vararg') |
| 5 | 5 | ||
| 6 | local function f (a, ...|t) | 6 | local 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 |
| 21 | end | 21 | end |
| 22 | 22 | ||
| 23 | local function vararg (... | t) return t end | 23 | local function vararg (... t) return t end |
| 24 | 24 | ||
| 25 | local call = function (f, args) return f(table.unpack(args, 1, args.n)) end | 25 | local call = function (f, args) return f(table.unpack(args, 1, args.n)) end |
| 26 | 26 | ||
| @@ -153,8 +153,8 @@ end | |||
| 153 | 153 | ||
| 154 | 154 | ||
| 155 | do -- vararg parameter used in nested functions | 155 | do -- 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 | |||
| 165 | end | 165 | end |
| 166 | 166 | ||
| 167 | do -- vararg parameter is read-only | 167 | do -- 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 | ||
| 180 | do -- _ENV as vararg parameter | 180 | do -- _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 | ||
| 202 | do -- access to vararg parameter | 202 | do -- 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 |
