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/core/class_db.hpp | 3 +++ include/godot_cpp/core/object.hpp | 2 ++ include/godot_cpp/core/property_info.hpp | 11 +++++++++++ 3 files changed, 16 insertions(+) (limited to 'include/godot_cpp/core') diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp index af394f0..e5bccf3 100644 --- a/include/godot_cpp/core/class_db.hpp +++ b/include/godot_cpp/core/class_db.hpp @@ -165,7 +165,10 @@ public: static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1); static void add_signal(const StringName &p_class, const MethodInfo &p_signal); static void bind_integer_constant(const StringName &p_class_name, const StringName &p_enum_name, const StringName &p_constant_name, GDExtensionInt p_constant_value, bool p_is_bitfield = false); + // Binds an implementation of a virtual method defined in Godot. static void bind_virtual_method(const StringName &p_class, const StringName &p_method, GDExtensionClassCallVirtual p_call); + // Add a new virtual method that can be implemented by scripts. + static void add_virtual_method(const StringName &p_class, const MethodInfo &p_method, const Vector &p_arg_names = Vector()); static MethodBind *get_method(const StringName &p_class, const StringName &p_method); diff --git a/include/godot_cpp/core/object.hpp b/include/godot_cpp/core/object.hpp index 79f8fbf..c1f1069 100644 --- a/include/godot_cpp/core/object.hpp +++ b/include/godot_cpp/core/object.hpp @@ -68,6 +68,8 @@ struct MethodInfo { int id = 0; std::vector arguments; std::vector default_arguments; + GDExtensionClassMethodArgumentMetadata return_val_metadata; + std::vector arguments_metadata; inline bool operator==(const MethodInfo &p_method) const { return id == p_method.id; } inline bool operator<(const MethodInfo &p_method) const { return id == p_method.id ? (name < p_method.name) : (id < p_method.id); } diff --git a/include/godot_cpp/core/property_info.hpp b/include/godot_cpp/core/property_info.hpp index 0ecfa32..f610f3f 100644 --- a/include/godot_cpp/core/property_info.hpp +++ b/include/godot_cpp/core/property_info.hpp @@ -80,6 +80,17 @@ struct PropertyInfo { p_info->usage = usage; *(reinterpret_cast(p_info->class_name)) = class_name; } + + GDExtensionPropertyInfo _to_gdextension() const { + return { + (GDExtensionVariantType)type, + name._native_ptr(), + class_name._native_ptr(), + hint, + hint_string._native_ptr(), + usage, + }; + } }; } // namespace godot -- cgit v1.2.3