diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2023-01-11 01:15:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-11 01:15:39 +0100 |
commit | 5c6158fdfd16c9f1d6f70865905cea172d581d19 (patch) | |
tree | 3d85203ff887935d9c0cf20902c5a8416a3ab51a /core/variant/callable.cpp | |
parent | 54688a753589a2104e31cf2265a254cad48715ba (diff) | |
parent | 33d3b7eea77517cd2fcce59c5e9128aa74511f9f (diff) |
Merge pull request #71157 from reduz/fix-callable-get-bound-arguments
Fix Callable call error reporting.
Diffstat (limited to 'core/variant/callable.cpp')
-rw-r--r-- | core/variant/callable.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index fd85fe78f6..2f2acc55a6 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -117,6 +117,7 @@ Callable Callable::bindv(const Array &p_arguments) { } Callable Callable::unbind(int p_argcount) const { + ERR_FAIL_COND_V_MSG(p_argcount <= 0, Callable(*this), "Amount of unbind() arguments must be 1 or greater."); return Callable(memnew(CallableCustomUnbind(*this, p_argcount))); } @@ -159,6 +160,27 @@ int Callable::get_bound_arguments_count() const { } } +void Callable::get_bound_arguments_ref(Vector<Variant> &r_arguments, int &r_argcount) const { + if (!is_null() && is_custom()) { + custom->get_bound_arguments(r_arguments, r_argcount); + } else { + r_arguments.clear(); + r_argcount = 0; + } +} + +Array Callable::get_bound_arguments() const { + Vector<Variant> arr; + int ac; + get_bound_arguments_ref(arr, ac); + Array ret; + ret.resize(arr.size()); + for (int i = 0; i < arr.size(); i++) { + ret[i] = arr[i]; + } + return ret; +} + CallableCustom *Callable::get_custom() const { ERR_FAIL_COND_V_MSG(!is_custom(), nullptr, vformat("Can't get custom on non-CallableCustom \"%s\".", operator String())); @@ -370,6 +392,11 @@ int CallableCustom::get_bound_arguments_count() const { return 0; } +void CallableCustom::get_bound_arguments(Vector<Variant> &r_arguments, int &r_argcount) const { + r_arguments = Vector<Variant>(); + r_argcount = 0; +} + CallableCustom::CallableCustom() { ref_count.init(); } |