summaryrefslogtreecommitdiff
path: root/modules/mono/editor/bindings_generator.cpp
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2019-02-19 22:36:27 +0100
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2019-02-19 22:38:22 +0100
commit9421da57ad552e9004e9ca3d739d75b0c1efee03 (patch)
tree9ff25829822164180c2edfcf847394ecbfa19c22 /modules/mono/editor/bindings_generator.cpp
parentaa5b99821b23d74eafb49f4b0d2d86fe693a903c (diff)
C#: Add 'Singleton' property to singleton wrapper class
This property returns an instance of the singleton. The purpose of this is to allow using methods from the base class like 'Connect'. Since all Godot singletons inherit Object, the type of the returned instance is Godot.Object.
Diffstat (limited to 'modules/mono/editor/bindings_generator.cpp')
-rw-r--r--modules/mono/editor/bindings_generator.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 77e9b1f1f4..2161b15591 100644
--- a/modules/mono/editor/bindings_generator.cpp
+++ b/modules/mono/editor/bindings_generator.cpp
@@ -97,7 +97,7 @@
#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"
-#define BINDINGS_GENERATOR_VERSION UINT32_C(6)
+#define BINDINGS_GENERATOR_VERSION UINT32_C(7)
const char *BindingsGenerator::TypeInterface::DEFAULT_VARARG_C_IN = "\t%0 %1_in = %1;\n";
@@ -854,6 +854,12 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
if (itype.is_singleton) {
// Add the type name and the singleton pointer as static fields
+ output.push_back(MEMBER_BEGIN "private static Godot.Object singleton;\n");
+ output.push_back(MEMBER_BEGIN "public static Godot.Object Singleton\n" INDENT2 "{\n" INDENT3
+ "get\n" INDENT3 "{\n" INDENT4 "if (singleton == null)\n" INDENT5
+ "singleton = Engine.GetSingleton(" BINDINGS_NATIVE_NAME_FIELD ");\n" INDENT4
+ "return singleton;\n" INDENT3 "}\n" INDENT2 "}\n");
+
output.push_back(MEMBER_BEGIN "private const string " BINDINGS_NATIVE_NAME_FIELD " = \"");
output.push_back(itype.name);
output.push_back("\";\n");