github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/runtime/lua/gc.quotas.lua (about) 1 local c = 0 2 local meta = {__gc = function() c = c + 1 end} 3 local function mk() 4 local t = {} 5 setmetatable(t, meta) 6 return t 7 end 8 9 -- Resource constraints forces finalizers to be called inside the context 10 runtime.callcontext({kill = {cpu = 1000000}}, function() 11 x = mk() 12 -- No resource constraints do not 13 runtime.callcontext({}, function() 14 y = mk() 15 end) 16 print(c) 17 --> =0 18 end) 19 print(c) 20 --> =2 21 22 23 local meta = {__gc = function(t) print(t.gc) end} 24 25 runtime.callcontext({kill={millis=1000}}, function() 26 local x = {gc = "local cx"} 27 setmetatable(x, meta) 28 local y = {gc = "local cy"} 29 setmetatable(y, meta) 30 local z = {gc = "local cz"} 31 setmetatable(z, meta) 32 print"leave" 33 end) 34 print"after" 35 --> =leave 36 --> =local cz 37 --> =local cy 38 --> =local cx 39 --> =after