fix error handle in callback with lua_pcall
according to errfunc cannot be a pseudo-index.
@@ -87,8 +87,11 @@ static void luv_call_callback(lua_State* L, luv_handle_t* data, luv_callback_id
lua_pop(L, nargs);
}
else {
+ int errfunc = 0;
+
// Get the traceback function in case of error
lua_pushcfunction(L, traceback);
+ errfunc = lua_gettop(L);
// And insert it before the args if there are any.
if (nargs) {
lua_insert(L, -1 - nargs);
@@ -100,7 +103,7 @@ static void luv_call_callback(lua_State* L, luv_handle_t* data, luv_callback_id
lua_insert(L, -1 - nargs);
}
- if (lua_pcall(L, nargs, 0, -2 - nargs)) {
+ if (lua_pcall(L, nargs, 0, errfunc)) {
fprintf(stderr, "Uncaught Error: %s\n", lua_tostring(L, -1));
exit(-1);
}
