From 7dde412e26315447edf2f46661143082b5becf32 Mon Sep 17 00:00:00 2001 From: karroffel Date: Sun, 14 Jan 2018 23:03:57 +0100 Subject: [PATCH] custom types can now be used as method parameters --- binding_generator.py | 2 ++ include/core/Godot.hpp | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index 239e6438..6af6d0b4 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -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") diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index c210f865..cb49e638 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -20,6 +20,13 @@ namespace godot { +template +T *as(Object *obj) +{ + return (T *) godot::nativescript_api->godot_nativescript_get_userdata(obj); +} + + template class GodotScript { public: @@ -33,6 +40,11 @@ public: return T::___get_class_name(); } + static GodotScript *___get_from_variant(Variant a) + { + return as >((Object *) a); + } + static void _register_methods() {} }; @@ -48,7 +60,6 @@ public: private: - template struct _ArgCast { static T _arg_cast(Variant a) @@ -61,7 +72,7 @@ template struct _ArgCast { static T *_arg_cast(Variant a) { - return (T *) ((Object *) a); + return (T *) T::___get_from_variant(a); } }; @@ -76,11 +87,6 @@ struct _ArgCast { -template -T *as(Object *obj) -{ - return (T *) godot::nativescript_api->godot_nativescript_get_userdata(obj); -} // instance and destroy funcs