aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2025-11-11 15:11:06 -0300
committerRoberto I <roberto@inf.puc-rio.br>2025-11-11 15:11:06 -0300
commit4cf498210e6a60637a7abb06d32460ec21efdbdc (patch)
tree7b9cffee61083a6b256311917019b58a1fbdd42a /testes
parent5b7d9987642f72d44223a8e5e79e013bb2b3d579 (diff)
downloadlua-master.tar.gz
lua-master.tar.bz2
lua-master.zip
'__pairs' can also return a to-be-closed objectHEADmaster
Diffstat (limited to 'testes')
-rw-r--r--testes/nextvar.lua7
1 files changed, 6 insertions, 1 deletions
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)
905 if i <= e.n then return i,a[i] end 905 if i <= e.n then return i,a[i] end
906end 906end
907 907
908setmetatable(a, {__pairs = function (x) return foo, x, 0 end}) 908local closed = false
909setmetatable(a, {__pairs = function (x)
910 local tbc = setmetatable({}, {__close = function () closed = true end})
911 return foo, x, 0, tbc
912 end})
909 913
910local i = 0 914local i = 0
911for k,v in pairs(a) do 915for k,v in pairs(a) do
912 i = i + 1 916 i = i + 1
913 assert(k == i and v == k+1) 917 assert(k == i and v == k+1)
914end 918end
919assert(closed) -- 'tbc' has been closed
915 920
916a.n = 5 921a.n = 5
917a[3] = 30 922a[3] = 30