Skip to content

Commit

Permalink
Wohoo, Ref<>s are now working
Browse files Browse the repository at this point in the history
  • Loading branch information
karroffel committed Jun 21, 2017
1 parent 38f1ee7 commit e1f3865
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def generate_class_implementation(icalls, used_classes, c):
if method["return_type"] != "void":
if is_class_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:
return_statement += "return " + ("(" + strip_name(method["return_type"]) + " *) " if is_class_type(method["return_type"]) else "")
else:
Expand Down Expand Up @@ -372,7 +372,7 @@ def get_icall_type_name(name):
cast = ""
if is_class_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:
cast += "(" + strip_name(method["return_type"]) + " *) (Object *) __result;"
else:
Expand Down
2 changes: 1 addition & 1 deletion include/core/Godot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ template<class T>
struct _ArgCast {
static T _arg_cast(Variant a)
{
return a.operator T();
return static_cast<T>(a);
}
};

Expand Down
15 changes: 10 additions & 5 deletions include/core/Ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class Ref {

operator Variant() const
{
if (reference) reference->reference();
return Variant((Object *) reference);
}

Expand All @@ -130,10 +129,8 @@ class Ref {

Ref(T *r)
{
if (r)
ref_pointer(r);
else
reference = nullptr;
r->reference();
reference = r;
}

template<class T_Other>
Expand All @@ -153,6 +150,14 @@ class Ref {
ref(re);
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; }
Expand Down

0 comments on commit e1f3865

Please sign in to comment.