PortingOverview

From D Wiki
Revision as of 11:59, 26 April 2015 by Laeeth (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page is under community development.

Porting from C



Interfacing D with an existing codebase


C

C++

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!");
}