我正在使用lua 5.1,我正在使用lua来加载可以从C++调用的函数.
int Error = luaL_loadfile(LuaState, "Test.lua");
if(!Error)
{
Error = lua_pcall(LuaState, 0, LUA_MULTRET, 0);
}
if(Error)
{
std::cerr << "-- " << lua_tostring(LuaState, -1) << std::endl;
lua_pop(LuaState, 1);
}
else
{
LuaStackBalancer LSB(LuaState); //Puts the Lua Stack back to the way it was found
lua_pushstring(LuaState, "Run");
lua_gettable(LuaState, LUA_GLOBALSINDEX);
if(lua_isfunction(LuaState, -1))
{
if(lua_pcall(LuaState, 0, 0, 0))
{
std::cerr << "-- " << lua_tostring(LuaState, -1) << std::endl;
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,如果我从C++调用的lua函数调用另一个错误输出的函数,则返回是该函数的第一个参数而不是错误消息.
AlwaysErrorsOut定义为:
int AlwaysErrorsOut(lua_State *LuaState)
{
return luaL_error(LuaState, "Error Test Successful"); …
Run Code Online (Sandbox Code Playgroud)