From 6f8d3d2c2a11ad840b13f4191b9dc52c5cf16bda Mon Sep 17 00:00:00 2001 From: raymoo Date: Mon, 10 Jun 2019 17:24:16 -0500 Subject: [PATCH] Allow registering base class methods for derived classes Adds register_class_method, a variant of register_method where the user can specify a derived class to register the method for. --- include/core/Godot.hpp | 7 +++++++ 1 file changed, 7 insertions(+) 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 +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::value, "Explicit class must derive from method class"); + register_method(name, static_cast(method_ptr), rpc_type); +} + template struct _PropertySetFunc { void (T::*f)(P);