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

GDScript: property setters do not work with curried lambda functions #70448

Closed
simast opened this issue Dec 22, 2022 · 2 comments
Closed

GDScript: property setters do not work with curried lambda functions #70448

simast opened this issue Dec 22, 2022 · 2 comments

Comments

@simast
Copy link

simast commented Dec 22, 2022

Godot version

v4.0.beta9.official [e780dc3]

System information

Windows 11

Issue description

As per the docs we can assign a function directly to a property setter:

var my_prop := 1.0:
	set = my_setter

Also the docs suggest that this can be used to "share the code across multiple properties". However this does not work with currying and lambda functions (see example in Steps to reproduce).

The reported error is:

Parse Error: Expected end of statement after property declaration, found "(" instead.

Steps to reproduce

Example code with the issue:

var prop: float:
	set = set_float_prop(&"prop")


func set_float_prop(param: StringName):
	return func (value: float):
		self[param] = value

Minimal reproduction project

N/A

@KoBeWi
Copy link
Member

KoBeWi commented Dec 23, 2022

share the code across multiple properties

This just means that you can assign the same function to multiple properties (although not sure how does that work).

Looks like setter expects a method identifier, not a true callable. Which means you can't use Callable(...) either.

@dalexeev
Copy link
Member

Also the docs suggest that this can be used to "share the code across multiple properties".

The sentence in the docs is a bit confusing. At the moment, you can share the same setter/getter between multiple properties, but have no way of distinguishing which property it's being called on. See:

As for argument binding, this is difficult to implement, see godotengine/godot-proposals#6750 (comment):

Binding arbitrary arguments sounds useful, but it's probably complex to implement. Functions are not Callables, they just create Callables at runtime when referenced. So to properly call the setter/getter with binds those would need to be stored in the script and passed as arguments at runtime. If you want non-constant values it becomes more difficult because it would need to store expressions to be executed when calling. I don't think this is worth the hassle.

I suggest closing the issue, as this is not a bug, but an intentional limitation for performance reasons. There are already several proposals related to the problem.

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

No branches or pull requests

4 participants