Commit 9d4e8a33 authored by Marek Vavruša's avatar Marek Vavruša

daemon/bindings: fixed event callback not clearing the stack

parent efccea8e
......@@ -440,8 +440,9 @@ static void event_callback(uv_timer_t *timer)
int ret = engine_pcall(L, 1);
if (ret != 0) {
fprintf(stderr, "error: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
}
/* Clear the stack, there may be event a/o enything returned */
lua_settop(L, 0);
/* Free callback if not recurrent or an error */
if (ret != 0 || uv_timer_get_repeat(timer) == 0) {
uv_close((uv_handle_t *)timer, (uv_close_cb) event_free);
......
......@@ -35,6 +35,7 @@ static inline lua_State *l_ffi_preface(struct kr_module *module, const char *cal
lua_getfield(L, -1, call);
lua_remove(L, -2);
if (lua_isnil(L, -1)) {
lua_pop(L, 1);
return NULL;
}
lua_pushlightuserdata(L, module);
......@@ -68,7 +69,7 @@ static int l_ffi_defer(lua_State *L)
/** @internal Helper for calling the entrypoint. */
static inline int l_ffi_call(lua_State *L, int argc)
{
int status = lua_pcall(L, argc, LUA_MULTRET, 0);
int status = lua_pcall(L, argc, 1, 0);
if (status != 0) {
fprintf(stderr, "error: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
......@@ -82,7 +83,7 @@ static inline int l_ffi_call(lua_State *L, int argc)
} else if (lua_isnumber(L, -1)) { /* Return code */
status = lua_tonumber(L, 1);
}
lua_pop(L, n);
lua_pop(L, 1);
}
return status;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment