diff options
| author | George Marques <george@gmarqu.es> | 2021-08-19 20:03:11 -0300 |
|---|---|---|
| committer | Bastiaan Olij <mux213@gmail.com> | 2021-09-27 23:08:08 +1000 |
| commit | a0634cca3f35413baa34f5a40f48345ee8d689ff (patch) | |
| tree | 77f0837e60423ef837a3bcf5777b19a08d45cdb0 /include/godot_cpp | |
| parent | b3a4a2cf9360cad559d11eeab8940c1cfc0b32d0 (diff) | |
| download | redot-cpp-a0634cca3f35413baa34f5a40f48345ee8d689ff.tar.gz | |
Auto-bind virtual method overrides
Diffstat (limited to 'include/godot_cpp')
| -rw-r--r-- | include/godot_cpp/classes/wrapped.hpp | 6 | ||||
| -rw-r--r-- | include/godot_cpp/core/binder_common.hpp | 4 | ||||
| -rw-r--r-- | include/godot_cpp/core/class_db.hpp | 6 | ||||
| -rw-r--r-- | include/godot_cpp/core/method_bind.hpp | 8 |
4 files changed, 15 insertions, 9 deletions
diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 770224a..8402e9c 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -76,6 +76,11 @@ protected: \ m_class(godot::internal::empty_constructor empty) : m_inherits(empty) {} \ \ + template <class T> \ + static void register_virtuals() { \ + m_inherits::register_virtuals<T>(); \ + } \ + \ public: \ static void initialize_class() { \ static bool initialized = false; \ @@ -85,6 +90,7 @@ public: m_inherits::initialize_class(); \ if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \ _bind_methods(); \ + m_inherits::register_virtuals<m_class>(); \ } \ initialized = true; \ } \ diff --git a/include/godot_cpp/core/binder_common.hpp b/include/godot_cpp/core/binder_common.hpp index a2ce8f5..3954f6b 100644 --- a/include/godot_cpp/core/binder_common.hpp +++ b/include/godot_cpp/core/binder_common.hpp @@ -168,12 +168,12 @@ void call_with_ptr_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, } template <class T, class... P> -void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...), const GDNativeTypePtr *p_args) { +void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...), const GDNativeTypePtr *p_args, void * /*ret*/) { call_with_ptr_args_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); } template <class T, class... P> -void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...) const, const GDNativeTypePtr *p_args) { +void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...) const, const GDNativeTypePtr *p_args, void * /*ret*/) { call_with_ptr_argsc_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); } diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp index ed16971..e569661 100644 --- a/include/godot_cpp/core/class_db.hpp +++ b/include/godot_cpp/core/class_db.hpp @@ -123,12 +123,12 @@ public: #define BIND_ENUM_CONSTANT(m_constant) \ ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant); -#define BIND_VIRTUAL_METHOD(m_method) \ +#define BIND_VIRTUAL_METHOD(m_class, m_method) \ { \ auto ___call##m_method = [](GDNativeObjectPtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr p_ret) -> void { \ - call_with_ptr_args(reinterpret_cast<SelfType *>(p_instance), &SelfType::m_method, p_args, p_ret); \ + call_with_ptr_args(reinterpret_cast<m_class *>(p_instance), &m_class::m_method, p_args, p_ret); \ }; \ - ClassDB::bind_virtual_method(get_class_static(), #m_method, ___call##m_method); \ + ClassDB::bind_virtual_method(m_class::get_class_static(), #m_method, ___call##m_method); \ } template <class T> diff --git a/include/godot_cpp/core/method_bind.hpp b/include/godot_cpp/core/method_bind.hpp index 6caaf4d..2c3e7b3 100644 --- a/include/godot_cpp/core/method_bind.hpp +++ b/include/godot_cpp/core/method_bind.hpp @@ -260,9 +260,9 @@ public: } virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret) const { #ifdef TYPED_METHOD_BIND - call_with_ptr_args<T, P...>(static_cast<T *>(p_instance), method, p_args); + call_with_ptr_args<T, P...>(static_cast<T *>(p_instance), method, p_args, nullptr); #else - call_with_ptr_args<MB_T, P...>(reinterpret_cast<MB_T *>(p_instance), method, p_args); + call_with_ptr_args<MB_T, P...>(reinterpret_cast<MB_T *>(p_instance), method, p_args, nullptr); #endif // TYPED_METHOD_BIND } @@ -338,9 +338,9 @@ public: } virtual void ptrcall(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret) const { #ifdef TYPED_METHOD_BIND - call_with_ptr_args<T, P...>(static_cast<T *>(p_instance), method, p_args); + call_with_ptr_args<T, P...>(static_cast<T *>(p_instance), method, p_args, nullptr); #else - call_with_ptr_args<MB_T, P...>(reinterpret_cast<MB_T *>(p_instance), method, p_args); + call_with_ptr_args<MB_T, P...>(reinterpret_cast<MB_T *>(p_instance), method, p_args, nullptr); #endif // TYPED_METHOD_BIND } |
