diff --git a/common/luaobject.c b/common/luaobject.c index 116434be6..7e4283c8f 100644 --- a/common/luaobject.c +++ b/common/luaobject.c @@ -227,14 +227,28 @@ luaA_object_emit_signal(lua_State *L, int oud, signal_t *sigfound = signal_array_getbyid(&obj->signals, a_strhash((const unsigned char *) name)); if(sigfound) - foreach(ref, sigfound->sigfuncs) + { + int nbfunc = sigfound->sigfuncs.len; + luaL_checkstack(L, lua_gettop(L) + nbfunc + nargs + 2, "too much signal"); + /* Push all functions and then execute, because this list can change + * while executing funcs. */ + foreach(func, sigfound->sigfuncs) + luaA_object_push_item(L, oud_abs, (void *) *func); + + for(int i = 0; i < nbfunc; i++) { + /* push object */ lua_pushvalue(L, oud_abs); - for(int i = 0; i < nargs; i++) - lua_pushvalue(L, - nargs - 1); - luaA_object_push_item(L, oud_abs, (void *) *ref); + /* push all args */ + for(int j = 0; j < nargs; j++) + lua_pushvalue(L, - nargs - nbfunc - 1 + i); + /* push first function */ + lua_pushvalue(L, - nargs - nbfunc - 1 + i); + /* remove this first function */ + lua_remove(L, - nargs - nbfunc - 2 + i); luaA_dofunction(L, nargs + 1, 0); } + } lua_pop(L, nargs); }