summaryrefslogtreecommitdiff
path: root/core/variant
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-07 13:18:53 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-07 13:18:53 +0100
commit41b74c675f8ce64a40b495c050624762d1bf4006 (patch)
tree36745cfa5050010980da2ea3edcf345d9341291f /core/variant
parent0ab91b3d7939a3dc92314f4b86cf0a609756dd40 (diff)
parentd762a0395a27d523d73066708d0d8f0e9077f5fd (diff)
Merge pull request #71000 from reduz/callable-bind-from-array
Allow binding Callable arguments from an array
Diffstat (limited to 'core/variant')
-rw-r--r--core/variant/callable.cpp14
-rw-r--r--core/variant/callable.h1
-rw-r--r--core/variant/variant_call.cpp1
3 files changed, 16 insertions, 0 deletions
diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp
index ba3fc536d7..60549d567e 100644
--- a/core/variant/callable.cpp
+++ b/core/variant/callable.cpp
@@ -102,6 +102,20 @@ Callable Callable::bindp(const Variant **p_arguments, int p_argcount) const {
}
return Callable(memnew(CallableCustomBind(*this, args)));
}
+
+Callable Callable::bindv(const Array &p_arguments) {
+ if (p_arguments.is_empty()) {
+ return *this; // No point in creating a new callable if nothing is bound.
+ }
+
+ Vector<Variant> args;
+ args.resize(p_arguments.size());
+ for (int i = 0; i < p_arguments.size(); i++) {
+ args.write[i] = p_arguments[i];
+ }
+ return Callable(memnew(CallableCustomBind(*this, args)));
+}
+
Callable Callable::unbind(int p_argcount) const {
return Callable(memnew(CallableCustomUnbind(*this, p_argcount)));
}
diff --git a/core/variant/callable.h b/core/variant/callable.h
index c9d32afb61..43fef47ec0 100644
--- a/core/variant/callable.h
+++ b/core/variant/callable.h
@@ -98,6 +98,7 @@ public:
template <typename... VarArgs>
Callable bind(VarArgs... p_args);
+ Callable bindv(const Array &p_arguments);
Callable bindp(const Variant **p_arguments, int p_argcount) const;
Callable unbind(int p_argcount) const;
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index bc00bfca0f..55bfa1f0f7 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -2017,6 +2017,7 @@ static void _register_variant_builtin_methods() {
bind_method(Callable, get_object_id, sarray(), varray());
bind_method(Callable, get_method, sarray(), varray());
bind_method(Callable, hash, sarray(), varray());
+ bind_method(Callable, bindv, sarray("arguments"), varray());
bind_method(Callable, unbind, sarray("argcount"), varray());
bind_custom(Callable, call, _VariantCall::func_Callable_call, true, Variant);