Skip to content
Laeeth Isharc edited this page Mar 19, 2015 · 1 revision

Table of Contents

Function wrapping

Exposing D functions to Python is easy!

See also

pyd.def

The heart of Pyd's function wrapping features is the def template function.

Notes on def

  • All calls to def must occur before calling module_init.
  • Any function whose return type and arguments are convertible can be wrapped by def.
  • def can only wrap functions with in arguments (not out or ref or lazy).
  • def can handle functions with default and typesafe variadic (e.g. ) 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 python in the following ways: |**D function** | **Python call** | void foo(int i); | foo(1), foo(i=1) | void foo(int i, double d = 3.14); | foo(1,2.0), foo(1), foo(i=1), etc | void foo(int i = 2, double d = 3.14 | foo(d=3.0) | void foo(int[] i...); | foo(1), foo(1,2,3), foo([1,2,3]), foo(i=1), foo(i=[1,2,3])

Examples

And when used in Python:

Clone this wiki locally