progrium/darwinkit

Tutorial on how to add new Objective-C classes to MacDriver

Closed this issue · 9 comments

Currently there is no step by step directions on how to add Objective-c classes to MacDriver. I ask that this tutorial be made.

My current idea is to make a program that scans an Objective-C class header file and records all the methods and their arguments into an API database. Then a second program can take the data in the API database and translate it into Go code making an automatic wrapper.

I am reading the code in the cocoa package currently. This package has 35 files in it. It has one big file called cocoa_objc.gen.go. This file is over 21,000 lines long and has the implementation of many objective-c classes in it. One thing I don't understand yet is why there are other files in this folder. For example the cocoa_objc.gen.go file has the implementation of several NSFont methods. But there is still a file in the package called NSFont.go. This file only has one method implemented in it. Why is the NSFont.go file needed?

I did more research on the core package and found out it has the same format. The package contains one large file called core_objc.gen.go and a bunch of little files with the names of classes in objective-c. The core_objc.gen.go file seems to have code in it that translates objective-c to c, then from c to go. The other files seem to make the go code more human-friendly.

I am guessing the "gen" in core_objc.gen.go is for "generated". If this file was generated using a program could we see this program?

Just wanted to note if this tutorial is made, a section should be included that tells the user how to test out changes to this project.

You're right, and there is tooling here to generate that code based on schemas produced by the project macschema which is all still under development, though not actively by me at the moment. It will take some time for me to get back into it all and make sure it all works and create tutorials like this but thanks to you and others, I'm trying to find ways to prioritize it.

Some of this has been started in the project wiki here, for example:
https://github.com/progrium/macdriver/wiki/HowToAddTypes

I made the tutorial: https://github.com/progrium/macdriver/wiki/How-to-Contribute
Please let me know what you think. Suggestions and corrections are always welcomed.

tmc commented

I made the tutorial: https://github.com/progrium/macdriver/wiki/How-to-Contribute Please let me know what you think. Suggestions and corrections are always welcomed.

it might be better to suggest using a go.work file vs the replace directive.

@tmc the issue with that is it requires Go 1.18 or higher. There probably are people who are still using older versions of Go who might want to contribute.

Closing for now. At some point I'll try to clean it up, but good first pass.