http://code.dlang.org/packages/autowrap

This came out of the need at work to take existing D code and make it available for both Excel and Python.

Both pyd and excel-d make the reasonable assumption that one is using them to write code specifically for those environments. That breaks when there's existing production D code one wants to wrap.

The idea is to not "dirty" the existing code with dependencies on either pyd or excel-d and instead wrap them from outside the existing dub packages, whilst still using pyd and excel-d behind the scenes.

The end result is that if you have two D modules called `my.module1` and `my.module2` and you want to create a Python extension called `mylibrary`, then one dub.sdl and one source/app.d such as this is enough:


    import autowrap.python;
    mixin(
        wrapAll(
            LibraryName("mylibrary"),
            Modules("my.module1", "my.module2", /* ... */),
        )
    );

Seriously, that's it.* Well, other than the fact that dub will produce libmylibrary.so on Linux and what you need is mylibrary.so, so you'll have to rename the file.

The functions that are to be enabled for wrapping must be marked `export`, both for Python and Excel. It is a form of tagging and the production code must be changed to accomodate it, but at least it introduces no extra dependencies.

For Python, any struct used in an `export` function's parameters or return type is automatically wrapped, as well as any structs inside it.


Atila


* Except maybe for those pesky bug things I can't seem to get rid of.

Reply via email to