How To Call D Code from Objective C?
Jacob Carlborg via Digitalmars-d
digitalmars-d at puremagic.com
Thu Dec 10 23:53:52 PST 2015
On 2015-12-11 07:01, Mike McKee wrote:
> Is there a way to call D code from Objective C on OSX?
You can call Objective-C from D [1]. For the other way around, you
currently need to use the API for the Objective-C runtime [2].
> Here's something cool I was thinking about doing:
>
> * I've learned how to make Cocoa UI Objective C apps on OSX.
>
> * I've learned how to load the native OSX webkit widget in a Cocoa app.
> It provides a rich user interface using ordinary HTML, CSS, and
> Javascript/jQuery. It's much better than anything Qt has with its
> widgets or QML. It's much better than anything Apple allows with its
> other Aqua Cocoa widgets. I can make any kind of widget you can think
> of, colored and styled anyway I want, using webkit.
>
> * I've learned how to enable a bridge between Javascript to Objective C.
> This lets me make an Objective C function that Javascript can call. So,
> if I need my webkit app to do something powerful like show a file
> chooser dialog, I can call an object called "objc" and so something like:
>
> var sFilePath = objc.chooseFile();
Are these Objective-C functions or C functions?
> * Now all I want to do is to bridge Objective C to D. That way, my
> webkit pages can call Objective C, which can then call D. I can put much
> of the heavy lifting work in D for my app. If I need to call an Apple
> Foundation Class library, I can have D call back to Objective C just for
> that special thing.
You can call the Foundation classes directly from D.
[1] http://dlang.org/spec/objc_interface.html
[2]
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list