diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-03-09 20:48:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-09 20:48:45 +0100 |
commit | 33c907f9f5b3ec1a43d0251d7cac80da49b5b658 (patch) | |
tree | 6adb187024a8de7ed0b2ebf3e7c75ae07d8407bf /core/variant/variant.h | |
parent | f17c5501eb4bb6a86d9f2f07567da081eb8991b0 (diff) | |
parent | 21637dfc2535a00f531b8b664c1e66ba34d11eb0 (diff) |
Merge pull request #58929 from reduz/remove-variant-arg-macros
Remove VARIANT_ARG* macros
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); |