custom types can now be used as method parameters

pull/67/head
karroffel 2018-01-14 23:03:57 +01:00
parent e3b20a28a9
commit 7dde412e26
2 changed files with 15 additions and 7 deletions

View File

@ -120,6 +120,8 @@ def generate_class_header(used_classes, c):
# ___get_class_name
source.append("\tstatic inline char *___get_class_name() { return (char *) \"" + strip_name(c["name"]) + "\"; }")
source.append("\tstatic inline Object *___get_from_variant(Variant a) { return (Object *) a; }")
enum_values = []
source.append("\n\t// enums")

View File

@ -20,6 +20,13 @@
namespace godot {
template<class T>
T *as(Object *obj)
{
return (T *) godot::nativescript_api->godot_nativescript_get_userdata(obj);
}
template<class T>
class GodotScript {
public:
@ -33,6 +40,11 @@ public:
return T::___get_class_name();
}
static GodotScript<T> *___get_from_variant(Variant a)
{
return as<GodotScript<T> >((Object *) a);
}
static void _register_methods() {}
};
@ -48,7 +60,6 @@ public:
private:
template<class T>
struct _ArgCast {
static T _arg_cast(Variant a)
@ -61,7 +72,7 @@ template<class T>
struct _ArgCast<T*> {
static T *_arg_cast(Variant a)
{
return (T *) ((Object *) a);
return (T *) T::___get_from_variant(a);
}
};
@ -76,11 +87,6 @@ struct _ArgCast<Variant> {
template<class T>
T *as(Object *obj)
{
return (T *) godot::nativescript_api->godot_nativescript_get_userdata(obj);
}
// instance and destroy funcs