Skip to content

Instantly share code, notes, and snippets.

@katlogic
Last active October 2, 2015 11:42
Show Gist options
  • Select an option

  • Save katlogic/1f5f358aa7e61c15378f to your computer and use it in GitHub Desktop.

Select an option

Save katlogic/1f5f358aa7e61c15378f to your computer and use it in GitHub Desktop.
r={}
tm={}
function setmetatable52(t,mt)
if rawget(mt,"__gc") and not rawget(t,"__gc_proxy") then
local p = newproxy(true)
rawset(t,"__gc_proxy", p)
debug.getmetatable(p).__gc=function()
rawset(t,"__gc_proxy",nil)
local nmt = debug.getmetatable(t)
if not nmt then return end
local fin = rawget(nmt,"__gc")
if not fin then return end
fin(t)
end
end
setmetatable(t,mt)
end
tm.__gc=function(t)
print('fin!')
r=t -- resurrect
setmetatable52(t, tm) -- and tell gc it resurrected
end
setmetatable52(r, tm)
r=nil
collectgarbage("collect")
r=nil
collectgarbage("collect")
os.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment