From 4cf498210e6a60637a7abb06d32460ec21efdbdc Mon Sep 17 00:00:00 2001 From: Roberto I Date: Tue, 11 Nov 2025 15:11:06 -0300 Subject: '__pairs' can also return a to-be-closed object --- testes/nextvar.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'testes') diff --git a/testes/nextvar.lua b/testes/nextvar.lua index 7e5bed56..098e7891 100644 --- a/testes/nextvar.lua +++ b/testes/nextvar.lua @@ -905,13 +905,18 @@ local function foo1 (e,i) if i <= e.n then return i,a[i] end end -setmetatable(a, {__pairs = function (x) return foo, x, 0 end}) +local closed = false +setmetatable(a, {__pairs = function (x) + local tbc = setmetatable({}, {__close = function () closed = true end}) + return foo, x, 0, tbc + end}) local i = 0 for k,v in pairs(a) do i = i + 1 assert(k == i and v == k+1) end +assert(closed) -- 'tbc' has been closed a.n = 5 a[3] = 30 -- cgit v1.2.3-55-g6feb