__gc.lua (602B)
1 2 if _VERSION == "Lua 5.1" then 3 local rg = assert(rawget) 4 local proxy_key = rg(_G, "__GC_PROXY") or "__gc_proxy" 5 local rs = assert(rawset) 6 local gmt = assert(debug.getmetatable) 7 local smt = assert(setmetatable) 8 local np = assert(newproxy) 9 10 return function(t, mt) 11 if rg(mt, "__gc") and not rg(t,"__gc_proxy") then 12 local p = np(true) 13 rs(t, proxy_key, p) 14 gmt(p).__gc = function() 15 rs(t, proxy_key, nil) 16 local nmt = gmt(t) 17 if not nmt then return end 18 local fin = rg(nmt, "__gc") 19 if fin then return fin(t) end 20 end 21 end 22 return smt(t,mt) 23 end 24 end 25 26 return setmetatable