Skip to content

Instantly share code, notes, and snippets.

@Version2beta
Created May 21, 2014 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Version2beta/fe004948debda94ba6b1 to your computer and use it in GitHub Desktop.
Save Version2beta/fe004948debda94ba6b1 to your computer and use it in GitHub Desktop.
Lua 5.1 hack on __gc
> -- collected from #lua user q66
> foo = newproxy(true)
> getmetatable(foo).__gc = function() print("o hai!") end
> foo = nil
> collectgarbage()
o hai!
> foo = {}
> foo.__my_gc_thingy = newproxy(true)
> getmetatable(foo.__my_gc_thingy).__gc = function() print("collectin' a table") end
> foo = nil
> collectgarbage()
collectin' a table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment