updated protected_function stuff

This commit is contained in:
ThePhD 2016-09-30 01:42:23 -04:00
parent 72a445ff6a
commit 6c34a2ac4f
2 changed files with 166 additions and 161 deletions

View File

@ -29,21 +29,26 @@
#include <algorithm>
namespace sol {
template <typename base_t>
class basic_protected_function : public base_t {
private:
static reference& handler_storage() {
namespace detail {
inline reference& handler_storage() {
static sol::reference h;
return h;
}
}
template <typename base_t>
class basic_protected_function : public base_t {
public:
static const reference& get_default_handler() {
return handler_storage();
static reference& get_default_handler() {
return detail::handler_storage();
}
static void set_default_handler(reference& ref) {
handler_storage() = ref;
static void set_default_handler(const reference& ref) {
detail::handler_storage() = ref;
}
static void set_default_handler(reference&& ref) {
detail::handler_storage() = std::move(ref);
}
private:
@ -139,11 +144,11 @@ namespace sol {
basic_protected_function& operator=(const basic_protected_function&) = default;
basic_protected_function(basic_protected_function&&) = default;
basic_protected_function& operator=(basic_protected_function&&) = default;
basic_protected_function(const basic_function<base_t>& b) : base_t(b) {}
basic_protected_function(basic_function<base_t>&& b) : base_t(std::move(b)) {}
basic_protected_function(const stack_reference& r) : basic_protected_function(r.lua_state(), r.stack_index()) {}
basic_protected_function(stack_reference&& r) : basic_protected_function(r.lua_state(), r.stack_index()) {}
basic_protected_function(lua_State* L, int index = -1) : base_t(L, index), error_handler(get_default_handler()) {
basic_protected_function(const basic_function<base_t>& b, reference eh = get_default_handler()) : base_t(b), error_handler(std::move(eh)) {}
basic_protected_function(basic_function<base_t>&& b, reference eh = get_default_handler()) : base_t(std::move(b)), error_handler(std::move(eh)) {}
basic_protected_function(const stack_reference& r, reference eh = get_default_handler()) : basic_protected_function(r.lua_state(), r.stack_index(), std::move(eh)) {}
basic_protected_function(stack_reference&& r, reference eh = get_default_handler()) : basic_protected_function(r.lua_state(), r.stack_index(), std::move(eh)) {}
basic_protected_function(lua_State* L, int index = -1, reference eh = get_default_handler()) : base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_CHECK_ARGUMENTS
stack::check<basic_protected_function>(L, index, type_panic);
#endif // Safety