mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
updated protected_function stuff
This commit is contained in:
parent
72a445ff6a
commit
6c34a2ac4f
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user