当我lua_pcall
从 C++ 调用Lua-function时,我通常会这样做:
const int pcall {lua_pcall(lua_state, 1, 1, 0)};
if (pcall == LUA_OK){
...
return true;
// OK!
}
std::cerr << "Error: pcall failed. Code: ";
std::cerr << pcall;
std::cerr << ", '" << lua_tostring(lua_state, -1) << "'\n";
...
// ERROR!
这很好,但不足以确定我的 lua 代码中的确切错误行。这是我的终端输出:
Error: pcall failed. Code: 2, 'attempt to call a nil value'
Error: pcall failed. Code: 2, 'attempt to call a boolean value'
Error: pcall failed. Code: 2, 'attempt to call a nil value'
Error: pcall failed. Code: 2, 'attempt to call a nil value'
Error: pcall failed. Code: 2, 'attempt to call a userdata value'
您如何检索有关每个错误的更多信息(例如代码行)?