lua-users home
lua-l archive

Re: Hooking into garbage collection

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 28.12.2013 03:41 schröbte Sean Conner:
	local mt =
	{
	 __gc = function(u)
	 call_magic_cleanup_stuff()
	 setmetatable({},getmetatable(u))
	 end
	}
	setmetatable({},mt)
Doing this for Lua 5.1 is not quite as easy, as you need to use a userdata
object (say, a pointer to int) instead of a Lua table, but the concept is
the same.
Lua 5.1 had `newproxy` for that. E.g.:
 local sentinel = newproxy and newproxy( true )
 or setmetatable( {}, { __gc = true } )
 getmetatable( sentinel ).__gc = function() writecache( c ) end
 -spc
Philipp

AltStyle によって変換されたページ (->オリジナル) /