When I call lua_pcall
from C++ to call a Lua-function, I usually do something like this:
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!
This is nice, but not enough to determine the exact error-line in my lua-code. This is my terminal output:
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'
How can you retrieve more information (for example the code-line) about each error?