diff --git a/src/luv.c b/src/luv.c index 9d602c46..7ae7e861 100644 --- a/src/luv.c +++ b/src/luv.c @@ -715,9 +715,11 @@ LUALIB_API int luv_cfpcall(lua_State* L, int nargs, int nresult, int flags) { case LUA_OK: break; case LUA_ERRMEM: - if ((flags & LUVF_CALLBACK_NOERRMSG) == 0) + if ((flags & LUVF_CALLBACK_NOERRMSG) == 0) { fprintf(stderr, "System Error: %s\n", luaL_tolstring(L, lua_absindex(L, -1), NULL)); + lua_pop(L, 1); // Remove error string pushed by luaL_tolstring() + } if ((flags & LUVF_CALLBACK_NOEXIT) == 0) exit(-1); lua_pop(L, 1); @@ -726,9 +728,11 @@ LUALIB_API int luv_cfpcall(lua_State* L, int nargs, int nresult, int flags) { case LUA_ERRRUN: case LUA_ERRERR: default: - if ((flags & LUVF_CALLBACK_NOERRMSG) == 0) + if ((flags & LUVF_CALLBACK_NOERRMSG) == 0) { fprintf(stderr, "Uncaught Error: %s\n", luaL_tolstring(L, lua_absindex(L, -1), NULL)); + lua_pop(L, 1); // Remove error string pushed by luaL_tolstring() + } if ((flags & LUVF_CALLBACK_NOEXIT) == 0) exit(-1); lua_pop(L, 1);