diff options
| author | Marc <marc.gilleron@gmail.com> | 2020-06-11 18:58:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-11 18:58:15 +0100 |
| commit | 9eceb16f0553884094d0f659461649be5d333866 (patch) | |
| tree | b3f5d507310f46320ce755d5b69e9214ccb5e26f /include/core | |
| parent | 2bb3a7e19c4fd84117b409d061d336b70b8db4ca (diff) | |
| parent | 6f8d3d2c2a11ad840b13f4191b9dc52c5cf16bda (diff) | |
| download | redot-cpp-9eceb16f0553884094d0f659461649be5d333866.tar.gz | |
Merge pull request #304 from raymoo/patch-1
Allow registering base class methods for derived classes
Diffstat (limited to 'include/core')
| -rw-r--r-- | include/core/Godot.hpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index c196da2..ddf1e3e 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -305,6 +305,13 @@ void register_method(const char *name, M method_ptr, godot_method_rpc_mode rpc_t godot::nativescript_api->godot_nativescript_register_method(godot::_RegisterState::nativescript_handle, ___get_method_class_name(method_ptr), name, attr, method); } +// User can specify a derived class D to register the method for, instead of it being inferred. +template <class D, class B, class R, class... As> +void register_method_explicit(const char *name, R (B::*method_ptr)(As...), godot_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED) { + static_assert(std::is_base_of<B, D>::value, "Explicit class must derive from method class"); + register_method(name, static_cast<R (D::*)(As...)>(method_ptr), rpc_type); +} + template <class T, class P> struct _PropertySetFunc { void (T::*f)(P); |
