luaclass: Allow Lua to listen to global signal connections.
This is the successor of `awful.screen.connect_for_each_screen`-like functions using the signal system itself "meta signals?". For signals such as requests that need to be fullfilled at startup, the previous API didn't "feel" native. Now it is possible for Lua to react to global signal connections and call the handler itself. This is intended to be used as a building block of a consistency refactoring. It could eventually be extended with an ugly global `block_next_connection`. To allow filtering for signals that can only have a single connection. So far it isn't required, so lets not polute this patch with such hack.
This commit is contained in:
parent
df0cdbed61
commit
1259adc078
|
@ -22,6 +22,8 @@
|
|||
#include "common/luaclass.h"
|
||||
#include "common/luaobject.h"
|
||||
|
||||
#define CONNECTED_SUFFIX "::connected"
|
||||
|
||||
struct lua_class_property
|
||||
{
|
||||
/** Name of the property */
|
||||
|
@ -300,6 +302,24 @@ luaA_class_connect_signal_from_stack(lua_State *L, lua_class_t *lua_class,
|
|||
const char *name, int ud)
|
||||
{
|
||||
luaA_checkfunction(L, ud);
|
||||
|
||||
/* Duplicate the function in the stack */
|
||||
lua_pushvalue(L, ud);
|
||||
|
||||
char *buf = p_alloca(char, a_strlen(name) + a_strlen(CONNECTED_SUFFIX) + 1);
|
||||
|
||||
/* Create a new signal to notify there is a global connection. */
|
||||
sprintf(buf, "%s%s", name, CONNECTED_SUFFIX);
|
||||
|
||||
/* Emit a signal to notify Lua of the global connection.
|
||||
*
|
||||
* This can useful during initialization where the signal needs to be
|
||||
* artificially emitted for existing objects as soon as something connects
|
||||
* to it
|
||||
*/
|
||||
luaA_class_emit_signal(L, lua_class, buf, 1);
|
||||
|
||||
/* Register the signal to the CAPI list */
|
||||
signal_connect(&lua_class->signals, name, luaA_object_ref(L, ud));
|
||||
}
|
||||
|
||||
|
@ -512,4 +532,6 @@ luaA_class_new(lua_State *L, lua_class_t *lua_class)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#undef CONNECTED_SUFFIX
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||
|
|
Loading…
Reference in New Issue