diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-25 17:45:50 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-25 17:45:50 -0300 |
| commit | c1a63c45f8ec5932993c8cec40d3c5ec0743349c (patch) | |
| tree | a61e8edb10b498c25e961cd7b2c7cb857e9db4c7 /testes | |
| parent | 4487c28ced3dcf47c3ee19b6f6eeb0089ec64ba5 (diff) | |
| download | lua-c1a63c45f8ec5932993c8cec40d3c5ec0743349c.tar.gz lua-c1a63c45f8ec5932993c8cec40d3c5ec0743349c.tar.bz2 lua-c1a63c45f8ec5932993c8cec40d3c5ec0743349c.zip | |
'__call' metamethod can be any callable object
Removed the restriction that a '__call' metamethod must be an actual
function.
Diffstat (limited to 'testes')
| -rw-r--r-- | testes/calls.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/testes/calls.lua b/testes/calls.lua index 56a12ae6..739a624f 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
| @@ -151,6 +151,23 @@ end | |||
| 151 | print('+') | 151 | print('+') |
| 152 | 152 | ||
| 153 | 153 | ||
| 154 | do -- testing chains of '__call' | ||
| 155 | local N = 20 | ||
| 156 | local u = table.pack | ||
| 157 | for i = 1, N do | ||
| 158 | u = setmetatable({i}, {__call = u}) | ||
| 159 | end | ||
| 160 | |||
| 161 | local Res = u("a", "b", "c") | ||
| 162 | |||
| 163 | assert(Res.n == N + 3) | ||
| 164 | for i = 1, N do | ||
| 165 | assert(Res[i][1] == i) | ||
| 166 | end | ||
| 167 | assert(Res[N + 1] == "a" and Res[N + 2] == "b" and Res[N + 3] == "c") | ||
| 168 | end | ||
| 169 | |||
| 170 | |||
| 154 | a = nil | 171 | a = nil |
| 155 | (function (x) a=x end)(23) | 172 | (function (x) a=x end)(23) |
| 156 | assert(a == 23 and (function (x) return x*2 end)(20) == 40) | 173 | assert(a == 23 and (function (x) return x*2 end)(20) == 40) |
