-
Notifications
You must be signed in to change notification settings - Fork 210
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
Handle generics in NativeScript derive and #[methods]
#983
Conversation
This is useful mainly for skipping marker fields in generic code.
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.
Very nice addition! I especially like how you found a way to use the natural type-aliases to register monomorphizations:
#[gdnative::derive::monomorphize]
type IntPair = Pair<i32>;
I was first under the impression this would need to happen in the scope of the NativeClass
macro itself.
Proc-macro code for To/FromVariant
has reached quite a complexity already, but I think that's in the nature of proc-macros. Those two traits have become very powerful in the meantime, with lots of serde-like features! 💪
Would you add monomorphize
to the prelude, or do you think it's rare enough to deserve a qualified import/path?
test/project/main.gd
Outdated
if !status: | ||
printerr(" !! _test_generic_class failed") | ||
|
||
return status |
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.
Maybe add newline at end of file?
The derive macros are now aware of both lifetime and type parameters. `'static` bounds are added to both kinds, which improves the error message shown when a user tries to put a lifetime into a NativeClass. This behavior is chosen because unlike type parameters, lifetime parameters aren't very useful in this context: only `'static` would be supported anyway, and any attempted usage is hightly likely to have originated from user error.
aee97b0
to
81e1bff
Compare
Admittedly, there is indeed a lot of complexity in those two macros. It's more of an unfortunate consequence of Godot having a richer data model than what serde allows (
I don't think it's prelude-worthy. It isn't something you'd expect to use in every other file in the average project. |
I'll be merging this in a day, in case there are no further comments. |
bors try |
tryBuild succeeded: |
bors r+ |
Build succeeded: |
The derive macros are now aware of both lifetime and type parameters.
'static
bounds are added to both kinds, which improves the error message shown when a user tries to put a lifetime into a NativeClass.This behavior is chosen because unlike type parameters, lifetime parameters aren't very useful in this context: only
'static
would be supported anyway, and any attempted usage is hightly likely to have originated from user error.Also added the
#[skip]
attribute for skipping fields inFromVarargs
. This is useful mainly for skipping marker fields in generic code.Close #601
Error message
The error message that appears when lifetime parameters are declared for
NativeClass
types now clearly indicate where the problem lies and what the expectations are:Compares this with the old error message:
Close #174