__gc for tables in Lua 5.1 and LuaJIT
$ luarocks install --server=https://luarocks.org/dev __gc
This is a dead-simple setmetatable() wrapper. It injects a newproxy() key directly into objects. So be careful if you use pairs().
root