diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-09 08:34:28 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-09 08:34:28 +0100 |
commit | 31f94574d4c114e4fbdca944113601ad09a981b4 (patch) | |
tree | 2d14090dff7eac9a30aa1c3d3fb1ec470397c520 /core/variant | |
parent | 9c7723b71755c3172f4b591ff8b1b3ee971f6843 (diff) | |
parent | 0e0ca01bce1adecde1de745d2b31d2ad0c12bf6b (diff) |
Merge pull request #70996 from reduz/properly-report-callable-bound-arguments
Properly report Callable bound arguments
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 60549d567e..fd85fe78f6 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -151,6 +151,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())); @@ -358,6 +366,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 43fef47ec0..10d291ac24 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -107,6 +107,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; @@ -147,6 +148,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 55bfa1f0f7..6c06b63dab 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, bindv, sarray("arguments"), varray()); bind_method(Callable, unbind, sarray("argcount"), varray()); |