From bede7fa0d8929f3862cc39ab75429e0d30fb481a Mon Sep 17 00:00:00 2001 From: Septian Date: Fri, 11 Aug 2023 11:22:10 +0700 Subject: [PATCH] Fix `get_method` from named lambda (cherry picked from commit 793cc080cbab0b047613bd449f0d35bf33cada5f) --- doc/classes/Callable.xml | 2 +- modules/gdscript/gdscript_lambda_callable.cpp | 4 ++++ modules/gdscript/gdscript_lambda_callable.h | 1 + modules/gdscript/gdscript_rpc_callable.cpp | 4 ++++ modules/gdscript/gdscript_rpc_callable.h | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/classes/Callable.xml b/doc/classes/Callable.xml index be6669110cd..d7259d1a21c 100644 --- a/doc/classes/Callable.xml +++ b/doc/classes/Callable.xml @@ -138,7 +138,7 @@ - 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]"<anonymous lambda>"[/code]. diff --git a/modules/gdscript/gdscript_lambda_callable.cpp b/modules/gdscript/gdscript_lambda_callable.cpp index 9e14e43a58a..3b89f077bdd 100644 --- a/modules/gdscript/gdscript_lambda_callable.cpp +++ b/modules/gdscript/gdscript_lambda_callable.cpp @@ -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(); diff --git a/modules/gdscript/gdscript_lambda_callable.h b/modules/gdscript/gdscript_lambda_callable.h index 33bdf6dfc1e..1c7a18fb9dc 100644 --- a/modules/gdscript/gdscript_lambda_callable.h +++ b/modules/gdscript/gdscript_lambda_callable.h @@ -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 p_script, GDScriptFunction *p_function, const Vector &p_captures); diff --git a/modules/gdscript/gdscript_rpc_callable.cpp b/modules/gdscript/gdscript_rpc_callable.cpp index a4dd8a8d3cf..265e624b6cc 100644 --- a/modules/gdscript/gdscript_rpc_callable.cpp +++ b/modules/gdscript/gdscript_rpc_callable.cpp @@ -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); } diff --git a/modules/gdscript/gdscript_rpc_callable.h b/modules/gdscript/gdscript_rpc_callable.h index c1007b18b09..66052157bec 100644 --- a/modules/gdscript/gdscript_rpc_callable.h +++ b/modules/gdscript/gdscript_rpc_callable.h @@ -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;