-
-
Save SoniEx2/971cc72004577a27b237 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local track={} | |
setmetatable(track,{__mode="v"}) | |
function setmetatable52(t,mt) | |
if mt.__gc then | |
local p = newproxy(true) | |
track[p] = t | |
getmetatable(p).__gc = function(p) | |
local mt = debug.getmetatable(t) | |
if mt and rawget(mt, "__gc") then | |
rawget(mt, "__gc")(t) | |
end | |
end | |
end | |
setmetatable(t,mt) | |
end | |
t={} | |
print(t) | |
m={__gc=function(tt) | |
print('got call, now resurrecting',tt) | |
t=tt | |
setmetatable52(tt,m) | |
end} | |
setmetatable52(t,m) | |
t=nil | |
for i=1,10 do collectgarbage("collect") end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I remove
t=nil
and addprint(t)
after the loop I get this:(note the second call to print(t) happens before the calls to __gc)