diff options
author | Thomas Harning Jr <harningt@gmail.com> | 2007-09-05 23:05:05 -0400 |
---|---|---|
committer | Thomas Harning Jr <harningt@gmail.com> | 2007-09-05 23:05:05 -0400 |
commit | 3bf12e614c65f22f012b35a19eafad28ad3d4ed5 (patch) | |
tree | 1cd4679662e26c31c3b7a9125823df9d484fd179 /src/event_callback.c | |
parent | b28ac1f588e2e05069f4104400e1b3f7c2d8e460 (diff) | |
download | luaevent-prosody-3bf12e614c65f22f012b35a19eafad28ad3d4ed5.tar.gz luaevent-prosody-3bf12e614c65f22f012b35a19eafad28ad3d4ed5.zip |
Completely refactored event_callback creation out into event_callback.
Diffstat (limited to 'src/event_callback.c')
-rw-r--r-- | src/event_callback.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/event_callback.c b/src/event_callback.c index 0d320eb..f2cd0bc 100644 --- a/src/event_callback.c +++ b/src/event_callback.c @@ -4,6 +4,8 @@ #include <assert.h> #include <lauxlib.h> +#define EVENT_CALLBACK_ARG_MT "EVENT_CALLBACK_ARG_MT" + void freeCallbackArgs(le_callback* arg, lua_State* L) { if(arg->base) { arg->base = NULL; @@ -45,6 +47,20 @@ static int luaevent_cb_gc(lua_State* L) { return 0; } +le_callback* event_callback_push(lua_State* L, int baseIdx, int callbackIdx) { + le_callback* cb; + le_base *base = event_base_get(L, baseIdx); + luaL_checktype(L, callbackIdx, LUA_TFUNCTION); + cb = lua_newuserdata(L, sizeof(*cb)); + luaL_getmetatable(L, EVENT_CALLBACK_ARG_MT); + lua_setmetatable(L, -2); + + lua_pushvalue(L, callbackIdx); + cb->callbackRef = luaL_ref(L, LUA_REGISTRYINDEX); + cb->base = base; + return cb; +} + int event_callback_register(lua_State* L) { luaL_newmetatable(L, EVENT_CALLBACK_ARG_MT); lua_pushcfunction(L, luaevent_cb_gc); |