summaryrefslogtreecommitdiff
path: root/core/object/script_language.h
diff options
context:
space:
mode:
authorreduz <reduzio@gmail.com>2022-03-09 14:58:40 +0100
committerreduz <reduzio@gmail.com>2022-03-09 18:39:13 +0100
commit21637dfc2535a00f531b8b664c1e66ba34d11eb0 (patch)
treebfe6059eedfd5a4233d7d4b46d60703e342860d8 /core/object/script_language.h
parent922348f4c00e694961a7c9717abdcd0310c11973 (diff)
Remove VARIANT_ARG* macros
* Very old macros from the time Godot was created. * Limited arguments to 5 (then later changed to 8) in many places. * They were replaced by C++11 Variadic Templates. * Renamed methods that take argument pointers to have a "p" suffix. This was used in some places and not in others, so made it standard. * Also added a dereference check for Variant*. Helped catch a couple of bugs.
Diffstat (limited to 'core/object/script_language.h')
-rw-r--r--core/object/script_language.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/core/object/script_language.h b/core/object/script_language.h
index 4b18d9a5e8..2122f785b6 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -176,8 +176,20 @@ public:
virtual void get_method_list(List<MethodInfo> *p_list) const = 0;
virtual bool has_method(const StringName &p_method) const = 0;
- virtual Variant call(const StringName &p_method, VARIANT_ARG_LIST);
- virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) = 0;
+
+ virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) = 0;
+
+ 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;
+ return callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), cerr);
+ }
+
virtual void notification(int p_notification) = 0;
virtual String to_string(bool *r_valid) {
if (r_valid) {
@@ -419,8 +431,8 @@ public:
virtual void get_method_list(List<MethodInfo> *p_list) const;
virtual bool has_method(const StringName &p_method) const;
- virtual Variant call(const StringName &p_method, VARIANT_ARG_LIST) { return Variant(); }
- virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
+
+ virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
return Variant();
}