Deprecate signal_add() on C-API objects
This commit makes the code automatically add signals when they are first used. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
e5f9ec4723
commit
a964396771
|
@ -34,13 +34,6 @@
|
||||||
int len, size; \
|
int len, size; \
|
||||||
} pfx##_array_t;
|
} pfx##_array_t;
|
||||||
|
|
||||||
#define ARRAY_TYPE_EXTRA(type_t, pfx, extra) \
|
|
||||||
typedef struct pfx##_array_t { \
|
|
||||||
type_t *tab; \
|
|
||||||
int len, size; \
|
|
||||||
extra; \
|
|
||||||
} pfx##_array_t;
|
|
||||||
|
|
||||||
#define foreach(var, array) \
|
#define foreach(var, array) \
|
||||||
for(int __foreach_index_##var = 0; \
|
for(int __foreach_index_##var = 0; \
|
||||||
__foreach_index_##var < (array).len; \
|
__foreach_index_##var < (array).len; \
|
||||||
|
|
|
@ -256,9 +256,6 @@ luaA_class_setup(lua_State *L, lua_class_t *class,
|
||||||
|
|
||||||
signal_add(&class->signals, "new");
|
signal_add(&class->signals, "new");
|
||||||
|
|
||||||
if (parent)
|
|
||||||
class->signals.inherits_from = &parent->signals;
|
|
||||||
|
|
||||||
lua_class_array_append(&luaA_classes, class);
|
lua_class_array_append(&luaA_classes, class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ luaA_checkudataornil(lua_State *L, int udx, lua_class_t *class)
|
||||||
static inline int \
|
static inline int \
|
||||||
luaA_##prefix##_class_add_signal(lua_State *L) \
|
luaA_##prefix##_class_add_signal(lua_State *L) \
|
||||||
{ \
|
{ \
|
||||||
signal_add(&(lua_class).signals, luaL_checkstring(L, 1)); \
|
luaA_deprecate(L, "signal usage without add_signal()"); \
|
||||||
return 0; \
|
return 0; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
|
|
@ -253,8 +253,7 @@ signal_object_emit(lua_State *L, signal_array_t *arr, const char *name, int narg
|
||||||
lua_remove(L, - nargs - nbfunc - 1 + i);
|
lua_remove(L, - nargs - nbfunc - 1 + i);
|
||||||
luaA_dofunction(L, nargs, 0);
|
luaA_dofunction(L, nargs, 0);
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
luaA_warn(L, "Trying to emit unknown signal '%s'", name);
|
|
||||||
|
|
||||||
/* remove args */
|
/* remove args */
|
||||||
lua_pop(L, nargs);
|
lua_pop(L, nargs);
|
||||||
|
@ -304,9 +303,6 @@ luaA_object_emit_signal(lua_State *L, int oud,
|
||||||
lua_remove(L, - nargs - nbfunc - 2 + i);
|
lua_remove(L, - nargs - nbfunc - 2 + i);
|
||||||
luaA_dofunction(L, nargs + 1, 0);
|
luaA_dofunction(L, nargs + 1, 0);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
luaA_warn(L, "Trying to emit unknown signal '%s'", name);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Then emit signal on the class */
|
/* Then emit signal on the class */
|
||||||
|
|
|
@ -175,7 +175,6 @@ int luaA_object_emit_signal_simple(lua_State *);
|
||||||
lua_setmetatable(L, -2); \
|
lua_setmetatable(L, -2); \
|
||||||
luaA_setuservalue(L, -2); \
|
luaA_setuservalue(L, -2); \
|
||||||
lua_pushvalue(L, -1); \
|
lua_pushvalue(L, -1); \
|
||||||
p->signals.inherits_from = &(lua_class).signals; \
|
|
||||||
luaA_class_emit_signal(L, &(lua_class), "new", 1); \
|
luaA_class_emit_signal(L, &(lua_class), "new", 1); \
|
||||||
return p; \
|
return p; \
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,54 +45,18 @@ signal_wipe(signal_t *sig)
|
||||||
cptr_array_wipe(&sig->sigfuncs);
|
cptr_array_wipe(&sig->sigfuncs);
|
||||||
}
|
}
|
||||||
|
|
||||||
ARRAY_TYPE_EXTRA(signal_t, signal, struct signal_array_t *inherits_from)
|
DO_BARRAY(signal_t, signal, signal_wipe, signal_cmp)
|
||||||
BARRAY_FUNCS(signal_t, signal, signal_wipe, signal_cmp)
|
|
||||||
|
|
||||||
static inline signal_t *
|
static inline signal_t *
|
||||||
signal_array_getbyid(signal_array_t *arr, unsigned long id)
|
signal_array_getbyid(signal_array_t *arr, unsigned long id)
|
||||||
{
|
{
|
||||||
signal_t sig = { .id = id };
|
signal_t sig = { .id = id };
|
||||||
signal_t *result;
|
return signal_array_lookup(arr, &sig);
|
||||||
|
|
||||||
result = signal_array_lookup(arr, &sig);
|
|
||||||
if(result)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
/* The signal doesn't exist yet. Check if some of our inherits_from have the
|
|
||||||
* signal and if yes, add it.
|
|
||||||
*/
|
|
||||||
signal_array_t *inherit = arr->inherits_from;
|
|
||||||
while(inherit != NULL)
|
|
||||||
{
|
|
||||||
if(signal_array_lookup(inherit, &sig))
|
|
||||||
break;
|
|
||||||
inherit = inherit->inherits_from;
|
|
||||||
}
|
|
||||||
if(inherit)
|
|
||||||
{
|
|
||||||
/* Add the signal to this array to pretend it always existed */
|
|
||||||
signal_array_insert(arr, sig);
|
|
||||||
result = signal_array_lookup(arr, &sig);
|
|
||||||
assert(result != NULL);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a signal to a signal array.
|
|
||||||
* Signals have to be added before they can be added or emitted.
|
|
||||||
* \param arr The signal array.
|
|
||||||
* \param name The signal name.
|
|
||||||
*/
|
|
||||||
static inline void
|
static inline void
|
||||||
signal_add(signal_array_t *arr, const char *name)
|
signal_add(signal_array_t *arr, const char *name)
|
||||||
{
|
{
|
||||||
unsigned long tok = a_strhash((const unsigned char *) name);
|
|
||||||
signal_t *sigfound = signal_array_getbyid(arr, tok);
|
|
||||||
if(!sigfound)
|
|
||||||
{
|
|
||||||
signal_t sig = { .id = tok };
|
|
||||||
signal_array_insert(arr, sig);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Connect a signal inside a signal array.
|
/** Connect a signal inside a signal array.
|
||||||
|
@ -109,7 +73,11 @@ signal_connect(signal_array_t *arr, const char *name, const void *ref)
|
||||||
if(sigfound)
|
if(sigfound)
|
||||||
cptr_array_append(&sigfound->sigfuncs, ref);
|
cptr_array_append(&sigfound->sigfuncs, ref);
|
||||||
else
|
else
|
||||||
warn("Trying to connect to unknown signal '%s'", name);
|
{
|
||||||
|
signal_t sig = { .id = tok };
|
||||||
|
cptr_array_append(&sig.sigfuncs, ref);
|
||||||
|
signal_array_insert(arr, sig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Disconnect a signal inside a signal array.
|
/** Disconnect a signal inside a signal array.
|
||||||
|
@ -131,8 +99,7 @@ signal_disconnect(signal_array_t *arr, const char *name, const void *ref)
|
||||||
cptr_array_remove(&sigfound->sigfuncs, func);
|
cptr_array_remove(&sigfound->sigfuncs, func);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
warn("Trying to disconnect from unknown signal '%s'", name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
4
spawn.c
4
spawn.c
|
@ -112,8 +112,6 @@ spawn_monitor_timeout(gpointer sequence)
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
warn("spawn::timeout signal is missing");
|
|
||||||
}
|
}
|
||||||
sn_startup_sequence_unref(sequence);
|
sn_startup_sequence_unref(sequence);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -218,8 +216,6 @@ spawn_monitor_event(SnMonitorEvent *event, void *data)
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
warn("%s signal is missing", event_type_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tell the spawn module that an app has been started.
|
/** Tell the spawn module that an app has been started.
|
||||||
|
|
Loading…
Reference in New Issue