diff options
Diffstat (limited to 'core/variant/variant.h')
-rw-r--r-- | core/variant/variant.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/core/variant/variant.h b/core/variant/variant.h index 836a67d942..ca18249f36 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -282,6 +282,14 @@ private: static void _register_variant_utility_functions(); static void _unregister_variant_utility_functions(); + void _variant_call_error(const String &p_method, Callable::CallError &error); + + // Avoid accidental conversion. If you reached this point, it's because you most likely forgot to dereference + // a Variant pointer (so add * like this: *variant_pointer). + + Variant(const Variant *) {} + Variant(const Variant **) {} + public: _FORCE_INLINE_ Type get_type() const { return type; @@ -527,8 +535,23 @@ public: static int get_builtin_method_count(Variant::Type p_type); static uint32_t get_builtin_method_hash(Variant::Type p_type, const StringName &p_method); - void call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error); - Variant call(const StringName &p_method, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant(), const Variant &p_arg6 = Variant(), const Variant &p_arg7 = Variant(), const Variant &p_arg8 = Variant()); + void callp(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error); + + template <typename... VarArgs> + Variant call(const StringName &p_method, VarArgs... p_args) { + Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported. + const Variant *argptrs[sizeof...(p_args) + 1]; + for (uint32_t i = 0; i < sizeof...(p_args); i++) { + argptrs[i] = &args[i]; + } + Callable::CallError cerr; + Variant ret; + callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), ret, cerr); + if (cerr.error != Callable::CallError::CALL_OK) { + _variant_call_error(p_method, cerr); + } + return ret; + } static void call_static(Variant::Type p_type, const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error); |