Conversation
ed3a3fd to
0fc8f58
Compare
|
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1454 |
What is the compile error message if said getter(/setter) is not found? (we can always improve etc it later, but it is good to note what we start with) |
0fc8f58 to
4a482e8
Compare
e346e6c to
682b276
Compare
…` fields Also remove `Texture` from minimal-codegen; used only in this place and get/set is not specific to this class.
682b276 to
8937052
Compare
| #[var(get = get_resource_rw, set = set_resource_rw, hint = RESOURCE_TYPE, hint_string = "Resource")] | ||
| resource_rw: Option<Gd<Resource>>, |
There was a problem hiding this comment.
This was an interesting bug:
#[var(get = get_texture_val, set = set_texture_val, ...)]refer to the getters/setters of the previous field. This happens to work due to having the same signature, and we don't have any tests actually accessing the property. I've added GDScript tests for this now.
But also, it's an indicator that the auto-generated getters/setters that are publicly accessible in Rust are not always desirable. We might want to reconsider this... 🤔

TLDR: in
#[var]attribute, keysgetandsetare now orthogonal (independent).Closes #1263.
Breaking changes
1. Orthogonality
Previously, specifying one of
getorsetautomatically opted out the other of the two (meaning no getter/setter would be generated). A user would need to explicitly define#[var(get = my_getter, set)]to add the generated setter back.2. Custom (user-defined) accessors with default name
The syntax
#[var(get)]and#[var(set)]now changes semantics, and intends to become the main way of providing custom getters/setters.It used to mean "provide a generated getter/setter".
In v0.5, it means "user-generated getter/setter with conventional name".
The convention is a
get_orset_prefix.So, if you write:
this will expect in the
#[godot_api]block the following function:So, this is equivalent to
#[var(get = get_my_property)], but with the advantage or disadvantage that changing field name also changes accessor name. In practice,#[var(get)]however avoids repetition and intends to become the standard way of using custom getters or setters.3. Disabling getters and setters
Disabling a getter or setter required opting in to the other accessor. Now, there is a dedicated syntax:
#[var(no_set)]disables the setter.#[var(get)]; omitting a setter implicitly disabled it.#[var(no_get)]disables the getter.#[var(set)].Overview of changes to existing syntax
#[var]#[var(get = fn, set = fn)]#[var(get)]no setter (read-only)
get_fieldgenerated setter
#[var(get = fn)]no setter (read-only)
generated setter
#[var(get, set)](like
#[var])#[var(get = fn, set)]fncustom
set_field#[var(get, set = fn)]get_fieldcustom setter
#[var(no_set)]no setter (read-only)
#[var(get, no_set)]no setter (read-only)