pyd.def

Contains utilities for wrapping D functions.

struct ModuleName (string _modulename);
Param of def

struct Docstring (string _doc);
Param of def, Def, StaticDef

struct PyName (string _name);
Param of def, Def, StaticDef

struct Mode (string _mode);
Param of Property, Member

void def (alias _fn, Options...)();
Wraps a D function, making it callable from Python.

Supports default arguments, typesafe variadic arguments, and python's keyword arguments.

Params:
fn The function to wrap.
Options Optional parameters. Takes Docstring!(docstring), PyName!(pyname), ModuleName!(modulename), and fn_t
modulename The name of the python module in which the wrapped function resides.
pyname The name of the function as it will appear in Python.
fn_t The function type of the function to wrap. This must be specified if more than one function shares the same name, otherwise the first one defined lexically will be used.
docstring The function's docstring.

Examples:
import pyd.pyd;
string foo(int i) {
    if (i > 10) {
        return "It's greater than 10!";
    } else {
        return "It's less than 10!";
    }
}
extern (C)
export void inittestdll() {
    def!(foo, ModuleName!"testdll");
    add_module("testdll");
}
And in Python:
>>> import testdll
>>> print testdll.foo(20)
It's greater than 10!


void py_init ();
For embedding python

void py_finish ();
For embedding python, should you wish to restart the interpreter.

PyObject* module_init (string docstring = "");
Module initialization function. Should be called after the last call to def. For extending python.

void add_module (Options...)();
Module initialization function. Should be called after the last call to def.

Params Options = Optional parameters. Takes Docstring!(docstring), and ModuleName!(modulename) modulename = name of module docstring = docstring of module

enum PyInitOrdering ;


Before
call will be made before Py_Initialize.

After
call will be made after Py_Initialize.

PyInitOrdering ModuleInit ;
call will be made at the appropriate time for initializing modules. (for python 2, it should be after Py_Initialize, for python 3, before).

void on_py_init (void delegate() dg, PyInitOrdering ord = ModuleInit);
Use this to wrap calls to add_module and the like.

py_init will ensure they are called at the appropriate time

Page was generated with on Sun Nov 11 11:29:00 2012