github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/runtime/lua/forin.lua (about) 1 -- Lua 5.4 introduces a 4th return value in the for in statement, which works as 2 -- a to be closed variable. 3 4 local foo = {} 5 setmetatable(foo, {__close=function() print"close foo" end}) 6 7 local r3 = function(s, i) 8 if i < 3 then return i + 1 else return nil end 9 end 10 11 for i in r3, nil, 0, foo do 12 print(i) 13 end 14 print"done" 15 --> =1 16 --> =2 17 --> =3 18 --> =close foo 19 --> =done