fin.lua (350B)
1 local setmetatable = require "__gc" 2 r={} 3 tm={} 4 count=0 5 tm.__gc=function(t) 6 count=count+1 7 if exiting then 8 assert(count==3) 9 print "looking good" 10 end 11 r=t -- resurrect 12 setmetatable(t, tm) -- and tell gc it resurrected 13 end 14 setmetatable(r, tm) 15 r=nil 16 collectgarbage("collect") 17 r=nil 18 collectgarbage("collect") 19 assert(count==2) 20 exiting=1 21 --os.exit()