Difference between revisions of "PortingOverview"

From D Wiki
Jump to: navigation, search
 
Line 8: Line 8:
 
Interfacing D with an existing codebase
 
Interfacing D with an existing codebase
 
---------------------------------------
 
---------------------------------------
 +
 +
'''C'''
 
*[http://dlang.org/interfaceToC.html C interfacing is simple and complete - D can call C, and C can call D]
 
*[http://dlang.org/interfaceToC.html C interfacing is simple and complete - D can call C, and C can call D]
 
*[http://dlang.org/htod.html converting C header files to D under Windows]
 
*[http://dlang.org/htod.html converting C header files to D under Windows]
 
*[https://github.com/jacob-carlborg/dstep/releases converting C and Objective C headers to D under OS X/Linux/FreeBSD]
 
*[https://github.com/jacob-carlborg/dstep/releases converting C and Objective C headers to D under OS X/Linux/FreeBSD]
 
*[https://p0nce.github.io/d-idioms/#Linking-with-C-gotchas Linking with C gotchas]
 
*[https://p0nce.github.io/d-idioms/#Linking-with-C-gotchas Linking with C gotchas]
 +
 +
'''C++'''
 
*[http://dlang.org/cpp_interface.html C++ interfacing is a key priority of the D core team but much can already be done - in fact more than is described here]
 
*[http://dlang.org/cpp_interface.html C++ interfacing is a key priority of the D core team but much can already be done - in fact more than is described here]
 
*[http://forum.dlang.org/post/m9s4cd$2s1v$1@digitalmars.com Calypso: a pre-alpha very early stage project to interface D with C++ under clang]
 
*[http://forum.dlang.org/post/m9s4cd$2s1v$1@digitalmars.com Calypso: a pre-alpha very early stage project to interface D with C++ under clang]
 +
 +
'''Python
 +
'''
 
*[https://github.com/ariovistus/pyd PyD] creates seamless interoperation between D and CPython, including for numpy arrays.  [http://www.youtube.com/watch?v=y-k7GyOcs3o "It just works".]  Make sure you visit the github code, and not the old version up at bitbucket.
 
*[https://github.com/ariovistus/pyd PyD] creates seamless interoperation between D and CPython, including for numpy arrays.  [http://www.youtube.com/watch?v=y-k7GyOcs3o "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
 
*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
*[https://github.com/JakobOvrum/LuaD LuaD] creates a simple interface between D and Lua
 
  
 
<code> D calling embedded Python
 
<code> D calling embedded Python
Line 27: Line 33:
 
  </nowiki>
 
  </nowiki>
 
</code>
 
</code>
 +
 +
'''Lua'''
 +
*[https://github.com/JakobOvrum/LuaD LuaD] creates a simple interface between D and Lua
 +
  
 
<code> Lua D example
 
<code> Lua D example

Latest revision as of 11:59, 26 April 2015

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