-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Multiple #[godot_api] impl
blocks
#925
Comments
Supporting multiple Are you interested in investigating the feasibility? We could of course give you some guidance in the code. |
#[godot_api] impl
blocks
I'd like to add one practical use case which comes to mind - I think it makes significantly easier to add stuff to multiple Godot classes with declarative macros, as it makes possible to keep the main This can help to simplify project-specific declarative macros which add traits to Godot classes and automatically expose trait methods to the engine, and apply such macros selectively. This case might be covered by builder API in future, though. |
yep that's exactly how it works, only requirement ist for all of them to be in the same file, so you can't split it up over multiple files. Since it has now been merged you can try it out by referencing gdext from github instead of crates.io. |
@0x53A Thank you a lot for this change! macro_rules! expose_trait_foo {
($id:ident) => {
#[godot_api(secondary)]
impl $id {
#[func]
fn on_foo(base: Gd<Self>, arg: i32) {
Self::foo(base, arg) # <- ensures 'foo()' has consistent signature
}
}
}
}
expose_trait_foo!(SomeStruct);
expose_trait_foo!(OtherStruct); It's really helpful to be able to apply consistent function signatures to different engine-exported types. It feels like a much nicer alternative to multi-inheritance, as it allows to mix and match different interfaces needed for a specific cases while keeping the entirely flat hierarchy, similar to mixins. With full dynamic capabilities of Godot's runtime reflection, but also with compile-time checked signatures. |
At the moment only one
#[godot_api]
impl block is allowed (and second one to implement the base class interface).The error message with multiple blocks is
Of course, the workaround is trivial, just put everything into one block, so this isn't important, but it would be really nice to have.
For code organization, I have been experimenting with a pattern where I define and implement a relative fine-grained trait in a node then create a godot function to wrap that trait.
Example what I'd like to do:
I don't yet know if this system of code organization makes sense, but that's beside the point.
My arguments why I would like to have multiple
#[godot_api]
blocks:The text was updated successfully, but these errors were encountered: