-
Notifications
You must be signed in to change notification settings - Fork 79
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
GenericSignal helper class #587
GenericSignal helper class #587
Conversation
Not sure the best way to comprehensively test this. I think the one thing that might fail at runtime is the code that is unpacking the arguments to pass to the connect closure. It is assuming that they can be constructed from a Variant. This should be true, but it's not the same code as was in the old generated helpers. I've tested a bit with my own Godot project, but it would be good to try some others that make use of Godot-defined signals with parameters, and check that they work. |
3e12f3d
to
7ca7537
Compare
e64e458
to
de2fa45
Compare
I've cleaned up the formatting - the PR should now just contain the actual changes I've made. |
95efcb3
to
2be97a8
Compare
2be97a8
to
e9ee6dd
Compare
@@ -37,8 +37,8 @@ jobs: | |||
steps: | |||
- uses: compnerd/gha-setup-swift@main | |||
with: | |||
branch: swift-5.10-release | |||
tag: 5.10-RELEASE | |||
branch: swift-6.0.2-release |
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.
@migueldeicaza I thought I'd try bumping the version right up to 6.0.2 here to see if the Windows compiler's argument pack support was fleshed out, as I remember you speculating that it might not be fully functional in 5.10 on Windows.
The tests pass so I guess that it is.
I guess it might be worth setting the swift-tools-version to 6.0 if we truly do need Swift 6 on Windows - but then we'd have to add an explicit opt-out of the Swift 6 language model for now, to avoid having to deal with that whole can of worms...
Note that with @elijah-semyonov's variant changes, I think the generic class has to deal with the possibility of one of the arguments passed to a signal-with-arguments could be nil. I'm not sure if that's actually possible in reality? Since this code was written before that change was merged, for now I've just taken the simplest route and I throw an error for a nil argument, just like I would for one of the wrong type. I can probably eventually get nil arguments to work fine if they are needed, but I wanted to minimise the changes after rebasing, so it might be simpler to tackle it in a follow-up PR later. |
The lack of support for One solution might be to bring back a
Or perhaps the only scenario we care about is passing an object that might be nil. I think that we might be able to get away with creating such an object, and manually set the handle to nil, and users of that code would need to test for 'object.isValid'. |
I am not a fan of 'object.isValid' approach, so perhaps we do need to introduce a Nil type, perhaps we can call it 'CallbackNil' to make it clear that it is to be generally shunned. |
4f4776f
to
fc03df2
Compare
I've revised this so that nil arguments should be passed through to the callback properly. |
After further discussion with @elijah-semyonov I've changed the generator as he suggested, so that primitive signal arguments are non-optional, but object ones are optional, in the actual signature of the GenericSignal. |
749140e
to
5aa8dfc
Compare
Require macOS 14 for the generic pack support Would bumping the swift-tools-version to 5.10 be better? Use generic signal instead of generating helper Don't use SimpleSignal Moved GenericSignal to its own file. Removed some unused code, tidied comments. Fixed popping objects. Cleaner unpacking, without the need to copy the arguments. revert unrelated formatting changes put back SignalSupport to minimise changes Removed SimpleSignal completely tweaked names for a cleaner diff Added test for built in signals
Not sure if we want to allow nil in arguments to signals - might have to do a little bit more work if so.
3943bfa
to
b4b4927
Compare
Thank you for nurturing this change. Cheers! |
See also #42
Instead of generating a helper class for each signal property, we use a single GenericSignal which can be specialised with the list of argument types that the signal contains.