diff options
author | DaylilyZeleen <735170336@qq.com> | 2024-01-18 17:23:21 +0800 |
---|---|---|
committer | DaylilyZeleen <735170336@qq.com> | 2024-02-13 03:20:02 +0800 |
commit | 6a3753c076fd6b709066a07bdc864f270090d8a9 (patch) | |
tree | 3a49bbb4f636eb5abe7c80d6dc064f2d9628b385 | |
parent | 0ddef6ed96bf1acac408291907d73cdbe69fb58f (diff) | |
download | redot-cpp-6a3753c076fd6b709066a07bdc864f270090d8a9.tar.gz |
Fix object return value of builtin types' methods.
-rw-r--r-- | binding_generator.py | 16 | ||||
-rw-r--r-- | include/godot_cpp/core/builtin_ptrcall.hpp | 12 |
2 files changed, 27 insertions, 1 deletions
diff --git a/binding_generator.py b/binding_generator.py index 2772135..bcf2aa6 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -964,8 +964,19 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl result.append(method_signature + "{") method_call = "\t" + is_ref = False + if "return_type" in method: - method_call += f'return internal::_call_builtin_method_ptr_ret<{correct_type(method["return_type"])}>(' + return_type = method["return_type"] + if is_enum(return_type): + method_call += f"return ({get_gdextension_type(correct_type(return_type))})internal::_call_builtin_method_ptr_ret<int64_t>(" + elif is_pod_type(return_type) or is_variant(return_type): + method_call += f"return internal::_call_builtin_method_ptr_ret<{get_gdextension_type(correct_type(return_type))}>(" + elif is_refcounted(return_type): + method_call += f"return Ref<{return_type}>::_gde_internal_constructor(internal::_call_builtin_method_ptr_ret_obj<{return_type}>(" + is_ref = True + else: + method_call += f"return internal::_call_builtin_method_ptr_ret_obj<{return_type}>(" else: method_call += "internal::_call_builtin_method_ptr_no_ret(" method_call += f'_method_bindings.method_{method["name"]}, ' @@ -986,6 +997,9 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl result += encode arguments.append(arg_name) method_call += ", ".join(arguments) + + if is_ref: + method_call += ")" # Close Ref<> constructor. method_call += ");" result.append(method_call) diff --git a/include/godot_cpp/core/builtin_ptrcall.hpp b/include/godot_cpp/core/builtin_ptrcall.hpp index 87311b8..19250d8 100644 --- a/include/godot_cpp/core/builtin_ptrcall.hpp +++ b/include/godot_cpp/core/builtin_ptrcall.hpp @@ -32,6 +32,7 @@ #define GODOT_BUILTIN_PTRCALL_HPP #include <gdextension_interface.h> +#include <godot_cpp/core/object.hpp> #include <array> @@ -39,6 +40,17 @@ namespace godot { namespace internal { +template <class O, class... Args> +O *_call_builtin_method_ptr_ret_obj(const GDExtensionPtrBuiltInMethod method, GDExtensionTypePtr base, const Args &...args) { + GodotObject *ret = nullptr; + std::array<GDExtensionConstTypePtr, sizeof...(Args)> call_args = { { (GDExtensionConstTypePtr)args... } }; + method(base, call_args.data(), &ret, sizeof...(Args)); + if (ret == nullptr) { + return nullptr; + } + return reinterpret_cast<O *>(internal::get_object_instance_binding(ret)); +} + template <class... Args> void _call_builtin_constructor(const GDExtensionPtrConstructor constructor, GDExtensionTypePtr base, Args... args) { std::array<GDExtensionConstTypePtr, sizeof...(Args)> call_args = { { (GDExtensionConstTypePtr)args... } }; |