From a69c599f99004c12f2b8129e6aa1941f49cede70 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 2 Nov 2015 08:10:29 -0500 Subject: [PATCH] Ensure proper semantics for default error handler --- .gitignore | 1 + sol/function.hpp | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 92a0a7f1..77b3dc40 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ lua-5.1.5/ luajit-2.0.4/ *.creator.user.* lua-5.3.1/ +main2.cpp diff --git a/sol/function.hpp b/sol/function.hpp index 631dddd6..db6bfc7a 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -107,10 +107,19 @@ public: }; class function : public reference { +private: + static reference& handler_storage() { + static sol::reference h; + return h; + } + public: - static reference& default_handler() { - static sol::reference h; - return h; + static const reference& get_default_handler () { + return handler_storage(); + } + + static void set_default_handler( reference& ref ) { + handler_storage() = ref; } private: @@ -199,7 +208,7 @@ public: sol::reference error_handler; function() = default; - function(lua_State* L, int index = -1): reference(L, index), error_handler(default_handler()) { + function(lua_State* L, int index = -1): reference(L, index), error_handler(get_default_handler()) { type_assert(L, index, type::function); } function(const function&) = default;