www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Tutorial on C++ Integration?

reply Mike McKee <volomike gmail.com> writes:
I'm using Qt/C++ on a Mac. I want to try my hand at making a 
dylib in D that can receive a C++ string, reverse it, and respond 
with the result back to Qt/C++.

Are there any easy tutorials out there with something simple like 

You probably want me to type some code so that I showed that I at 
least tried something. Okay, here's me just guessing:

// test.dylib

auto _cstr2dstr(inout(char)* cstr) {
     import core.stdc.string: strlen;
     return cstr ? cstr[0 .. strlen(cstr)] : cstr[0 .. 0];

extern(C++) char*  reverseString(char* cstr) {
   import std.string;
   import std.algorithm;
   s = _cstr2dstr(cstr);
   s = s.reverse();
   return toStringz(s);

Also, what do I type to define this as a class that C++ can call, 
such as the following C++?

QObject Foo = new Foo();
qDebug() << Foo.reverseString('bar');

Next, I'm a bit fuzzy on how to compile that into a dylib yet, as 
well as how to call this inside of Qt/C++ with QtCreator.
Sep 28 2015
next sibling parent Kagamin <spam here.lot> writes:
http://wiki.dlang.org/Vision/2015H1 C++ integration was planned 
to be available by the end of 2015. May be too optimistic still.
Sep 28 2015
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2015-09-28 09:08, Mike McKee wrote:
 I'm using Qt/C++ on a Mac. I want to try my hand at making a dylib in D
Dynamic libraries are not officially supported on OS X. -- /Jacob Carlborg
Sep 28 2015