[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Solution to catching signals without using Lua hooks
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Sun, 20 Jan 2008 01:29:35 -0700
I wrote a signal handler library for Lua a while ago, and it always
irked me that it was "difficult" to handle signals without corrupting
the Lua stack unless you used lua_sethook() (or so I thought). I've
recently tried making a new state via lua_newthread() and saving it to
the registry so it doesn't get collected. I've thus been able to have
a signal handler do this:
static lua_State *myL = NULL; /* set later */
static void handle(int sig)
{
lua_pushstring(myL, LUA_SIGNAL);
lua_gettable(myL, LUA_REGISTRYINDEX);
lua_pushnumber(myL, sig);
lua_gettable(myL, -2);
lua_call(myL, 0, 0);
}
When the library loads, myL is set to the new state returned by
lua_newthread(). I haven't run into any issues yet, but I wonder if
this solution has any problems or side effects I don't see? I'd
appreciate some input :)
Cheers,
--
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant