Skip to content

Instantly share code, notes, and snippets.

@SoniEx2
Forked from katlogic/52emu.lua
Created September 26, 2015 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SoniEx2/971cc72004577a27b237 to your computer and use it in GitHub Desktop.
Save SoniEx2/971cc72004577a27b237 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
@SoniEx2
Copy link
Author

SoniEx2 commented Sep 26, 2015

If I remove t=nil and add print(t) after the loop I get this:

(note the second call to print(t) happens before the calls to __gc)

Program starting as '"/home/soniex2/zbs/bin/linux/x64/luajit" -e "io.stdout:setvbuf('no')" "/home/soniex2/git/github/lua/LJPlus/test.lua"'.
Program 'luajit' started in '/home/soniex2/git/github/lua/LJPlus' (pid: 8930).
table: 0x406142a8
table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
got call, now resurrecting  table: 0x406142a8
ERROR: ld.so: object '/home/soniex2/.local/share/Steam/ubuntu12_32/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
Program completed in 0.02 seconds (pid: 8930).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment