[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Sun, 12 Oct 2003 19:12:02 +1000
On Sunday 12 October 2003 04:23 pm, Rhys Weatherley wrote:
> We should look into the Objective-C ABI to see if we can do better
> with that language.
I had a look through Apple's Objective-C documentation, and I think this is
doable. The <objc/objc-api.h> interface contains a number of functions that
can be used to walk the class hierarchy at runtime, enumerate all of the
methods, create objects, send messages, etc.
There would be two parts to wrapping up Cocoa in C#. The first would involve
writing a C program which walks the Objective-C classes and outputs the
corresponding C# definitions, with all of the necessary interop attributes
and what-not in place. This would be mostly automatic, I think.
The second part is hooking up object instantiation and message dispatch. You
could import the "objc-api" helper functions from "libobjc4.dylib", and call
them directly from the C# constructors and methods. A simple "IntPtr" would
be used to represent the actual Objective-C object.
Constructors would call "objc_lookUpClass" and then "class_createInstance".
Methods would call "class_getInstanceMethod" followed by "obj_msgSendv". Or
something like that. It may be possible to do all of this in Portable.NET
now, using the current PInvoke facilities.
Eventually, we could move the "objc-api" stuff directly into the runtime
engine so that it happens automatically when an appropriately-marked C# class
is loaded. The CVM coder would be able to cache class pointers and method
selectors, making the binding more efficient. But that will have to wait
until after I rearrange PInvoke following DotGNU 0.1.
I hope this helps get you started. With any luck, you can simply write a
conversion program that spits out C# definitions, without needing to wrap
very much by hand in C.