Skip to content

Instantly share code, notes, and snippets.

@katlogic
Forked from SoniEx2/52emu.lua
Created September 26, 2015 19:21
Show Gist options
  • Save katlogic/94c61fb4261cb805b046 to your computer and use it in GitHub Desktop.
Save katlogic/94c61fb4261cb805b046 to your computer and use it in GitHub Desktop.
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
t=nil
for i=1,10 do collectgarbage("collect") end
os.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment