How to use D for cross platform development?

Bennie Copeland mugen.kanosei at gmail.com
Thu Mar 29 12:03:05 PDT 2012


On Thursday, 29 March 2012 at 16:36:57 UTC, Jacob Carlborg wrote:
> On 2012-03-29 14:44, Chris W. wrote:
>
>> Thanks for the link. Objective-C is basically C and can be 
>> implemented
>> in C style as far as I know. Is it worth going down to the C 
>> level like so:
>
> Yes that would be possible.
>
>> struct NSObject {
>> struct objc_class* isa;
>> }
>> struct objc_class {
>> Class isa;
>> Class super_class;
>> const char *name;
>> long version;
>> long info;
>> long instance_size;
>> struct objc_ivar_list *ivars;
>> struct objc_method_list **methodLists;
>> struct objc_cache *cache;
>> struct objc_protocol_list *protocols;
>> }
>>
>> Just a random thought.
>
> That's the alternative approach, I've done that as well. It's 
> very tedious and becomes verbose very fast.
>
> Both I and Michel have created an Objective-C/D bridge that 
> uses this approach. It lets you call Objective-C methods, 
> create instances of Objective-C classes, create subclasses in D 
> that inherit from Objective-C classes and so on. It did this 
> all automatically. The problem with the bridge was the enormous 
> template bloat. A GUI Hello World application takes around 60MB 
> with the bridge.
>
> http://www.dsource.org/projects/dstep
> http://michelf.com/projects/d-objc-bridge/
>
> That's why Michel started the DMD fork to directly support 
> binding to Objective-C classes and methods.
>
> If you just have a small amount of Objective-C code that needs 
> to be called and basically never changes then it won't be a 
> problem using the Objective-C runtime functions. Otherwise I 
> wouldn't recommend it.
>
> I've ported the SDL initialization code for Mac OS X to D, to 
> be used in derelict. This doesn't contain any fancy templates 
> like the bridge uses to help making the code less verbose. It's 
> quite a lot of D code compared to the Objective-C code:
>
> http://dsource.org/projects/derelict/browser/branches/Derelict2/DerelictSDL/derelict/sdl/macinit
>
> This would be the original Objective-C code:
>
> http://codespeak.net/svn/pypy/dist/pypy/rlib/rsdl/macosx-sdl-main/SDLMain.m
>
> If you're going with this approach you could have a look at my 
> bridge if you need help, it has some useful documentation of 
> how it works and is implemented:
>
> http://www.dsource.org/projects/dstep/wiki/ObjcBridge/BridgeInternals

Thanks for your help. My primary use case is to provide a native 
look and feel GUI on the Mac. So, to the extent of creating the 
interface using Cocoa and tying it back to the core code written 
in D.



More information about the Digitalmars-d mailing list