Merge pull request #80506 from sepTN/fix-lambda-get_method

Fix `get_method` from named lambda
This commit is contained in:
Rémi Verschelde 2023-08-14 09:36:35 +02:00
commit e1bb9b523d
No known key found for this signature in database
GPG Key ID: C3336907360768E1
5 changed files with 11 additions and 1 deletions

View File

@ -138,7 +138,7 @@
<method name="get_method" qualifiers="const">
<return type="StringName" />
<description>
Returns the name of the method represented by this [Callable]. If the callable is a lambda function, returns the function's name.
Returns the name of the method represented by this [Callable]. If the callable is a GDScript lambda function, returns the function's name or [code]"&lt;anonymous lambda&gt;"[/code].
</description>
</method>
<method name="get_object" qualifiers="const">

View File

@ -67,6 +67,10 @@ ObjectID GDScriptLambdaCallable::get_object() const {
return script->get_instance_id();
}
StringName GDScriptLambdaCallable::get_method() const {
return function->get_name();
}
void GDScriptLambdaCallable::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
int captures_amount = captures.size();

View File

@ -56,6 +56,7 @@ public:
CompareEqualFunc get_compare_equal_func() const override;
CompareLessFunc get_compare_less_func() const override;
ObjectID get_object() const override;
StringName get_method() const override;
void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override;
GDScriptLambdaCallable(Ref<GDScript> p_script, GDScriptFunction *p_function, const Vector<Variant> &p_captures);

View File

@ -63,6 +63,10 @@ ObjectID GDScriptRPCCallable::get_object() const {
return object->get_instance_id();
}
StringName GDScriptRPCCallable::get_method() const {
return method;
}
void GDScriptRPCCallable::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
r_return_value = object->callp(method, p_arguments, p_argcount, r_call_error);
}

View File

@ -51,6 +51,7 @@ public:
CompareEqualFunc get_compare_equal_func() const override;
CompareLessFunc get_compare_less_func() const override;
ObjectID get_object() const override;
StringName get_method() const override;
void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override;
Error rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const override;