-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Allow godot-visible functions to receive a Gd instead of self. #396
Allow godot-visible functions to receive a Gd instead of self. #396
Conversation
4418908
to
4b9c57a
Compare
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-396 |
Did you test whether this solves the issue in #338 ? |
It doesn't solve #338 because that involves implementing a trait that already defines on_notification to use &mut self. |
I'd find it a bit weird for it to not be possible to do this for the trait methods as well as regular methods. It would require a bigger change to codegen to do this though which would probably cause a conflict with #387. that's kinda why i waited with doing this. but it might still be nice to have this for user-defined functions before then. would it be better to tag the argument rather than the function? also there should definitely be some tests for this. i dont think using |
|
Wouldn't it be possible to scan for whether the type of the first parameter is |
how do you distinguish between that and a static method that takes a |
i could yeah, i didn't test it very much. i just did it quickly to see what would be needed to implement this. I'll see if i can find it again. |
My bad, thought rust-lang/rust#44874 was already stabilized, which would have lended itself for this purpose. You are right, it does not work if we cannot name the Gd parameter |
@mhoff12358 here: https://github.com/lilizoey/gdextension/tree/feature/instance-storage-get-gd. I haven't tested this much beyond just checking that it works (by manually calling all the functions). But i think this should work. |
76ec1f5
to
0dae372
Compare
I've pulled in lilizoey's commit adding a |
godot-core/src/storage.rs
Outdated
@@ -113,7 +122,7 @@ mod multi_threaded { | |||
use std::sync; | |||
use std::sync::atomic::{AtomicU32, Ordering}; | |||
|
|||
use crate::obj::GodotClass; | |||
use crate::obj::{Base, Gd, GodotClass, Share}; |
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.
Oh i forgot to add Inherits
as an import here, that's why the CI failed.
0dae372
to
1d66d7a
Compare
Alright, tests finally added. It's a really simple case, but still. Lemme know if you'd like it to do something more complex. |
Whoops, the test broke clippy. Seems I introduced a warning. But I really need to get to bed, I'll fix it tomorrow |
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, this is a nice feature on the road to #338!
9f79a6d
to
9f04e1f
Compare
I improved the test case to actually trigger the error condition. |
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 for the update! 🙂
Some more comments. There are also some conflicts at the moment.
godot-macros/src/class/godot_api.rs
Outdated
sig.params[0].0 = FnParam::Receiver(FnReceiverParam { | ||
attributes: vec![], | ||
tk_ref: Some(proc_macro2::Punct::new('&', proc_macro2::Spacing::Alone)), | ||
tk_mut: None, | ||
tk_self: Ident::new("self", proc_macro2::Span::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.
You construct a &self
parameter here, but what is this used for?
And how do you know it's not &mut self
?
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 is an attempt to simplify func.rs
's get_signature_info
method. Now there's no case where both gd_self
being true and the first argument being &self
or &mut self
can conflict set receiver_type
twice.
I don't love this, and could also go back and just add a panic! to get_signature_info
if the first argument is &self
.
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.
Thinking on it again, there's already a panic! in get_signature_info
.
I think it makes sense to inelegantly handle the case where gd_self
is true and the first argument is &self
in get_signature_info
with a panic! as a fallback. And then have process_godot_fns
check for that case and emit a prettier looking bail error instead.
I'll upload a separate commit that switches to that, so it'll be easier to go with which you prefer.
9f04e1f
to
23fbfd3
Compare
c2b9dfb
to
94f4866
Compare
9853ffc
to
cd921c7
Compare
The test case that triggers the error seems to cause the integration test runner to fail on any non-windows machine. Even though every individual test passes. |
CI checks for the string What you could try is explicitly disable type annotations by using var gd_self_reference: Variant
# or just:
var gd_self_reference instead of: var gd_self_reference: GdSelfReference This should move the error from parse time to runtime. |
@mhoff12358 Do you think you'll have time to update this over the next few days? 🙂 |
Yeah, hopefully tonight or tomorrow now that it's the weekend.
…On Sat, Sep 30, 2023, 3:41 AM Jan Haller ***@***.***> wrote:
@mhoff12358 <https://github.com/mhoff12358> Do you think you'll have time
to update this over the next few days? 🙂
—
Reply to this email directly, view it on GitHub
<#396 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHXX7ZUKRRQGBLUYXXQBTDX47LK7ANCNFSM6AAAAAA4JZO4NE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
3d71798
to
d33813c
Compare
This is done by tagging the function with #[func(gd_self)].
d33813c
to
c28de15
Compare
This actually is a runtime error. Godot spits out "SCRIPT ERROR: Invalid call. Nonexistent function 'function_name' in base 'RustClass'." at runtime if function_name does exist but panics inside rust. I don't see any easy way to do something that would assert for that error and prevent it from causing a real failure, so I commented out the test with a todo to re-add it if someone does build a way to depend on that kind of failure. It looks like tests are passing, other than an issue with credentials in the docs test. (They're currently rerunning because I rebased to not have an unnecessary extra commit). Were there any other outstanding issues? |
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! The docs is something I have to address separately, but it's not part of the main CI.
This is done by tagging the function with #[func(gd_self)].
I haven't written tests because there was an unrelated issue on my machine, but I have tested with a different project and it seems to work.