-
Notifications
You must be signed in to change notification settings - Fork 211
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
New syntax for #[export] methods and #[base] parameters #872
Conversation
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.
Thanks a lot for this pull request, and sorry for the late review!
If I am not missing something, this PR changes several things at once:
- Add
#[base]
and redefine the "owner parameter" syntax - Introduce
#[method]
in addition to#[export]
- Deprecate reference return
- Something with
Deref
(is this somehow overlapping with Returns the dereferenced type in the exported method #870?) - Some other refactorings (macro simplification,
rpc_mode: Option<RpcMode>
) - Something else?
For the future, I would appreciate if we could keep a pull request limited to more or less one related functionality. This makes it easier to review, reduces the risk of bugs/untested functionality and typically also means less time until it can be merged.
For now (unless it's very simple to split by commit), I don't want you to spend huge effort on tearing those things apart, but maybe you could elaborate each of the changes a bit here? That would help tremendously to understand the motivation behind each change and the design choices in its implementation! 🙂
Regarding Some points to consider:
I'm open to ideas, it should just be concise (ideally 1 word). Could even be something like Is the Also, |
tryBuild succeeded: |
It is described as exporting as a method. This would be useful in the future to add features like the
At least, it is backward compatible with the range of tests originally in the library. The
This pull request was branched from the deref-return branch. Sorry if this is confusing. I'm not yet familiar with Git. |
9fcec43
to
e113a6b
Compare
I see. I think the whole topic would look different if people qualified proc macros and attributes: #[gdnative::methods]
impl MyClass {
#[gdnative::method]
fn exposed_via_gdnative(&self, owner: &Node, i: i32) -> String {
...
}
pub fn pure_rust(&self) -> bool {
...
}
} But without that, it's not really clear: #[methods]
impl MyClass {
#[method]
fn exposed_via_gdnative(&self, owner: &Node, i: i32) -> String {
...
}
pub fn pure_rust(&self) -> bool {
...
}
} Which is why I was thinking maybe something related to Godot (or at least the exporting) should be made part of the name. But I appreciate other input on that topic 🙂
Do we actually want to support
No worries! Just for the future, it would probably be easier to keep unrelated improvements in separate PRs (even if they touch the same code, like here the export proc-macros) 🙂 But we can also keep this pull request bigger if you prefer -- in that case, could you edit your initial post here to add the other improvements (I'm not sure if my list fully captures them)? That way we have a complete overview of any changes. |
tryBuild succeeded: |
- Enable to use Path syntax. - Remove abstractions that inhibit expansion. - Remove code that only accepts [export = "wrong"]. - Add error message.
The ways of emit warnings is a terrible hack. This is because there is no way to emit warnings from macros in stable Rust. Follow these steps to emit warnings. - Detect whether reference types are used in derive_methods(). - Expand the call to deprecated_reference_return!() macro to user code.
- Separate method parameters and macro parameters. - Separate location of structure building.
- Reduction of codes. - Normalize comma positions.
No. I did this because it makes for a simpler code. Additional code would be needed to make this unsupported, would you do so?
I think it is better to have an description in the commit, so I wrote it in the commit message. If this is not clear, I will add the explanation to the first comment. I checked all the changes. No changes were found that were not included in the list. See the commit message for a summary of the refactoring. (Mouse-over the commit link for a quick view)
If I rebase the history now, I will make it more confusing. So I will go ahead and study it. |
The commit history looks very nice now, thanks! 👍
Ah ok. I think we can live with the way it is now, maybe just don't advertise So the only topic left is the naming 😅 |
I haven't spend much thought on it, but on first glance I like |
Regarding some of the opinions on the naming, I would say that I'm not too picky on which direction, but I would prefer if whichever attribute that is being used is descriptive on the functionality. Since the idea is that we are exporting or connecting methods/properties to godot, using the term If it were feasible, I might actually be more inclined to go the otherway by changing Then again, since it's also possible to use the explicit module path with the proc macro, I really like the readability of I'm be happy with these changes. |
Everyone: more input on If there's no progress in the naming, I might merge this soon and we handle the naming discussion separately (with a potentially breaking change on This would allow us to integrate the proc-macro changes already, and make room free for other improvements on that codebase. |
This PR looks fairly good! 🙂 I added some commits:
Feel free to merge/rebase with your own commits as you wish, I don't insist on my commits (or their authorship) to be retained as-is. Just kept it as 3 commits so it's easier to see independent changes, we can also squash them. Note that
Let me know what you think! Would be nice to merge this soon 🚀 |
Thanks for the great documentation! 😄 I am a machine translated english as you can see, so it would be very helpful for me to write the document instead.
Oh my god! 😱 However, it is unlikely that we will reach a consensus if we continue to discuss this, so this will do for now. Once #350 is implemented, we can truly write Finally, I have committed some fixes, so take a look. |
Thanks a lot for all this great effort! 👍
Haha 😅 But to get more feedback, we need people to try the new syntax, and this won't happen in an unmerged PR. The new #[godot(base)]
fn my_method(&self, base: &Node); So I'm definitely open for further discussion on this matter! bors r+ |
Build succeeded: |
933: Rename `#[godot]` to `#[method]` r=Bromeon a=Bromeon Follow-up to #872. As mentioned there, the syntax was provisional and still subject to change. This PR renames `#[godot]` back to `#[method]`. Other changes, such as the `#[base]` parameter name, remain unaffected (still a bit conflicted about that too, but that's another story...) Reasoning behind the name `#[godot]` was a potential greater unification of godot-rust attributes, which would allow to use `#[godot]` more widespread as _the_ attribute, e.g. ```rs #[derive(NativeClass)] #[godot(inherit=Node, no_constructor)] struct MyClass { #[godot(get)] my_property: i32, } #[godot_api] impl MyClass { #[godot] fn my_method(&self, #[base] base: &Node) {...} } ``` However, this comes with a bigger change. In order to avoid huge deprecations or breaking changes, I think it makes sense to not include this in the current minor version. It could be discussed for v0.11, or maybe only for GDExtension. Since having `#[godot]` in only one place would be "somewhere in between" the old and new naming, I'd rather find an identifier that fits the existing `#[property]` and `#[methods]` naming scheme -- and `#[method]` as suggested by the original author would fit relatively nicely. Overall, I still believe "method" is not expressive and there is room for improvement, as well as for other names like "property" or so. But I don't want this to delay the whole 0.10.1 release further; we'd rather think about nicer naming another time, maybe when GDExtension is around. This PR introduces a breaking change toward `master`, but not toward the last released version `0.10.0`, so it can be included in `0.10.1`. Co-authored-by: Jan Haller <[email protected]>
933: Rename `#[godot]` to `#[method]` r=Bromeon a=Bromeon Follow-up to #872. As mentioned there, the syntax was provisional and still subject to change. This PR renames `#[godot]` back to `#[method]`. Other changes, such as the `#[base]` parameter name, remain unaffected (still a bit conflicted about that too, but that's another story...) Reasoning behind the name `#[godot]` was a potential greater unification of godot-rust attributes, which would allow to use `#[godot]` more widespread as _the_ attribute, e.g. ```rs #[derive(NativeClass)] #[godot(inherit=Node, no_constructor)] struct MyClass { #[godot(get)] my_property: i32, } #[godot_api] impl MyClass { #[godot] fn my_method(&self, #[base] base: &Node) {...} } ``` However, this comes with a bigger change. In order to avoid huge deprecations or breaking changes, I think it makes sense to not include this in the current minor version. It could be discussed for v0.11, or maybe only for GDExtension. Since having `#[godot]` in only one place would be "somewhere in between" the old and new naming, I'd rather find an identifier that fits the existing `#[property]` and `#[methods]` naming scheme -- and `#[method]` as suggested by the original author would fit relatively nicely. Overall, I still believe "method" is not expressive and there is room for improvement, as well as for other names like "property" or so. But I don't want this to delay the whole 0.10.1 release further; we'd rather think about nicer naming another time, maybe when GDExtension is around. This PR introduces a breaking change toward `master`, but not toward the last released version `0.10.0`, so it can be included in `0.10.1`. Co-authored-by: Jan Haller <[email protected]>
Resolve #850
Feature
Allows onwer argument to be omitted.
By adding the #[base] attribute to the argument, it is defined as the owner argument. Only the second argument can be the owner argument. Also, there is no way to define the owner argument without #[base].
All optional parameters that can be used with the #[export] attribute can also be used with #[method].
Compatibility
The old syntax #[export] attribute will continue to be supported. (It does not support omission of the owner argument.)
The
godot_wrap_method!
macro is not compatible because its definition has changed. (Can be fixed for compatibility if needed)Written tests. (B-head#1)