The basics

Module basics

The most minimal working Pyd module looks something like this:

import pyd.pyd;

extern (C) void PydMain() {

The first line imports Pyd:

import pyd.pyd;

The pyd module in the pyd package publicly imports all of the other components of Pyd.

The PydMain function is called when the module is imported by Python. You will call most of Pyd's API from here. At the very least, PydMain must contain a call to module_init. The module_init function has the following form:

PyObject* module_init(char[] docstring="");

It does little more than call Py_InitModule and return the new module object. This object is also available via the Pyd_Module_p property once you've called module_init.

Due to the way in which Pyd implements function and class wrapping, any calls to def must occur before the call to module_init, and any calls to wrap_class must occur after the call. I know this seems like a rather arbitrary rule, but it is important. Calls to def in the wrong place will simply be ignored, and calls to wrap_class in the wrong place will throw an assert.

PydMain will catch any D exception that is thrown from inside it, and safely pass that exception to Python.