Last active
October 2, 2015 11:42
-
-
Save katlogic/1f5f358aa7e61c15378f 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
| 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