The heart of PyD's function wrapping is the def template function.
../../examples/def/example.d
- Notes
- Any function whose return type and parameters types are convertible by
- All calls to def must occur before the call to module_init or py_init PyD's type conversion can be wrapped by def.
- def can't handle
out
,ref
, orlazy
parameters. - def can't handle functions with c-style variadic arguments
- def can handle functions with default and typesafe variadic arguments
- def supports skipping default arguments (on the python side) and will automatically fill in any omitted default arguments
- def-wrapped functions can take keyword arguments in python
def-wrapped functions can be called in the following ways:
D function | Python call |
---|---|
void foo(int i); |
foo(1) foo(i=1) |
void foo(int i = 2, double d = 3.14); |
foo(1, 2.0) foo(d=2.0) foo() |
void foo(int[] i...); |
foo(1) foo(1,2,3) foo([1,2,3]) foo(i=[1,2,3]) |
Aside from the required function alias, def recognizes a number of poor-man keyword arguments, as well as a type specifier for the function alias.
def!(func, void function(int), ModuleName!"mymodl")();
Order is not significant for these optional arguments.
specify the module in which to inject the function
Default: ''
Specify the docstring to associate with the function
Default: ''
Specify the name that python will bind the function to
Default: the name of the exposed function