diff options
author | Juan Linietsky <reduzio@gmail.com> | 2023-01-06 15:37:53 +0100 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2023-01-08 23:35:11 +0100 |
commit | 0e0ca01bce1adecde1de745d2b31d2ad0c12bf6b (patch) | |
tree | aea57faa3c7e1a1f7cc2816fba45c4a688422623 /core/variant | |
parent | b14f7aa9f92ff44135c283a9c88dab5ef9136d64 (diff) |
Properly report Callable bound arguments
Fixes #63213
Adds a function: Callable::get_amount_of_arguments_bound() to query this in callables. Exposed to the engine API.
Diffstat (limited to 'core/variant')
-rw-r--r-- | core/variant/callable.cpp | 12 | ||||
-rw-r--r-- | core/variant/callable.h | 2 | ||||
-rw-r--r-- | core/variant/callable_bind.cpp | 8 | ||||
-rw-r--r-- | core/variant/callable_bind.h | 3 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 1 |
5 files changed, 25 insertions, 1 deletions
diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index ba3fc536d7..849bfaa38f 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -137,6 +137,14 @@ StringName Callable::get_method() const { return method; } +int Callable::get_bound_arguments_count() const { + if (!is_null() && is_custom()) { + return custom->get_bound_arguments_count(); + } else { + return 0; + } +} + CallableCustom *Callable::get_custom() const { ERR_FAIL_COND_V_MSG(!is_custom(), nullptr, vformat("Can't get custom on non-CallableCustom \"%s\".", operator String())); @@ -344,6 +352,10 @@ const Callable *CallableCustom::get_base_comparator() const { return nullptr; } +int CallableCustom::get_bound_arguments_count() const { + return 0; +} + CallableCustom::CallableCustom() { ref_count.init(); } diff --git a/core/variant/callable.h b/core/variant/callable.h index c9d32afb61..c80481c0aa 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -106,6 +106,7 @@ public: ObjectID get_object_id() const; StringName get_method() const; CallableCustom *get_custom() const; + int get_bound_arguments_count() const; uint32_t hash() const; @@ -146,6 +147,7 @@ public: virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const = 0; virtual Error rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const; virtual const Callable *get_base_comparator() const; + virtual int get_bound_arguments_count() const; CallableCustom(); virtual ~CallableCustom() {} diff --git a/core/variant/callable_bind.cpp b/core/variant/callable_bind.cpp index 4713a49303..83035dc70d 100644 --- a/core/variant/callable_bind.cpp +++ b/core/variant/callable_bind.cpp @@ -87,6 +87,10 @@ const Callable *CallableCustomBind::get_base_comparator() const { return &callable; } +int CallableCustomBind::get_bound_arguments_count() const { + return callable.get_bound_arguments_count() + binds.size(); +} + void CallableCustomBind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { const Variant **args = (const Variant **)alloca(sizeof(const Variant **) * (binds.size() + p_argcount)); for (int i = 0; i < p_argcount; i++) { @@ -164,6 +168,10 @@ const Callable *CallableCustomUnbind::get_base_comparator() const { return &callable; } +int CallableCustomUnbind::get_bound_arguments_count() const { + return callable.get_bound_arguments_count() - argcount; +} + void CallableCustomUnbind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { if (argcount > p_argcount) { r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; diff --git a/core/variant/callable_bind.h b/core/variant/callable_bind.h index 2bdf7e4782..a79a521b5b 100644 --- a/core/variant/callable_bind.h +++ b/core/variant/callable_bind.h @@ -51,7 +51,7 @@ public: virtual ObjectID get_object() const override; //must always be able to provide an object virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override; virtual const Callable *get_base_comparator() const override; - + virtual int get_bound_arguments_count() const override; Callable get_callable() { return callable; } Vector<Variant> get_binds() { return binds; } @@ -76,6 +76,7 @@ public: virtual ObjectID get_object() const override; //must always be able to provide an object virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override; virtual const Callable *get_base_comparator() const override; + virtual int get_bound_arguments_count() const override; Callable get_callable() { return callable; } int get_unbinds() { return argcount; } diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 088e24ba6e..6b6df0a5c7 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -2016,6 +2016,7 @@ static void _register_variant_builtin_methods() { bind_method(Callable, get_object, sarray(), varray()); bind_method(Callable, get_object_id, sarray(), varray()); bind_method(Callable, get_method, sarray(), varray()); + bind_method(Callable, get_bound_arguments_count, sarray(), varray()); bind_method(Callable, hash, sarray(), varray()); bind_method(Callable, unbind, sarray("argcount"), varray()); |