當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());
}