Difference between revisions of "PortingOverview"
Line 1: | Line 1: | ||
This page is under community development. | This page is under community development. | ||
+ | Porting from C | ||
+ | -------------- | ||
*[https://p0nce.github.io/d-idioms/#Porting-from-C-gotchas Porting from C gotchas] | *[https://p0nce.github.io/d-idioms/#Porting-from-C-gotchas Porting from C gotchas] | ||
− | *[ | + | |
+ | |||
+ | Interfacing D with an existing codebase | ||
+ | --------------------------------------- | ||
+ | *[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] | ||
+ | *[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] | ||
+ | *[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 | ||
+ | *[https://github.com/JakobOvrum/LuaD LuaD] creates a simple interface between D and Lua | ||
+ | |||
+ | <code> D calling embedded Python | ||
+ | <nowiki> | ||
+ | void main() { | ||
+ | auto context = new InterpContext(); | ||
+ | context.a = 2; | ||
+ | context.py_stmts("print ('1 + %s' % a)"); | ||
+ | } | ||
+ | </nowiki> | ||
+ | </code> | ||
+ | |||
+ | <code> Lua D example | ||
+ | <nowiki> | ||
+ | import luad.all; | ||
+ | |||
+ | void main() | ||
+ | { | ||
+ | auto lua = new LuaState; | ||
+ | lua.openLibs(); | ||
+ | |||
+ | auto print = lua.get!LuaFunction("print"); | ||
+ | print("hello, world!"); | ||
+ | } | ||
+ | </nowiki> | ||
+ | </code> |
Revision as of 11:55, 26 April 2015
This page is under community development.
Porting from C
Interfacing D with an existing codebase
- 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++ 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
- 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
- LuaD creates a simple interface between D and Lua
D calling embedded Python
void main() {
auto context = new InterpContext();
context.a = 2;
context.py_stmts("print ('1 + %s' % a)");
}
Lua D example
import luad.all;
void main()
{
auto lua = new LuaState;
lua.openLibs();
auto print = lua.get!LuaFunction("print");
print("hello, world!");
}