* lua函数调用报错修正

This commit is contained in:
2026-04-30 17:41:15 +08:00
parent 586f82a60e
commit 86df4eec97
+13 -14
View File
@@ -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;