Pop errors off the stack if they're present.

This commit is contained in:
ThePhD 2016-10-29 15:12:47 -04:00
parent 5193db55c3
commit f896a9ea16
2 changed files with 7 additions and 2 deletions

View File

@ -37,6 +37,7 @@ namespace sol {
std::string w;
public:
error(const std::string& str) : error(detail::direct_error, "lua: error: " + str) {}
error(std::string&& str) : error(detail::direct_error, "lua: error: " + std::move(str)) {}
error(detail::direct_error_tag, const std::string& str) : std::runtime_error(""), w(str) {}
error(detail::direct_error_tag, std::string&& str) : std::runtime_error(""), w(std::move(str)) {}

View File

@ -31,8 +31,12 @@ namespace sol {
return -1;
#else
const char* message = lua_tostring(L, -1);
std::string err = message ? message : "An unexpected error occurred and forced the lua state to call atpanic";
if (message) {
std::string err = message;
lua_pop(L, 1);
throw error(err);
}
throw error(std::string("An unexpected error occurred and forced the lua state to call atpanic"));
#endif
}