From ddd96b30594eb06de7d2f9a6fe3fcb10709e1c81 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 3 Feb 2022 15:03:51 +0200 Subject: [GDExtension] Fix registration of functions with enum or native pointer return type. --- core/object/make_virtuals.py | 4 ++-- core/variant/native_ptr.h | 46 +++++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 18 deletions(-) (limited to 'core') diff --git a/core/object/make_virtuals.py b/core/object/make_virtuals.py index e961745d96..5de1b49026 100644 --- a/core/object/make_virtuals.py +++ b/core/object/make_virtuals.py @@ -123,9 +123,9 @@ def generate_version(argcount, const=False, returns=False): callargtext += "," callargtext += " m_ret& r_ret" s = s.replace("$CALLSIBEGIN", "Variant ret = ") - s = s.replace("$CALLSIRET", "r_ret = ret;") + s = s.replace("$CALLSIRET", "r_ret = VariantCaster::cast(ret);") s = s.replace("$CALLPTRRETPASS", "&ret") - s = s.replace("$CALLPTRRET", "r_ret = ret;") + s = s.replace("$CALLPTRRET", "r_ret = (m_ret)ret;") else: s = s.replace("$CALLSIBEGIN", "") s = s.replace("$CALLSIRET", "") diff --git a/core/variant/native_ptr.h b/core/variant/native_ptr.h index fe541c8d4b..8e9fbbc0a4 100644 --- a/core/variant/native_ptr.h +++ b/core/variant/native_ptr.h @@ -53,22 +53,36 @@ struct GDNativePtr { operator Variant() const { return uint64_t(data); } }; -#define GDVIRTUAL_NATIVE_PTR(m_type) \ - template <> \ - struct GDNativeConstPtr { \ - const m_type *data = nullptr; \ - GDNativeConstPtr(const m_type *p_assign) { data = p_assign; } \ - static const char *get_name() { return "const " #m_type; } \ - operator const m_type *() const { return data; } \ - operator Variant() const { return uint64_t(data); } \ - }; \ - template <> \ - struct GDNativePtr { \ - m_type *data = nullptr; \ - GDNativePtr(m_type *p_assign) { data = p_assign; } \ - static const char *get_name() { return #m_type; } \ - operator m_type *() const { return data; } \ - operator Variant() const { return uint64_t(data); } \ +#define GDVIRTUAL_NATIVE_PTR(m_type) \ + template <> \ + struct GDNativeConstPtr { \ + const m_type *data = nullptr; \ + GDNativeConstPtr() {} \ + GDNativeConstPtr(const m_type *p_assign) { data = p_assign; } \ + static const char *get_name() { return "const " #m_type; } \ + operator const m_type *() const { return data; } \ + operator Variant() const { return uint64_t(data); } \ + }; \ + template <> \ + struct VariantCaster> { \ + static _FORCE_INLINE_ GDNativeConstPtr cast(const Variant &p_variant) { \ + return GDNativeConstPtr((const m_type *)p_variant.operator uint64_t()); \ + } \ + }; \ + template <> \ + struct GDNativePtr { \ + m_type *data = nullptr; \ + GDNativePtr() {} \ + GDNativePtr(m_type *p_assign) { data = p_assign; } \ + static const char *get_name() { return #m_type; } \ + operator m_type *() const { return data; } \ + operator Variant() const { return uint64_t(data); } \ + }; \ + template <> \ + struct VariantCaster> { \ + static _FORCE_INLINE_ GDNativePtr cast(const Variant &p_variant) { \ + return GDNativePtr((m_type *)p_variant.operator uint64_t()); \ + } \ }; template -- cgit v1.2.3