Merge pull request #66177 from rburing/callable_callv

add `callv` method
This commit is contained in:
Rémi Verschelde 2022-09-23 09:45:02 +02:00
commit ee95cc0b79
4 changed files with 24 additions and 0 deletions

View file

@ -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 { Error Callable::rpcp(int p_id, const Variant **p_arguments, int p_argcount, CallError &r_call_error) const {
if (is_null()) { if (is_null()) {
r_call_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL; r_call_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL;

View file

@ -71,6 +71,7 @@ public:
void callp(const Variant **p_arguments, int p_argcount, Variant &r_return_value, CallError &r_call_error) const; 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; 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; Error rpcp(int p_id, const Variant **p_arguments, int p_argcount, CallError &r_call_error) const;

View file

@ -1859,6 +1859,7 @@ static void _register_variant_builtin_methods() {
/* Callable */ /* Callable */
bind_method(Callable, callv, sarray("arguments"), varray());
bind_method(Callable, is_null, sarray(), varray()); bind_method(Callable, is_null, sarray(), varray());
bind_method(Callable, is_custom, sarray(), varray()); bind_method(Callable, is_custom, sarray(), varray());
bind_method(Callable, is_standard, sarray(), varray()); bind_method(Callable, is_standard, sarray(), varray());

View file

@ -81,6 +81,13 @@
[/codeblock] [/codeblock]
</description> </description>
</method> </method>
<method name="callv" qualifiers="const">
<return type="Variant" />
<param index="0" name="arguments" type="Array" />
<description>
Calls the method represented by this [Callable]. Contrary to [method call], this method does not take a variable number of arguments but expects all arguments to be passed via a single [Array].
</description>
</method>
<method name="get_method" qualifiers="const"> <method name="get_method" qualifiers="const">
<return type="StringName" /> <return type="StringName" />
<description> <description>