diff --git a/docs/source/features.rst b/docs/source/features.rst index a702adb8..fc24343b 100644 --- a/docs/source/features.rst +++ b/docs/source/features.rst @@ -18,6 +18,11 @@ what Sol supports - Implicit conversion to the types you want ``double b = table["computed_value"];`` +* :doc:`Optional` support: setting values, getting values of multiple (different) types + - :doc:`Lazy evaluation` for nested/chained queries + ``optional maybe_number = table["a"]["b"]["invalid_key"];`` + - Turns on safety when you want it: speed when you don't + * Support for callables (functions, lambdas, member functions) - Pull out any Lua function with :doc:`sol::function` ``sol::function fx = table["socket_send"];`` diff --git a/sol/error.hpp b/sol/error.hpp index 37882f56..5e4f41ca 100644 --- a/sol/error.hpp +++ b/sol/error.hpp @@ -31,9 +31,22 @@ struct direct_error_tag {}; const auto direct_error = direct_error_tag{}; } // detail class error : public std::runtime_error { +private: + // Because VC++ is a fuccboi + std::string w; public: - error(const std::string& str): std::runtime_error("lua: error: " + str) {} - error(detail::direct_error_tag, const std::string& str) : std::runtime_error(str) {} + error(const std::string& str) : error(detail::direct_error, "lua: error: " + 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)) {} + + error(const error& e) = default; + error(error&& e) = default; + error& operator=(const error& e) = default; + error& operator=(error&& e) = default; + + virtual const char* what() const override { + return w.c_str(); + } }; } // sol diff --git a/sol/protected_function.hpp b/sol/protected_function.hpp index b9e02307..79cb0cf4 100644 --- a/sol/protected_function.hpp +++ b/sol/protected_function.hpp @@ -55,8 +55,9 @@ private: target.push(); } } + bool valid () const { return stackindex > 0;} ~handler() { - if (stackindex > 0) { + if (valid()) { lua_remove(target.lua_state(), stackindex); } }