On 2015-01-26 01:37, Walter Bright wrote:

I'm obviously terrible at communicating. Let me try again. Assume that I
wrote Calypso, and I was explaining it to you:

-----------------------------------------

Given the C++ header file foo.h:

     void bar(unsigned *);

and the C++ source file foo.cpp:

     void bar(unsigned *p) { }

I want to call bar() from my D code in test.d:

     void main() {
       uint x;
       bar(&x);
     }

Here's how to do it with Calypso:

     calypso foo.h

which will generate the file foo.d. add an import to test.d:

     import foo;

     void main() {
       uint x;
       bar(&x);
     }

To compile and link:

     clang++ foo.cpp -c
     dmd test foo.o

Which generates the program 'test' which can be run.

It works something like this:

Given the C++ header file foo.h:

    void bar(unsigned *);

and the C++ source file foo.cpp:

    void bar(unsigned *p) { }

I want to call bar() from my D code in test.d:

    void main() {
      uint x;
      bar(&x);
    }

Here's how to do it with Calypso:

    module test;

    modmap (C++) "foo.h";
    import (C++) _ : bar;

    void main() {
      uint x;
      bar(&x);
    }

To compile and link:

    clang++ foo.cpp -c
    ldc test.d foo.o

Which generates the program 'test' which can be run.

Calypso is not a separate tool. It's a fork of LDC which allows you to directly import/include a C++ header files and use the declarations from within D. No bindings or intermediate files are necessary.

--
/Jacob Carlborg

Reply via email to