Allow GodotExt
syntax to be used for virtuals
#188
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#136 introduced virtual function dispatch, and with it a new syntax for
init
,ready
etc:As you can see, there is now quite a bit of repetition, although (2) could use
Base<Self::Base>
.I took it as a challenge to see if it's possible to still use
GodotExt
in place of the*Virtual
name:This turned out to be not straightforward, because
#[godot_api]
does not know the base class ofPlayer
at that point. But trick 77, which I had already used in a variation for theInherits
declarations, came in handy: I'd define a declarative macro during the#[derive(GodotClass)]
, which would help resolvePlayer
to its base nameArea2D
. So the proc-macro could eventually replaceGodotExt
with the true trait.This works as demonstrated by this PR. But there are a few trade-offs to keep in mind:
#[class]
.engine::NodeVirtual
.GodotExt
is not a real trait, but a magic placeholder substituted by the proc-macro. I added a doc-alias so one would findGodotExt
in the docs (under#[godot_api]
), but still.GodotExt
and*Virtual
. While identical in semantics, it's not clear to the user which one they should choose or if there's a difference. I'm also not sure if the repetition is a problem in the first place, or rather makes code clearer by expressing which functionality is inherited.Thoughts? This is a draft, and we may end up not merging it.