[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to implement cleaning function ( atexit() like )
- From: Graham Wakefield <wakefield@...>
- Date: Wed, 17 Apr 2013 11:22:53 +0900
Note that this doesn't work for Lua 5.1, because tables do not invoke __gc metamethods.
For Lua 5.1 a workaround is to use newproxy():
http://lua-users.org/wiki/HiddenFeatures
E.g.:
t = newproxy(true)
getmetatable(t).__gc = function() print("bye bye t") end
-- later:
t = nil
collectgarbage()
collectgarbage()
The same newproxy() method is available in LuaJIT, or you could use an ffi metatype instead.
On Apr 4, 2013, at 8:38 PM, Luiz Henrique de Figueiredo wrote:
>> 2/ how can I implement atexit like stuff in Lua ?
>
> Set a gc metamethod for a table that is keep safely in a global variable.
>
>> 3/ is this function called even when the daemon will receive a SIGQUIT
>> signal ?
>
> The standard Lua interpreter does not handle SIGQUIT. You can either
> change it or use your own Lua host. You can also try to do signal
> handling using luaposix.
>