From 0c2055d15d000f9e7070d401ff9e03d4bb2b339e Mon Sep 17 00:00:00 2001 From: Ricardo Buring Date: Tue, 20 Sep 2022 22:32:46 +0200 Subject: Callable: add callv method This method can be called from GDExtension. --- core/variant/callable.cpp | 15 +++++++++++++++ core/variant/callable.h | 1 + core/variant/variant_call.cpp | 1 + 3 files changed, 17 insertions(+) (limited to 'core/variant') diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index 28efb43fc5..b35e2f004b 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -63,6 +63,21 @@ void Callable::callp(const Variant **p_arguments, int p_argcount, Variant &r_ret } } +Variant Callable::callv(const Array &p_arguments) const { + int argcount = p_arguments.size(); + const Variant **argptrs = nullptr; + if (argcount) { + argptrs = (const Variant **)alloca(sizeof(Variant *) * argcount); + for (int i = 0; i < argcount; i++) { + argptrs[i] = &p_arguments[i]; + } + } + CallError ce; + Variant ret; + callp(argptrs, argcount, ret, ce); + return ret; +} + Error Callable::rpcp(int p_id, const Variant **p_arguments, int p_argcount, CallError &r_call_error) const { if (is_null()) { r_call_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL; diff --git a/core/variant/callable.h b/core/variant/callable.h index 1f1c983eb3..0305dc55c3 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -71,6 +71,7 @@ public: void callp(const Variant **p_arguments, int p_argcount, Variant &r_return_value, CallError &r_call_error) const; void call_deferredp(const Variant **p_arguments, int p_argcount) const; + Variant callv(const Array &p_arguments) const; Error rpcp(int p_id, const Variant **p_arguments, int p_argcount, CallError &r_call_error) const; diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index f09885b325..a62b8a24a0 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1859,6 +1859,7 @@ static void _register_variant_builtin_methods() { /* Callable */ + bind_method(Callable, callv, sarray("arguments"), varray()); bind_method(Callable, is_null, sarray(), varray()); bind_method(Callable, is_custom, sarray(), varray()); bind_method(Callable, is_standard, sarray(), varray()); -- cgit v1.2.3