When lua code causes an exception, luabind will leave an error message on the stack for me to collect. I am wondering how to guarantee that the lua stack will be in a sensible state after I have handled the exception:
The examples I've found tells me to use
luabind::from_stack(e.state(), -1)
. Won't this leave the error message still on the stack? Shouldn't I pop it?Is it sufficient to pop the error message from the stack? Does the error cause other garbage to be left on the stack?
How do I make sure that the lua state is good after an error has occurred?
This is what I've got:
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());
}