Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_method from named lambda #80506

Merged
merged 1 commit into from
Aug 14, 2023

Conversation

sepTN
Copy link
Contributor

@sepTN sepTN commented Aug 11, 2023

Fix #80434

Snippet used:

extends Node2D

func _ready():
	var fun = func test(): pass
	print(fun.get_method())

Before PR:
before

After PR:
after

@sepTN sepTN requested a review from a team as a code owner August 11, 2023 05:30
@akien-mga akien-mga added bug topic:gdscript cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release labels Aug 11, 2023
@akien-mga akien-mga added this to the 4.2 milestone Aug 11, 2023
@dalexeev
Copy link
Member

  1. I'm not sure if this method should return for an unnamed lambda: <anonymous lambda> or an empty string. <anonymous lambda> is more descriptive, but perhaps it should be documented.
  2. GDScript: The same should be done for GDScriptRPCCallable.
  3. Core: CallableCustomBind, CallableCustomUnbind and CallableCustomMethodPointerBase already implement the method.
  4. C#: ManagedCallable and BaseSignalCallable did not implement the method.
func test():
    pass

@rpc
func test_rpc():
    pass

func _ready() -> void:
    var l1 := func (): pass
    var l2 := func lambda(): pass

    print(test.get_method()) # test
    print(test_rpc.get_method()) # Error: Can't get method on CallableCustom "Node(node.gd)::test_rpc (rpc)".
    print(l1.get_method()) # <anonymous lambda>
    print(l2.get_method()) # lambda

@sepTN
Copy link
Contributor Author

sepTN commented Aug 11, 2023

I do think it should stay that way, <anonymous lambda> is more descriptive than an empty string.

Just updated the branch with a commit for the GDScriptRPCCallable, so is this the desired behavior?


Snippet:

extends Node2D

func test():
		pass

@rpc
func test_rpc():
		pass

func _ready() -> void:
		var l1 := func (): pass
		var l2 := func lambda(): pass

		print(test.get_method())
		print(test_rpc.get_method())
		print(l1.get_method())
		print(l2.get_method())

Without this PR (current master branch):
before2

With this PR:
image


Also, I have no prior Godot C# experience so I have no idea how to implement that in ManagedCallable and BaseSignalCallable, wouldn't it be better to have it on its own PR?

@dalexeev
Copy link
Member

You should squash the commits into one, according to the docs.

I'm not sure if this method should return for an unnamed lambda: <anonymous lambda> or an empty string. <anonymous lambda> is more descriptive, but perhaps it should be documented.

<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.
</description>
</method>

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].

C#: ManagedCallable and BaseSignalCallable did not implement the method.

I'm not sure about that, just noticed. let the C# team decide.

@sepTN sepTN requested a review from a team as a code owner August 11, 2023 13:28
Copy link
Member

@dalexeev dalexeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct.

@akien-mga akien-mga merged commit e1bb9b5 into godotengine:master Aug 14, 2023
@akien-mga
Copy link
Member

Thanks!

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't get method name from named lambda
4 participants