mirror of
https://github.com/lua/lua
synced 2026-09-29 04:35:58 +03:00
'__call' metamethod can be any callable object
Removed the restriction that a '__call' metamethod must be an actual function.
This commit is contained in:
parent
4487c28ced
commit
c1a63c45f8
2 changed files with 31 additions and 14 deletions
|
|
@ -151,6 +151,23 @@ end
|
|||
print('+')
|
||||
|
||||
|
||||
do -- testing chains of '__call'
|
||||
local N = 20
|
||||
local u = table.pack
|
||||
for i = 1, N do
|
||||
u = setmetatable({i}, {__call = u})
|
||||
end
|
||||
|
||||
local Res = u("a", "b", "c")
|
||||
|
||||
assert(Res.n == N + 3)
|
||||
for i = 1, N do
|
||||
assert(Res[i][1] == i)
|
||||
end
|
||||
assert(Res[N + 1] == "a" and Res[N + 2] == "b" and Res[N + 3] == "c")
|
||||
end
|
||||
|
||||
|
||||
a = nil
|
||||
(function (x) a=x end)(23)
|
||||
assert(a == 23 and (function (x) return x*2 end)(20) == 40)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue