summaryrefslogtreecommitdiff
path: root/modules/mono/editor/bindings_generator.h
diff options
context:
space:
mode:
authorIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2022-12-01 01:45:11 +0100
committerIgnacio Roldán Etcheverry <ignalfonsore@gmail.com>2022-12-02 14:47:12 +0100
commit17b2838f39c634324710166d2f36458906ecaf4a (patch)
tree19dc228fe31d06a50608fca6cd889669494da0de /modules/mono/editor/bindings_generator.h
parentf86c6b6ac47ecf3e75c74cb94fd65efa6ea2eb0c (diff)
C#: Cleanup Variant marshaling code in source/bindings generators
This change aims to reduce the number of places that need to be changed when adding or editing a Godot type to the bindings. Since the addition of `Variant.From<T>/As<T>` and `VariantUtils.CreateFrom<T>/ConvertTo<T>`, we can now replace a lot of the previous code in the bindings generator and the source generators that specify these conversions for each type manually. The only exceptions are the generic Godot collections (`Array<T>` and `Dictionary<TKey, TValue>`) which still use the old version, as that one cannot be matched by our new conversion methods (limitation in the language with generics, forcing us to use delegate pointers). The cleanup applies to: - Bindings generator: - `TypeInterface.cs_variant_to_managed` - `TypeInterface.cs_managed_to_variant` - Source generators: - `MarshalUtils.AppendNativeVariantToManagedExpr` - `MarshalUtils.AppendManagedToNativeVariantExpr` - `MarshalUtils.AppendVariantToManagedExpr` - `MarshalUtils.AppendManagedToVariantExpr`
Diffstat (limited to 'modules/mono/editor/bindings_generator.h')
-rw-r--r--modules/mono/editor/bindings_generator.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h
index a479c44368..6d172f4fb8 100644
--- a/modules/mono/editor/bindings_generator.h
+++ b/modules/mono/editor/bindings_generator.h
@@ -209,7 +209,7 @@ class BindingsGenerator {
String name;
StringName cname;
- int type_parameter_count;
+ int type_parameter_count = 0;
/**
* Identifier name of the base class.
@@ -514,7 +514,12 @@ class BindingsGenerator {
static void postsetup_enum_type(TypeInterface &r_enum_itype);
- TypeInterface() {}
+ TypeInterface() {
+ static String default_cs_variant_to_managed = "VariantUtils.ConvertTo<%1>(%0)";
+ static String default_cs_managed_to_variant = "VariantUtils.CreateFrom<%1>(%0)";
+ cs_variant_to_managed = default_cs_variant_to_managed;
+ cs_managed_to_variant = default_cs_managed_to_variant;
+ }
};
struct InternalCall {