From 8fbb7cf79535a2b382d57ce2a094d4cbee316fd1 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Tue, 30 Jan 2024 11:25:25 -0600 Subject: Allow GDExtensions to register virtual methods and call them on scripts --- include/godot_cpp/classes/wrapped.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'include/godot_cpp/classes') diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 32caf39..25a93df 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -36,6 +36,7 @@ #include #include +#include #include @@ -107,6 +108,26 @@ public: GodotObject *_owner = nullptr; }; +_FORCE_INLINE_ void snarray_add_str(Vector &arr) { +} + +_FORCE_INLINE_ void snarray_add_str(Vector &arr, const StringName &p_str) { + arr.push_back(p_str); +} + +template +_FORCE_INLINE_ void snarray_add_str(Vector &arr, const StringName &p_str, P... p_args) { + arr.push_back(p_str); + snarray_add_str(arr, p_args...); +} + +template +_FORCE_INLINE_ Vector snarray(P... p_args) { + Vector arr; + snarray_add_str(arr, p_args...); + return arr; +} + namespace internal { GDExtensionPropertyInfo *create_c_property_list(const ::godot::List<::godot::PropertyInfo> &plist_cpp, uint32_t *r_size); @@ -445,4 +466,14 @@ private: // Don't use this for your classes, use GDCLASS() instead. #define GDEXTENSION_CLASS(m_class, m_inherits) GDEXTENSION_CLASS_ALIAS(m_class, m_class, m_inherits) +#define GDVIRTUAL_CALL(m_name, ...) _gdvirtual_##m_name##_call(__VA_ARGS__) +#define GDVIRTUAL_CALL_PTR(m_obj, m_name, ...) m_obj->_gdvirtual_##m_name##_call(__VA_ARGS__) + +#define GDVIRTUAL_REQUIRED_CALL(m_name, ...) _gdvirtual_##m_name##_call(__VA_ARGS__) +#define GDVIRTUAL_REQUIRED_CALL_PTR(m_obj, m_name, ...) m_obj->_gdvirtual_##m_name##_call(__VA_ARGS__) + +#define GDVIRTUAL_BIND(m_name, ...) ::godot::ClassDB::add_virtual_method(get_class_static(), _gdvirtual_##m_name##_get_method_info(), ::godot::snarray(__VA_ARGS__)); +#define GDVIRTUAL_IS_OVERRIDDEN(m_name) _gdvirtual_##m_name##_overridden() +#define GDVIRTUAL_IS_OVERRIDDEN_PTR(m_obj, m_name) m_obj->_gdvirtual_##m_name##_overridden() + #endif // GODOT_WRAPPED_HPP -- cgit v1.2.3