-
-
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
Add #[init(...)]
to be used by generated init
function
#199
Comments
Thanks! All attribute APIs currently follow this schema: #[attribute(key, key = value, ...)] And it would be nice to keep it that way, because:
Maybe we can additionally consider Arbitrary expressions have some other issues: scope/visibility, order of initializations, side effects. I don't think we need to support them from the start. Even just Also, why is Brainstorming alternative syntaxes: #[init(default)]
#[init(default = value)]
#[init(default_alloc)] |
Note that even Scope is clear: same as where the expr is written, since it lives in the same module as the generated impl. Initialization order is also clear. And not usually relevant. Side effects are possible but I don't see the problem with that. |
I like |
No, negatives as well as gdext/godot-macros/src/util.rs Lines 498 to 512 in eb30a8b
It's still limiting, but could serve as a start. For string literals we should definitely have a way to let Further extending
One thought was that #[init(onready)]
lateinit_field: Option<...>, However, that may also be confusing, as "init" explicitly refers to the constructor otherwise. Anyway, can be revisited later...
That's nice, then we don't need to fully qualify anything and
Yeah, it would need to be quite deliberate. I also think it's going to be fine -- wouldn't really be possible to prevent. |
That would be good. Could be a simple matter of unconditionally calling
Agreed. I think it'll be doable, because a comma is never at the top level of an expression. And it never will be, because this would give ambiguities when parsing function arguments as well. So we just run through the tokens, pushing and popping matching brackets onto a stack, until we find a comma while the stack is empty. |
#[default(...)]
to be used by generated init
function#[init(...)]
to be used by generated init
function
203: Make `get` and `set` arguments take identifiers instead of strings r=Bromeon a=ttencate Refactors `KvParser` to accept some expressions, as long as they don't contain a comma at the top level outside any pair of `[]`, `()` or `{}`. Also tightens up spans in error messages quite a bit. Prelude for #199. Co-authored-by: Thomas ten Cate <[email protected]>
Right now, the
init
function created by#[class(init)]
invokesDefault::default()
for each field. This is already somewhat useful, but not sufficient if there are fields with types likeGd<Node>
.I was tempted to implement
Default
forGd
, but this would completely hide the allocation and very likely lead to the user forgetting to manuallyfree()
it.So it would be nice if we could specify a different default instead. Proposal:
#[default]
or not annotated at all, useDefault::default()
.#[default(...)]
, use the...
as the initializer. I think we can support arbitrary expressions here because parentheses are always balanced, but would have to see how far we can get with this. This would support the use case above:#[default(Node::new_alloc())] my_node: Gd<Node>
makes the allocation visible.Note that
#[default]
is orthogonal to#[export]
, which is why we don't write#[export(default = ...)]
.The text was updated successfully, but these errors were encountered: