luaobject: add signal_object_emit
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
1692496fce
commit
2a252cd4da
|
@ -181,6 +181,37 @@ luaA_object_remove_signal(lua_State *L, int oud,
|
||||||
lua_remove(L, ud);
|
lua_remove(L, ud);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
signal_object_emit(lua_State *L, signal_array_t *arr, const char *name, int nargs)
|
||||||
|
{
|
||||||
|
signal_t *sigfound = signal_array_getbyid(arr,
|
||||||
|
a_strhash((const unsigned char *) name));
|
||||||
|
|
||||||
|
if(sigfound)
|
||||||
|
{
|
||||||
|
int nbfunc = sigfound->sigfuncs.len;
|
||||||
|
luaL_checkstack(L, lua_gettop(L) + nbfunc + nargs + 1, "too much signal");
|
||||||
|
/* Push all functions and then execute, because this list can change
|
||||||
|
* while executing funcs. */
|
||||||
|
foreach(func, sigfound->sigfuncs)
|
||||||
|
luaA_object_push(L, (void *) *func);
|
||||||
|
|
||||||
|
for(int i = 0; i < nbfunc; i++)
|
||||||
|
{
|
||||||
|
/* push all args */
|
||||||
|
for(int j = 0; j < nargs; j++)
|
||||||
|
lua_pushvalue(L, - nargs - nbfunc + i);
|
||||||
|
/* push first function */
|
||||||
|
lua_pushvalue(L, - nargs - nbfunc + i);
|
||||||
|
/* remove this first function */
|
||||||
|
lua_remove(L, - nargs - nbfunc - 1 + i);
|
||||||
|
luaA_dofunction(L, nargs, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* remove args */
|
||||||
|
lua_pop(L, nargs);
|
||||||
|
}
|
||||||
|
|
||||||
/** Emit a signal to an object.
|
/** Emit a signal to an object.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
* \param oud The object index on the stack.
|
* \param oud The object index on the stack.
|
||||||
|
|
|
@ -134,6 +134,8 @@ luaA_object_push(lua_State *L, void *pointer)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void signal_object_emit(lua_State *, signal_array_t *, const char *, int);
|
||||||
|
|
||||||
void luaA_object_add_signal(lua_State *, int, const char *, int);
|
void luaA_object_add_signal(lua_State *, int, const char *, int);
|
||||||
void luaA_object_remove_signal(lua_State *, int, const char *, int);
|
void luaA_object_remove_signal(lua_State *, int, const char *, int);
|
||||||
void luaA_object_emit_signal(lua_State *, int, const char *, int);
|
void luaA_object_emit_signal(lua_State *, int, const char *, int);
|
||||||
|
|
Loading…
Reference in New Issue