From f896a9ea1688c677b3c4e522bbe8b329dba11dce Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sat, 29 Oct 2016 15:12:47 -0400 Subject: [PATCH] Pop errors off the stack if they're present. --- sol/error.hpp | 1 + sol/state.hpp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sol/error.hpp b/sol/error.hpp index cf85fece..1e262d87 100644 --- a/sol/error.hpp +++ b/sol/error.hpp @@ -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)) {} diff --git a/sol/state.hpp b/sol/state.hpp index 8eff7dba..4f127844 100644 --- a/sol/state.hpp +++ b/sol/state.hpp @@ -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"; - throw error(err); + 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 }