moonbridge
changeset 271:30629973dcff
Make moonbridge_io.signalsocket(...) accept strings as argument
author | jbe |
---|---|
date | Sun Jun 04 20:12:56 2017 +0200 (2017-06-04) |
parents | fab22173abc8 |
children | 8b8be1a66a98 |
files | moonbridge_io.c reference.txt |
line diff
1.1 --- a/moonbridge_io.c Sun Jun 04 19:53:34 2017 +0200 1.2 +++ b/moonbridge_io.c Sun Jun 04 20:12:56 2017 +0200 1.3 @@ -65,6 +65,7 @@ 1.4 #define MOONBR_IO_CHILD_MT_REGKEY "moonbridge_io_child" 1.5 #define MOONBR_IO_CHILD_PT_REGKEY "moonbridge_io_child_pt" 1.6 #define MOONBR_IO_SIGNALSOCKET_REGKEY "moonbridge_io_signalsocket" 1.7 +#define MOONBR_IO_SIGNALS_REGKEY "moonbridge_io_signals" 1.8 1.9 #ifdef MOONBR_IO_USE_TLS 1.10 1.11 @@ -1626,9 +1627,22 @@ 1.12 luaL_error(L, "Could not create socket pair for signal queueing"); 1.13 } 1.14 } 1.15 + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_SIGNALS_REGKEY); 1.16 + lua_insert(L, 1); 1.17 argc = lua_gettop(L); 1.18 - for (i=1; i<=argc; i++) { 1.19 - sig = luaL_checkinteger(L, i); 1.20 + for (i=2; i<=argc; i++) { 1.21 + if (lua_type(L, i) == LUA_TSTRING) { 1.22 + lua_pushvalue(L, i); 1.23 + lua_gettable(L, 1); 1.24 + sig = lua_tointeger(L, -1); 1.25 + lua_pop(L, 1); 1.26 + if (!sig) { 1.27 + lua_pushvalue(L, i); 1.28 + luaL_error(L, "Unknown signal \"%s\"", lua_tostring(L, i)); 1.29 + } 1.30 + } else { 1.31 + sig = luaL_checkinteger(L, i); 1.32 + } 1.33 errno = 0; 1.34 signal(sig, moonbr_io_signalhandler); 1.35 if (errno) luaL_error(L, "Could not install signal handler (invalid signal number?)"); 1.36 @@ -2094,7 +2108,9 @@ 1.37 lua_pushinteger(L, SIGINFO); lua_setfield(L, -2, "INFO"); 1.38 lua_pushinteger(L, SIGUSR1); lua_setfield(L, -2, "USR1"); 1.39 lua_pushinteger(L, SIGUSR2); lua_setfield(L, -2, "USR2"); 1.40 - lua_setfield(L, -2, "signals"); 1.41 + lua_pushvalue(L, -1); 1.42 + lua_setfield(L, -3, "signals"); 1.43 + lua_setfield(L, LUA_REGISTRYINDEX, MOONBR_IO_SIGNALS_REGKEY); 1.44 1.45 luaL_setfuncs(L, moonbr_io_module_funcs, 0); 1.46 return 1;
2.1 --- a/reference.txt Sun Jun 04 19:53:34 2017 +0200 2.2 +++ b/reference.txt Sun Jun 04 20:12:56 2017 +0200 2.3 @@ -400,7 +400,8 @@ 2.4 2.5 This function installs a signal handler for the signals with the numbers passed 2.6 as arguments and returns a socket which receives a byte for each received 2.7 -signal. 2.8 +signal. Optionally, a string may be used instead of the signal number (e.g. 2.9 +"KILL" instead of 9, or "TERM" instead of 15). 2.10 2.11 Subsequent calls of this function can extend the set of signals but will always 2.12 return the same socket. If the socket is closed, it is no longer possible to