PortingOverview
This page is under community development.
Porting from C
Interfacing D with an existing codebase
C
- C interfacing is simple and complete - D can call C, and C can call D
- converting C header files to D under Windows
- converting C and Objective C headers to D under OS X/Linux/FreeBSD
- Linking with C gotchas
C++
- C++ interfacing is a key priority of the D core team but much can already be done - in fact more than is described here
- Calypso: a pre-alpha very early stage project to interface D with C++ under clang
Python
- PyD creates seamless interoperation between D and CPython, including for numpy arrays. "It just works". Make sure you visit the github code, and not the old version up at bitbucket.
- Other options are to use cython wrappings to connect to D, or to write in D directly to the Python API. There are examples of this in the PyD examples directory within PyD
D calling embedded Python
void main() {
auto context = new InterpContext();
context.a = 2;
context.py_stmts("print ('1 + %s' % a)");
}
Lua
- LuaD creates a simple interface between D and Lua
Lua D example
import luad.all;
void main()
{
auto lua = new LuaState;
lua.openLibs();
auto print = lua.get!LuaFunction("print");
print("hello, world!");
}