diff options
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/vararg.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/testes/vararg.lua b/testes/vararg.lua index 4320684e..92f720cb 100644 --- a/testes/vararg.lua +++ b/testes/vararg.lua | |||
| @@ -150,5 +150,31 @@ do | |||
| 150 | local a, b = g() | 150 | local a, b = g() |
| 151 | assert(a == nil and b == 2) | 151 | assert(a == nil and b == 2) |
| 152 | end | 152 | end |
| 153 | |||
| 154 | |||
| 155 | do -- vararg parameter used in nested functions | ||
| 156 | local function foo (... = tab1) | ||
| 157 | return function (... = tab2) | ||
| 158 | return {tab1, tab2} | ||
| 159 | end | ||
| 160 | end | ||
| 161 | local f = foo(10, 20, 30) | ||
| 162 | local t = f("a", "b") | ||
| 163 | assert(t[1].n == 3 and t[1][1] == 10) | ||
| 164 | assert(t[2].n == 2 and t[2][1] == "a") | ||
| 165 | end | ||
| 166 | |||
| 167 | do -- vararg parameter is read-only | ||
| 168 | local st, msg = load("return function (... = t) t = 10 end") | ||
| 169 | assert(string.find(msg, "const variable 't'")) | ||
| 170 | |||
| 171 | local st, msg = load[[ | ||
| 172 | local function foo (... = extra) | ||
| 173 | return function (...) extra = nil end | ||
| 174 | end | ||
| 175 | ]] | ||
| 176 | assert(string.find(msg, "const variable 'extra'")) | ||
| 177 | end | ||
| 178 | |||
| 153 | print('OK') | 179 | print('OK') |
| 154 | 180 | ||
