From 2001f6acbe1a51f4616ffe30642af24f81885d0a Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 15 Jun 2023 00:03:43 +0200 Subject: [PATCH] Implemented proper StringName* to variant conversion in the generated binds. --- editor/bindings_generator.cpp | 3 +++ mono_gd/gd_mono_marshal.cpp | 8 ++++++++ mono_gd/gd_mono_marshal.h | 5 +++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/editor/bindings_generator.cpp b/editor/bindings_generator.cpp index 63fea9c..5531e6e 100644 --- a/editor/bindings_generator.cpp +++ b/editor/bindings_generator.cpp @@ -93,6 +93,8 @@ #define C_METHOD_MANAGED_FROM_VARIANT C_NS_MONOMARSHAL "::variant_to_mono_object" #define C_METHOD_MONOSTR_TO_GODOT C_NS_MONOMARSHAL "::mono_string_to_godot" #define C_METHOD_MONOSTR_FROM_GODOT C_NS_MONOMARSHAL "::mono_string_from_godot" +#define C_METHOD_STRING_NAME_PTR_TO_VARIANT C_NS_MONOMARSHAL "::string_name_ptr_to_variant" +//#define C_METHOD_STRING_NAME_PTR_FROM_VARIANT C_NS_MONOMARSHAL "::variant_to_string_name_ptr" #define C_METHOD_MONOARRAY_TO(m_type) C_NS_MONOMARSHAL "::mono_array_to_" #m_type #define C_METHOD_MONOARRAY_FROM(m_type) C_NS_MONOMARSHAL "::" #m_type "_to_mono_array" @@ -3133,6 +3135,7 @@ void BindingsGenerator::_populate_builtin_type_interfaces() { itype.name = "StringName"; itype.cname = itype.name; itype.proxy_name = "StringName"; + itype.c_in = "\t%0 %1_in = " C_METHOD_STRING_NAME_PTR_TO_VARIANT "(%1);\n"; itype.c_out = "\treturn memnew(StringName(%1));\n"; itype.c_type = itype.name; itype.c_type_in = itype.c_type + "*"; diff --git a/mono_gd/gd_mono_marshal.cpp b/mono_gd/gd_mono_marshal.cpp index 0c99c45..479acd7 100644 --- a/mono_gd/gd_mono_marshal.cpp +++ b/mono_gd/gd_mono_marshal.cpp @@ -1372,6 +1372,14 @@ Variant mono_object_to_variant_no_err(MonoObject *p_obj, const ManagedType &p_ty return mono_object_to_variant_impl(p_obj, p_type, /* fail_with_err: */ false); } +Variant string_name_ptr_to_variant(StringName *p_obj) { + if (!p_obj) { + return Variant(); + } + + return Variant(*p_obj); +} + String mono_object_to_variant_string(MonoObject *p_obj, MonoException **r_exc) { if (p_obj == nullptr) { return String("null"); diff --git a/mono_gd/gd_mono_marshal.h b/mono_gd/gd_mono_marshal.h index 89be3d8..fad2da2 100644 --- a/mono_gd/gd_mono_marshal.h +++ b/mono_gd/gd_mono_marshal.h @@ -143,6 +143,8 @@ Variant mono_object_to_variant(MonoObject *p_obj); Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type); Variant mono_object_to_variant_no_err(MonoObject *p_obj, const ManagedType &p_type); +Variant string_name_ptr_to_variant(StringName *p_obj); + /// Tries to convert the MonoObject* to Variant and then convert the Variant to String. /// If the MonoObject* cannot be converted to Variant, then 'ToString()' is called instead. String mono_object_to_variant_string(MonoObject *p_obj, MonoException **r_exc); @@ -467,8 +469,7 @@ struct M_Projection { return Projection(M_Vector4::convert_to(p_from.matrix[0]), M_Vector4::convert_to(p_from.matrix[1]), M_Vector4::convert_to(p_from.matrix[2]), - M_Vector4::convert_to(p_from.matrix[3]) - ); + M_Vector4::convert_to(p_from.matrix[3])); } static _FORCE_INLINE_ M_Projection convert_from(const Projection &p_from) {