Browse Source

Wohoo, Ref<>s are now working

Karroffel 8 years ago
parent
commit
e1f3865467
3 changed files with 13 additions and 8 deletions
  1. 2 2
      binding_generator.py
  2. 1 1
      include/core/Godot.hpp
  3. 10 5
      include/core/Ref.hpp

+ 2 - 2
binding_generator.py

@@ -306,7 +306,7 @@ def generate_class_implementation(icalls, used_classes, c):
         if method["return_type"] != "void":
         if method["return_type"] != "void":
             if is_class_type(method["return_type"]):
             if is_class_type(method["return_type"]):
                 if is_reference_type(method["return_type"]):
                 if is_reference_type(method["return_type"]):
-                    return_statement += "return Ref<" + strip_name(method["return_type"]) + ">(";
+                    return_statement += "return Ref<" + strip_name(method["return_type"]) + ">::__internal_constructor(";
                 else:
                 else:
                     return_statement += "return " + ("(" + strip_name(method["return_type"]) + " *) " if is_class_type(method["return_type"]) else "")
                     return_statement += "return " + ("(" + strip_name(method["return_type"]) + " *) " if is_class_type(method["return_type"]) else "")
             else:
             else:
@@ -372,7 +372,7 @@ def generate_class_implementation(icalls, used_classes, c):
                 cast = ""
                 cast = ""
                 if is_class_type(method["return_type"]):
                 if is_class_type(method["return_type"]):
                     if is_reference_type(method["return_type"]):
                     if is_reference_type(method["return_type"]):
-                        cast += "Ref<" + stip_name(method["return_type"]) + ">(__result);"
+                        cast += "Ref<" + stip_name(method["return_type"]) + ">::__internal_constructor(__result);"
                     else:
                     else:
                         cast += "(" + strip_name(method["return_type"]) + " *) (Object *) __result;"
                         cast += "(" + strip_name(method["return_type"]) + " *) (Object *) __result;"
                 else:
                 else:

+ 1 - 1
include/core/Godot.hpp

@@ -67,7 +67,7 @@ template<class T>
 struct _ArgCast {
 struct _ArgCast {
 	static T _arg_cast(Variant a)
 	static T _arg_cast(Variant a)
 	{
 	{
-		return a.operator T();
+		return static_cast<T>(a);
 	}
 	}
 };
 };
 
 

+ 10 - 5
include/core/Ref.hpp

@@ -108,7 +108,6 @@ public:
 	
 	
 	operator Variant() const
 	operator Variant() const
 	{
 	{
-		if (reference) reference->reference();
 		return Variant((Object *) reference);
 		return Variant((Object *) reference);
 	}
 	}
 	
 	
@@ -130,10 +129,8 @@ public:
 
 
 	Ref(T *r)
 	Ref(T *r)
 	{
 	{
-		if (r)
-			ref_pointer(r);
-		else
-			reference = nullptr;
+		r->reference();
+		reference = r;
 	}
 	}
 	
 	
 	template<class T_Other>
 	template<class T_Other>
@@ -153,6 +150,14 @@ public:
 		ref(re);
 		ref(re);
 		re.reference = nullptr;
 		re.reference = nullptr;
 	}
 	}
+
+	template<class T_Other>
+	static Ref<T> __internal_constructor(T_Other *r)
+	{
+		Ref<T> ref;
+		ref.reference = (T *) r;
+		return ref;
+	}
 	
 	
 	
 	
 	inline bool is_valid() const { return reference != nullptr; }
 	inline bool is_valid() const { return reference != nullptr; }