pyd.def
- template
def
(char[] name,alias fn,uint MIN_ARGS = NumberOfArgs!(typeof(&fn)),fn_t = typeof(&fn))
- Wraps a D function, making it callable from Python.
Params:
name |
The name of the function as it will appear in Python. |
fn |
The function to wrap. |
MIN_ARGS |
The minimum number of arguments this function can accept.
For use with functions with default arguments. Defaults to
the maximum number of arguments this function supports. |
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. |
Examples:
import pyd.pyd;
char[] 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", foo);
module_init("testdll");
}
And in Python:
>>> import testdll
>>> print testdll.foo(20)
It's greater than 10!
- PyObject *
module_init
(char[] name);
- Module initialization function. Should be called after the last call to def.
|