-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Extract CallbackBridge from Document. #327
base: master
Are you sure you want to change the base?
Conversation
That's a good step in cleaning up the mess that is Few notes, mostly affecting coding style:
|
Ah! I was wondering about that; thank you for confirming. I will update to follow the standard prefix conventions here. Added a TODO. |
Is this something you'd be open to discussing further? I'm using some of these APIs from Swift code and the nullability annotations make a big difference in ergonomics there. I've found that annotating the nullability of some of these APIs also helped better clarify the expected behavior (e.g. NULL has special meaning in some cases that isn't immediately apparent from the method signature alone). I'd love to learn more about "bad practices such as dangerous casting" because this conflicts with Objective-C/Swift interop. |
Added TODOs. Thank you! |
Ah this is good to know, I've added a TODO to clean this up. |
Agreed that this API felt a bit out of place. I've replaced the method with an externalized C callback that can be passed directly to |
Gently checking in here to see if there's anything remaining for me to clean up. |
Sorry I haven't replied, I didn't have time working on SameBoy the last few weeks, I'll go over the PR again in a few days. |
No worries! Thank you for the great feedback :) |
Finally had time to go over the code, sorry for the delay! Other than my issue with nullability, everything looks fine. My issues with with nullability are:
For that reason I avoid nullability in my Objective-C codebases. Now, I understand this only affects the Swift integration but I'm afraid this will encourage further use of nullability in future 3rd-party contributions and forks. My familiarity with Swift is fairly limited (I've mostly reversed Swift code and that was painful enough ><), but is there a way to handle this issue in the Swift bridging mechanism rather than the Objective-C headers? If that's not possible I'd settle for a comment in these two affected files explaining these are merely for allowing integration of this object into Swift codebase. |
53fbbbd
to
4ebe973
Compare
This new class enables a generalized mechanism for connecting Objective-C and Swift types to GB_gameboy_t's callback mechanisms. It has been extracted from Document.m, and Document.m now uses this type to facilitate all callbacks.
Also as part of this change:
GB_get_user_data
exist outside of CallbackBridge.m, as theGB_get_user_data
value has changed from a Document to a CallbackBridge.This change reduces the size of Document.m by 104 lines (from 2040 to 1936).
TODO
CallbackBridgeDelegate
and other exported symbols should have theGB
prefix (e.g.GBCallbackBridgeDelegate
). The Document class is an exception due to an Apple convention.gotNewSample
is actually optional, it will only be called if you first set the sample rateinitWithGB
should beinitWithGameBoy
{
following a method definition belongs on its own lineconnectPrinter
makes sense as a bridge APIconnectLinkCableWithPartner
should beenableSerialCallbacks
instead and should not have a partner parameter, as a Link Cable between two Game Boys is just one of many use cases of the serial API. Document.m should just callenableSerialCallbacks
for both the master and slave Game Boys.Part of #324