48 hour game jam
Jacob Carlborg
doob at me.com
Tue Oct 16 23:35:28 PDT 2012
On 2012-10-16 19:57, Ethan wrote:
> I'm just going to throw it out there that you don't actually need to
> touch Objective-C at all. Cocoa/Foundation/all those Objective-C
> interfaces sit on top of something known as Core Foundation, which are C
> APIs. The pointers used by Core Foundation can generally be used as
> Objective-C objects of the same type as well.
That's not entirely correct. Most of the types in Core Foundation are a
toll free bridge to the corresponding Objective-C types in the
Foundation framework. But all the GUI related classes, i.e. AppKit, are
not available in the same way.
> It would be handy to have a D binding to all the Core- libraries on OSX.
> I might do that myself when I get my Mac if such a binding doesn't
> already exist. The book should be equally applicable for iOS as well,
> but last time I was in iOS land I was still a newbie to the whole OSX
> programming thing.
If you're going to write GUI applications on Mac OS X you need to
interact with the Objective-C frameworks. The reason for this is that,
as stated above, AppKit is only available from Objective-C and you
really need to be able to create your own Objective-C classes and
subclasses.
There are two ways to interact with Objective-C
* Create an Objective-C/D bridge
* Make D binary compilable with Objective-C
The Objective-C/D bridge would use the Objective-C runtime functions
defined in C to interact with Objective-C. Every time an object is
passed over the bridge it needs to be encapsulated or de-encapsulated.
Another problem is the code/template bloat. A Hello World application
will be around 60MB in size. This has already been done:
http://www.dsource.org/projects/dstep
The other approach would be to make D binary compaitable with
Objective-C, that is, provide extern (Objective-C) declarations. This
would generate basically the same code as the Objective-C compiler
would, but with the nice syntax of D instead of the horrible syntax that
Objective-C is. This would also allow you do create bindings to
Objective-C classes, methods and functions just as with C.
The problem with this approach, it's a lot of work to modify the
compiler. But that has already been done as well:
http://michelf.ca/projects/d-objc/
This fork of DMD isn't ready yet (there's an alpha available) and there
hasn't been any changes made in over a year. If I recall correctly,
Michel Fortin said he hasn't got the time now to work on this. It also
the problem with always playing catchup with the upstream version of DMD.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list