-
Notifications
You must be signed in to change notification settings - Fork 76
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
Adds #signal Macro #190
Adds #signal Macro #190
Conversation
I love this change. Here are some thoughts that I have:
Here are the Api changes for this PR: https://gist.github.com/migueldeicaza/7c0624034196453574075d375a51ec2e |
p ("public init? (_ from: Variant)") { | ||
p ("guard from.gtype == .\(gtype) else") { | ||
p ("return nil") | ||
} | ||
p ("var v = \(bc.name)()") | ||
p ("from.toType(.\(gtype), dest: &v)") | ||
p ("self.init (from: v)") | ||
} | ||
p("public static func unwrap(variant: Variant) -> Self?") { | ||
p("guard variant.gtype == .\(gtype) else { return nil }") | ||
p("var value = \(bc.name)()") | ||
p("variant.toType(.\(gtype), dest: &value)") | ||
p("return value") | ||
} |
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.
Perhaps this might be me, but I feel that the initializer was more appropriate in this context, and not specifically for type casting reasons. Rather, because we are constructing something with that variant. unwrap
would imply to me that Variant is actually a representation of an optional, which, I think, might be a little confusing.
usage: UInt32 (usage.rawValue)) | ||
usage: UInt32 (usage.rawValue) | ||
) |
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.
Is there a particular reason why the closing parens was moved here?
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, just a personal code formatting habit that leaked in. I'd love to start using something like swiftformat on this project some day, we've got a lot of styles mixing here.
For now I'll revert this part because it doesn't belong in the PR.
|
||
/// Describes a signal and its arguments. | ||
/// - note: It is recommended to use the #signal macro instead of using this directly. | ||
public struct SignalWithNoArguments { |
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.
I'm noticing that SignalWithNArguments
feels ergonomically similar to that of SwiftUI's TupleView. Perhaps we can glean from that, so that we're not manually writing all these cases out?
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.
On the surface, I don't see a way that can work and still give us the nice emit
functions that enforce the types, but if you can say more about what you have in mind I can take another look.
Yeah I think you and @alicerunsonfedora are right to call this out. I'm not super happy with unwrap either. I have a feeling that GodotVariant is now be attempting to be too many things. I will think about it some more and explore alternatives.
Good point, I can definitely change this. Thanks for the feedback! |
Apologies folks, I accidentally merged this patch, and I have now undone the push. I think we can reopen this. |
I'll repost soon. Noting some other feedback from a friend: a member macro might be more appropriate that a freestanding one, so I'll also look into that. |
One small observation, the
|
Another question, you mentioned:
I could not figure out how Object or Wrapper are made to conform to There are no conformances to it that I could find. |
Hmm, I see the difference but I don't quite follow why it should call the initializer?
If we now call |
I added these manually in my game project when they were needed. But I'll look at this again as part of re-considering |
Adds a new freestanding macro that can be used inside a
@Godot
class to register a signal with Godot.Signal arguments can be defined and their types will be enforced on new
emit(signal:_argument)
methods.This all works nicely with the Godot editor too — signals are exposed there and can be connected to GDScripts and well use the argument names provided in the
#signal
invocation.I did have to change
GodotVariant
'sinit()
requirement to be anunwrap
so that subclasses of Godot objects could be made to conform to it. This makes the PR a bit more wide-reaching, but it means that it is possible to send a Node object as an argument to a@Callable
now.