Fix `get_method` from named lambda

(cherry picked from commit 793cc080cb)
This commit is contained in:
Septian 2023-08-11 11:22:10 +07:00 committed by Yuri Sizov
parent ed94e3eb79
commit bede7fa0d8
5 changed files with 11 additions and 1 deletions

View File

@ -138,7 +138,7 @@
<method name="get_method" qualifiers="const"> <method name="get_method" qualifiers="const">
<return type="StringName" /> <return type="StringName" />
<description> <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> </description>
</method> </method>
<method name="get_object" qualifiers="const"> <method name="get_object" qualifiers="const">

View File

@ -67,6 +67,10 @@ ObjectID GDScriptLambdaCallable::get_object() const {
return script->get_instance_id(); 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 { 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(); int captures_amount = captures.size();

View File

@ -56,6 +56,7 @@ public:
CompareEqualFunc get_compare_equal_func() const override; CompareEqualFunc get_compare_equal_func() const override;
CompareLessFunc get_compare_less_func() const override; CompareLessFunc get_compare_less_func() const override;
ObjectID get_object() 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; 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); 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(); 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 { 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); 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; CompareEqualFunc get_compare_equal_func() const override;
CompareLessFunc get_compare_less_func() const override; CompareLessFunc get_compare_less_func() const override;
ObjectID get_object() 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; 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; Error rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const override;