Ensure proper semantics for default error handler

This commit is contained in:
ThePhD 2015-11-02 08:10:29 -05:00
parent 3e17b24065
commit a69c599f99
2 changed files with 14 additions and 4 deletions

1
.gitignore vendored
View File

@ -39,3 +39,4 @@ lua-5.1.5/
luajit-2.0.4/ luajit-2.0.4/
*.creator.user.* *.creator.user.*
lua-5.3.1/ lua-5.3.1/
main2.cpp

View File

@ -107,12 +107,21 @@ public:
}; };
class function : public reference { class function : public reference {
public: private:
static reference& default_handler() { static reference& handler_storage() {
static sol::reference h; static sol::reference h;
return h; return h;
} }
public:
static const reference& get_default_handler () {
return handler_storage();
}
static void set_default_handler( reference& ref ) {
handler_storage() = ref;
}
private: private:
struct handler { struct handler {
const reference& target; const reference& target;
@ -199,7 +208,7 @@ public:
sol::reference error_handler; sol::reference error_handler;
function() = default; 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); type_assert(L, index, type::function);
} }
function(const function&) = default; function(const function&) = default;