-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
generate cgo Objective-C bindings #56
Conversation
The NSString definition was generated with:
And then run through |
objc2/objc.go
Outdated
@@ -0,0 +1,52 @@ | |||
package objc2 |
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 started a new package for this to experiment with the minimal amount of code needed to support the generated definitions. Based on how this goes we could either integrate the dynamic Send
methods directly, or move that into a separate package that could be called on an object Send(obj, "selector:")
Can we schedule a call on Discord to go over this. |
examples/pomodoro/main.go
Outdated
obj.Retain() | ||
obj.Button().SetTitle("▶️ Ready") | ||
// TODO implement inheritance to get "title" prop from button | ||
appkit.NSButton_setTitle_(obj.Button(), foundation.NSString_FromString("▶️ Ready")) |
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.
@progrium I guess ideally we'd want macschema
to parse out the "Inherits From" info, but for now I could implement a quick hack to parse this info out of the schema on the generator side:
"Declaration": "@interface NSStatusBarButton : NSButton",
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.
👍
looks like its starting to come together! |
Generates cgo code and Go wrappers to call the Objective-C methods. Type information in `api` is generated using `macschema` to fetch and parse from the docs. `go run ./gen/cmd` generates the `*_objc.gen.go` files containing the cgo code to invoke each Objective-C method, and Go wrappers on top of it. The generated types are meant to be embedded by the author in a struct to include the generated methods, but allow the author to augment them with additional methods, like: ``` type NSFoo struct { gen_NSFoo } ```
pls remove the 1.15 test and add 1.17 so checks pass as something here is using io/fs |
The generator uses `embed.FS` to include the template file, which is new in Go 1.16.
Generates cgo code and Go wrappers to call the Objective-C methods. Type information in
api
is generated usingmacschema
to fetch and parse from the docs.go run ./gen/cmd
generates the*_objc.gen.go
files containing the cgo code to invoke each Objective-C method, and Go wrappers on top of it.The generated types are meant to be embedded by the author in a struct to include the generated methods, but allow the author to augment them with additional methods, like: