Pyd provides a series of template functions for converting types to and from Python. Template arguments are in boldface, function arguments are in italics.
PyObject* _py(T) (T t);
- Converts D item t of type T to a PyObject. The returned pointer is a new, owned reference. The following conversions are possible:
D type Python type bool bool C_long (usually int) int C_longlong (usually long) long double float idouble, cdouble complex char (as ASCII string) str dynamic array list associative array dict delegate or function pointer A callable object A wrapped class The wrapped type A wrapped struct The wrapped type Pointer-to-wrapped-struct The wrapped type PydObject The wrapped object's type PyObject* The object's type
nullif the conversion is not possible.
PydObject py(T) (T t);
- Converts D item t of type T to a PyObject with the
_pyfunction (above), and returns a PydObject wrapping that PyObject. This will throw a wrapped Python
RuntimeErrorif the conversion is not possible.
T d_type(T) (PyObject* o);
- Attempts to convert Python object o to the D type T. Note that this means you must call this function with both the template and function arguments. The following conversions are possible:
Python type D type Any type PyObject* Any type PydObject Wrapped struct Wrapped struct Wrapped struct Pointer to wrapped struct Wrapped class Wrapped class Any callable delegate Any iterable dynamic array str char complex cdouble float double long C_longlong (usually long) int C_long (usually int) bool bool
PydConversionExceptionif the conversion is not possible.