-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Add #[export_group]
Attribute for Creating Property Groups
#214
Conversation
Thanks a lot for this pull request! 🙂 We should probably consider how we represent the variety of GDScript's #[export_group(name = "My group", prefix = "my_")]
#[export]
my_number: i32,
#[export]
my_string: GodotString, Does that first I don't think a separate Furthermore, we had such a feature request a year ago in gdnative, and I added some comments there: Regarding syntax suggestions, it may be helpful to define "group properties" (name, prefix) in one place and then refer to them from other places. There are multiple ways to achieve that. Two are outlined in gdnative#855, but there are more: 1. Require a separate
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we don't need to find the perfect, super-complex design right now. We can start experimenting and then iteratively improve based on user feedback.
tokens: &mut Vec<TokenStream>, | ||
getsets: &mut Vec<TokenStream>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why these variables are renamed here?
Probably easier to understand if the same name is used as on the call site.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the extracting into function makes it a bit hard to see changes 🙈
But I agree with splitting it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason but being lazy. Will change the name back.
Re: extracting
Yup, hard to see, but a separate commit would have been overkill I think.
grouped_foo: 0, | ||
grouped_bar: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't test the group association -- is there a way to check that programmatically at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I do not (yet) know. Will experiment a bit with Gdscript property groups and introspection and then revisit this issue.
I really like option 1 you mentioned: It feels like the natural thing to do, as property groups are intended to keep struct-like data close together. The non-locality in this case could even be an advantage, as common property groups are reusable that way. Think of how we can right now edit Vectors in a concise way in the editor as single properties instead of having an "ABC x" and "ABC y" property each time we wanna use a vector. There's a lot of potential here. This last point wouldn't really be viable with options 2 and 3, which treat property groups not as grouped data, but as relations on data of a larger, encompassing struct. So I am definitely in favor of 1. |
Expanding on that: As those reusable structs may be more than exports, I am in favor of naming and deriving the trait something like "ExportGroupable", with helper attributes for prefix and name. |
Thank you for your review, you're right, my proposed export_group syntax has a bunch of shortcomings. |
So, after thinking about this, and looking into gdnative, which I hadn't used before, I think jumping into implementation for more than checking feasibility of a syntax option at this stage is premature. For this reason I will close this PR for now and create an issue instead, where we can develop the idea more. Once a solid, informed choice on the syntax has been made, we can then move on with getting this into gdext. |
This makes Godot's property groups available to exported properties in Rust.
On the itest side there may be possibilities to further test the success of creating the property, right now itest only uses the attribute, i.e. checks that code using it compiles. However, I am unsure how to properly query this in a way like
HasProperty
is tested.Feedback is more than welcome!
Without this PR
With this PR