为什么这段代码片段:
if (iErr) {
std::stringstream ss;
string serror("error");
ss << "lua error code " << iErr << ": " << lua_tostring(lua, -1);
ss >> serror;
Log *log= StandardLog::getInstance();
log->logError("Lua error following in next line");
log->logError(serror);
//lua_pop(lua, 1);/* pop error message from the stack */
return 1;
}
只需打印:
Lua error following in next line
lua
代替
Lua error following in next line
lua error code 3: lua/generator/generator_example_nodenavigator.lua:10: attempt to call global 'require' (a nil value)
Logger 行如下所示:
void Logger::log(char message[]){
string smessage(message);
log(smessage);
}
void Logger::log(string smessage){
...
}
但似乎记录器没有错,因为我使用 cerr 得到了相同的输出。