Wiki

Clone wiki

pyd / PydObject

PydObject

The PydObject class wraps a PyObject*, using the D garbage collector to handle the reference count so that you don't have to. It also overloads quite a lot of operators, and tries to make using Python objects in D code as much like using them in Python as possible. However, it is incomplete (the function and method call methods in particular need work, and there are a number of helper functions that need to be written), and remains a work in progress.

Authors

Kirk McDonald

See also

The Python/C API
pyd.pydobject

Table of Contents

PydObject

Arithmetic

The following operators are supported for T a convertible D type and me a python object that supports the corresponding operator overload.

PydObject me, p;
T t;
p = me + t;
p = me - t;
p = me * t;
p = me / t;
p = me % t;
p = me ^^ t; // same as me ** t in python
p = me << t;
p = me >> t;
p = me & t;
p = me ^ t;
p = me | t;
p = me ~ t; // same as me + t in python
p = +me;
p = -me;
p = ~me;

In-place Arithmetic

The following in-place operators supported for T a convertible D type and me a python object that supports the corresponding operator overload.

PydObject me, p;
T t;
p = me += t;
p = me -= t;
p = me *= t;
p = me /= t;
p = me %= t;
p = me ^^= t; // same as me **= t in python
p = me <<= t;
p = me >>= t;
p = me & =t;
p = me ^= t;
p = me |= t;
p = me ~= t; // same as me += t in python 

Type Conversion

PydObject as_int();
PydObject as_long();
PydObject as_float(); 
T to_d!(T)(T t);

Updated