当lua代码导致异常时,luabind会在堆栈中留下一条错误消息供我收集。我想知道如何保证LUA堆栈将处于一个合理的状态,我已经处理了异常后:如何在发生错误后确保(luabind)lua状态良好?
我发现的例子告诉我使用
luabind::from_stack(e.state(), -1)
。这不会将错误信息留在堆栈上吗?我不应该弹出它吗?是否足以从堆栈弹出错误消息?错误是否会导致其他垃圾留在堆栈上?
如何在发生错误后确保lua状态良好?
这是我的本钱:
try {
// Do lua-stuff here that causes an exception from lua
}
catch (const luabind::error& e) {
luabind::object error_msg(luabind::from_stack(e.state(), -1));
std::stringstream ss;
ss << error_msg;
throw my_own_exception_class(ss.str());
}