From 86df4eec97c395eb569d13027d6dbfc01110e83d Mon Sep 17 00:00:00 2001 From: lveyou <1339484752@qq.com> Date: Thu, 30 Apr 2026 17:41:15 +0800 Subject: [PATCH] =?UTF-8?q?*=20lua=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dl/script/dl_lua.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/dl/script/dl_lua.cpp b/dl/script/dl_lua.cpp index 39b305b9..16ce1bc0 100644 --- a/dl/script/dl_lua.cpp +++ b/dl/script/dl_lua.cpp @@ -63,26 +63,25 @@ namespace dl { log_err0("lua 执行函数失败:为空"); return false; - }/* - try - { - func(); } - catch (const luabridge::LuaException& e) - { - log_err("lua 执行函数失败:{}", e.what()); - return false; - }*/ - auto handler = [](lua_State* L) -> int { - // Augment the error message with a traceback - luaL_traceback(L, L, lua_tostring(L, 1), 1); - return 1; + + const char* traceback = nullptr; + auto handler = [&traceback](lua_State* L) -> int + { + const char* msg = luaL_tolstring(L, 1, nullptr); + luaL_traceback(L, L, msg, 1); + lua_pop(L, 1); // pop result of luaL_tolstring + + const char* tb = lua_tostring(L, -1); + traceback = tb ? tb : "Unknown Lua error"; + + return 1; }; auto result = func.callWithHandler(handler); if (!result) { - log_err("lua 执行函数失败:{}", result.message()); + log_err("lua 执行函数失败:{}", traceback); return false; } return true;