Merge pull request #304 from raymoo/patch-1

Allow registering base class methods for derived classes
pull/415/head
Marc 2020-06-11 18:58:15 +01:00 committed by GitHub
commit 9eceb16f05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -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); 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> template <class T, class P>
struct _PropertySetFunc { struct _PropertySetFunc {
void (T::*f)(P); void (T::*f)(P);