luaobject: change function push method in signal emit

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-08-19 10:29:36 +02:00
parent f111d0cab1
commit c180904d77
1 changed files with 18 additions and 4 deletions

View File

@ -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);
}