Calypso and the future of D

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 26 00:18:53 PST 2015


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


More information about the Digitalmars-d mailing list