* lua函数调用报错修正
This commit is contained in:
+13
-14
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user