From c1a63c45f8ec5932993c8cec40d3c5ec0743349c Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 25 Jun 2019 17:45:50 -0300 Subject: '__call' metamethod can be any callable object Removed the restriction that a '__call' metamethod must be an actual function. --- testes/calls.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'testes') 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 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) -- cgit v1.2.3-55-g6feb