some NodePath fixes and better handling of Object type arguments

pull/7/head
Karroffel 2017-04-06 02:32:24 +02:00
parent 63c2b9d474
commit 5e3b01f0f1
8 changed files with 93 additions and 13 deletions

View File

@ -33,6 +33,7 @@ struct GodotMethod {
is_noscript: bool,
is_const: bool,
is_virtual: bool,
has_varargs: bool,
is_from_script: bool,
arguments: Vec<GodotArgument>
}
@ -295,6 +296,13 @@ fn generate_class_header(used_classes: &HashSet<&String>, class: &GodotClass) ->
}
}
if method.has_varargs {
if method.arguments.len() > 0 {
contents += ", ";
}
contents = contents + "const Array& __var_args = Array()";
}
contents = contents + ")" + if method.is_const && !class.singleton { " const" } else { "" } + ";\n";
// contents = contents + ")" + if method.is_const { " const" } else { "" } + ";\n";
}
@ -416,6 +424,13 @@ fn generate_class_implementation(icalls: &mut HashSet<(String, Vec<String>)>, us
}
}
if method.has_varargs {
if method.arguments.len() > 0 {
contents += ", ";
}
contents = contents + "const Array& __var_args";
}
contents = contents + ")" + if method.is_const && !class.singleton { " const" } else { "" } + "\n{\n";
@ -425,7 +440,7 @@ fn generate_class_implementation(icalls: &mut HashSet<(String, Vec<String>)>, us
contents = contents + "\t}\n\n";
}
if method.is_virtual {
if method.is_virtual || method.has_varargs {
contents = contents + "\tArray __args;\n";
@ -434,6 +449,12 @@ fn generate_class_implementation(icalls: &mut HashSet<(String, Vec<String>)>, us
contents = contents + "\t__args.append(" + escape_cpp(&arg.name) + ");\n";
}
if method.has_varargs {
contents = contents + "\tfor (int i = 0; i < __var_args.size(); i++) {\n";
contents = contents + "\t\t__args.append(__var_args[i]);\n";
contents = contents + "\t}\n";
}
contents = contents + "\t";
if method.return_type != "void" {

View File

@ -38,6 +38,25 @@ namespace godot {
template<class T>
struct _ArgCast {
static T _arg_cast(Variant a)
{
return (T) a;
}
};
template<class T>
struct _ArgCast<T*> {
static T *_arg_cast(Variant a)
{
return (T *) ((Object *) a);
}
};
template<class T>
T *as(Object *obj)
{
@ -188,7 +207,7 @@ struct _WrappedMethod1 {
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(*arg[0]);
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]));
return v;
}
@ -207,7 +226,7 @@ struct _WrappedMethod1<T, void, A0> {
Variant **arg = (Variant **) args;
(obj->*(method->f))(*arg[0]);
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]));
return v;
}
@ -253,7 +272,7 @@ struct _WrappedMethod2 {
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(*arg[0], *arg[1]);
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]));
return v;
}
@ -272,7 +291,7 @@ struct _WrappedMethod2<T, void, A0, A1> {
Variant **arg = (Variant **) args;
(obj->*(method->f))(*arg[0], *arg[1]);
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]));
return v;
}
@ -318,7 +337,7 @@ struct _WrappedMethod3 {
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(*arg[0], *arg[1], *arg[2]);
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]));
return v;
}
@ -337,7 +356,7 @@ struct _WrappedMethod3<T, void, A0, A1, A2> {
Variant **arg = (Variant **) args;
(obj->*(method->f))(*arg[0], *arg[1], *arg[2]);
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]));
return v;
}
@ -382,7 +401,7 @@ struct _WrappedMethod4 {
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(*arg[0], *arg[1], *arg[2], *arg[3]);
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]), _ArgCast<A3>::_arg_cast(*arg[3]));
return v;
}
@ -401,7 +420,7 @@ struct _WrappedMethod4<T, void, A0, A1, A2, A3> {
Variant **arg = (Variant **) args;
(obj->*(method->f))(*arg[0], *arg[1], *arg[2], *arg[3]);
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]), _ArgCast<A3>::_arg_cast(*arg[3]));
return v;
}
@ -445,7 +464,7 @@ struct _WrappedMethod5 {
Variant *var = (Variant *) &v;
Variant **arg = (Variant **) args;
*var = (obj->*(method->f))(*arg[0], *arg[1], *arg[2], *arg[3], *arg[4]);
*var = (obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]), _ArgCast<A3>::_arg_cast(*arg[3]), _ArgCast<A4>::_arg_cast(*arg[4]));
return v;
}
@ -464,7 +483,7 @@ struct _WrappedMethod5<T, void, A0, A1, A2, A3, A4> {
Variant **arg = (Variant **) args;
(obj->*(method->f))(*arg[0], *arg[1], *arg[2], *arg[3], *arg[4]);
(obj->*(method->f))(_ArgCast<A0>::_arg_cast(*arg[0]), _ArgCast<A1>::_arg_cast(*arg[1]), _ArgCast<A2>::_arg_cast(*arg[2]), _ArgCast<A3>::_arg_cast(*arg[3]), _ArgCast<A4>::_arg_cast(*arg[4]));
return v;
}

View File

@ -9,7 +9,15 @@ namespace godot {
NodePath::NodePath()
{
String from = "";
godot_node_path_new(&_node_path, (godot_string *) &from);
}
NodePath::NodePath(const NodePath &other)
{
String from = other;
godot_node_path_new(&_node_path, (godot_string *) &from);
godot_node_path_copy(&_node_path, &other._node_path);
}
NodePath::NodePath(const String &from)
@ -17,6 +25,12 @@ NodePath::NodePath(const String &from)
godot_node_path_new(&_node_path, (godot_string *) &from);
}
NodePath::NodePath(const char *contents)
{
String from = contents;
godot_node_path_new(&_node_path, (godot_string *) &from);
}
String NodePath::get_name(const int idx) const
{
godot_string str = godot_node_path_get_name(&_node_path, idx);
@ -63,6 +77,11 @@ NodePath::operator String() const
return *(String *) &str;
}
void NodePath::operator =(const NodePath& other)
{
godot_node_path_copy(&_node_path, &other._node_path);
}
NodePath::~NodePath()
{
godot_node_path_destroy(&_node_path);

View File

@ -24,7 +24,11 @@ class GD_CPP_CORE_API NodePath
public:
NodePath();
NodePath(const String &from);
NodePath(const NodePath &other);
NodePath(const String& from);
NodePath(const char *contents);
String get_name(const int idx) const;
@ -42,6 +46,8 @@ public:
operator String() const;
void operator =(const NodePath& other);
~NodePath();
};

View File

@ -1,5 +1,7 @@
#include "String.hpp"
#include "NodePath.hpp"
namespace godot {
@ -119,6 +121,11 @@ bool String::operator >=(const String &s)
return !(*this < s);
}
String::operator NodePath() const
{
return NodePath(*this);
}
const wchar_t *String::c_string() const
{
return godot_string_c_str(&_godot_string);

View File

@ -15,6 +15,8 @@
namespace godot {
class NodePath;
class GD_CPP_CORE_API String
{
godot_string _godot_string;
@ -61,6 +63,8 @@ public:
bool operator >=(const String &s);
operator NodePath() const;
const wchar_t *c_string() const;
};

View File

@ -385,6 +385,10 @@ Variant::operator PoolColorArray() const
godot_pool_color_array s = godot_variant_as_pool_color_array(&_godot_variant);
return *(PoolColorArray *) &s;
}
Variant::operator Object*() const {
godot_object *o = godot_variant_as_object(&_godot_variant);
return (Object *) o;
}
Variant::Type Variant::get_type() const
{

View File

@ -205,7 +205,7 @@ public:
operator NodePath() const;
operator RID() const;
operator InputEvent() const;
operator Object() const;
operator Object*() const;
operator Dictionary() const;
operator Array() const;