是否有可能从C/C++中获取lua堆栈中的所有错误?这是我尝试过的
C++
int main()
{
lua_State* L = luaL_newstate();
luaL_openlibs(L);
if (luaL_loadfile(L, "LuaBridgeScript.lua"))
{
throw std::runtime_error("Unable to find lua file");
}
int error = lua_pcall(L, 0, 0, 0);
while (error && lua_gettop(L))
{
std::cout << "stack = " << lua_gettop(L) << "\n";
std::cout << "error = " << error << "\n";
std::cout << "message = " << lua_tostring(L, -1) << "\n";
lua_pop(L, 1);
error = lua_pcall(L, 0, 0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
LUA:
printMessage("hi")
printMessage2("hi2")
Run Code Online (Sandbox Code Playgroud)
输出:
stack = 1
error = …Run Code Online (Sandbox Code Playgroud)