From 8a71de53c002b7afdd516cff7190896d40496483 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Fri, 2 May 2025 00:48:02 +0530 Subject: Fix luv callback error triggering exit and segfault --- src/LuaRuntime.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/LuaRuntime.cpp') diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp index eaf3df7..07ddb67 100644 --- a/src/LuaRuntime.cpp +++ b/src/LuaRuntime.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -19,6 +20,10 @@ LuaRuntime::LuaRuntime() { init_web_api(); } +int luv_callback(lua_State *state, int nargs, int nresults, int flags) { + return luv_cfpcall(state, nargs, nresults, flags | LUVF_CALLBACK_NOEXIT); +} + void LuaRuntime::start_event_loop() { if (event_loop != nullptr) stop_event_loop(); @@ -28,6 +33,7 @@ void LuaRuntime::start_event_loop() { // Load `uv` (luv) luv_set_loop(state, event_loop->get_uv_loop()); + luv_set_callback(state, &luv_callback); luaopen_luv(state); lua_setglobal(state, uv_global_name); } -- cgit v1.3.1