pyd.class_wrap

Contains utilities for wrapping D classes.

template is_wrapped (T)
A useful check for whether a given class has been wrapped. Mainly used by the conversion functions (see make_object.d), but possibly useful elsewhere.

struct Def (alias fn,Options...);
Wraps a member function of the class.

Supports default arguments, typesafe variadic arguments, and python's keyword arguments.

Params:
fn The member function to wrap.
Options Optional parameters. Takes Docstring!(docstring), PyName!(pyname), and fn_t.
fn_t The type of the function. It is only useful to specify this if more than one function has the same name as this one.
pyname The name of the function as it will appear in Python. Defaults to fn's name in D
docstring The function's docstring. Defaults to "".

struct StaticDef (alias fn,Options...);
Wraps a static member function of the class. Similar to pyd.def.def

Supports default arguments, typesafe variadic arguments, and python's keyword arguments.

Params:
fn The member function to wrap.
Options Optional parameters. Takes Docstring!(docstring), PyName!(pyname), and fn_t
fn_t The type of the function. It is only useful to specify this if more than one function has the same name as this one.
pyname The name of the function as it will appear in Python. Defaults to fn's name in D.
docstring The function's docstring. Defaults to "".

struct Property (alias fn,Options...);
Wraps a property of the class.

Params:
fn The property to wrap.
Options Optional parameters. Takes Docstring!(docstring), PyName!(pyname), and Mode!(mode)
pyname The name of the property as it will appear in Python. Defaults to fn's name in D.
mode specifies whether this property is readable, writable. possible values are "r", "w", "rw", and "" (in the latter case, automatically determine which mode to use based on availability of getter and setter forms of fn). Defaults to "".
docstring The function's docstring. Defaults to "".

struct Repr (alias _fn);
Wraps a method as the class's __repr__ in Python.

Params:
fn The property to wrap. Must have the signature string function().

struct Init (cps...);
Wraps the constructors of the class.

This template takes a single specialization of the ctor template (see ctor_wrap.d), which describes a constructor that the class supports. The default constructor need not be specified, and will always be available if the class supports it.

Supports default arguments, typesafe variadic arguments, and python's keyword arguments.

Params:
cps Parameter list of the constructor to be wrapped.

BUGS:
This currently does not support having multiple constructors with the same number of arguments.

template OpBinary (string op,rhs_t = Guess) if (IsPyBinary(op) && op != "in")
template OpBinaryRight (string op,lhs_t = Guess) if (IsPyBinary(op))
Wrap a binary operator overload.

Example:
class Foo{
    int _j;
    int opBinary(string op)(int i) if(op == "+"){
        return i+_j;
    }
    int opBinaryRight(string op)(int i) if(op == "+"){
        return i+_j;
    }
}

class_wrap!(Foo,
    OpBinary!("+"),
    OpBinaryRight!("+"));


Params:
op Operator to wrap
rhs_t (optional) Type of opBinary's parameter for disambiguation if there are multiple overloads.

BUGS:
Issue 8602 prevents disambiguation for case X opBinary(string op, T)(T t);

struct OpUnary (string _op) if (IsPyUnary(_op));
Wrap a unary operator overload.

struct OpAssign (string _op,rhs_t = Guess) if (IsPyAsg(_op));
Wrap an operator assignment overload.

Example:
class Foo{
    int _j;
    void opOpAssign(string op)(int i) if(op == "+"){
        _j = i;
    }
}

class_wrap!(Foo,
    OpAssign!("+"));


Params:
op Base operator to wrap
rhs_t (optional) Type of opOpAssign's parameter for disambiguation if there are multiple overloads.

struct OpCompare (_rhs_t = Guess);
Wrap opCmp.

Params:
rhs_t (optional) Type of opCmp's parameter for disambiguation if there are multiple overloads (for classes it will always be Object).

struct OpIndex (index_t...);
struct OpIndexAssign (index_t...);
Wrap opIndex, opIndexAssign.

Params:
index_t (optional) Types of opIndex's parameters for disambiguation if there are multiple overloads.

struct OpSlice ();
Wrap opSlice.

Requires signature
Foo.opSlice(Py_ssize_t, Py_ssize_t);
This is a limitation of the C/Python API.

struct OpSliceAssign (rhs_t = Guess);
Wrap opSliceAssign.

Requires signature
Foo.opSliceAssign(Value,Py_ssize_t, Py_ssize_t);
This is a limitation of the C/Python API.

struct OpCall (Args_t...);
wrap opCall. The parameter types of opCall must be specified.

template Len ()
template Len (alias fn)
Wraps Foo.length or another function as python's __len__ function.

Requires signature
Py_ssize_t length();
This is a limitation of the C/Python API.

void wrap_class (T, Params...)();
Wrap a class.

Params:
T The class being wrapped.
Params Mixture of definitions of members of T to be wrapped and optional arguments. Concerning optional arguments, accepts PyName!(pyname), ModuleName!(modulename), and Docstring!(docstring).
pyname The name of the class as it will appear in Python. Defaults to T's name in D
modulename The name of the python module in which the wrapped class resides. Defaults to "".
docstring The class's docstring. Defaults to "".

Page was generated with on Sun Nov 11 11:29:00 2012