On Thu, Nov 4, 2010 at 10:05 PM, Brett Calcott <[email protected]> wrote: > What am I doing wrong here. The same code compiles as "def add", but > not as "def __add__"? > > cdef extern from "box2d/Common/b2Math.h": > cdef cppclass b2Vec2: > float x, y > b2Vec2() > b2Vec2(float x, float y) > b2Vec2 operator+(b2Vec2 v) > > cdef class Vec2: > cdef b2Vec2 *obj > def __cinit__(self, float x=0.0, float y=0.0): > self.obj = new b2Vec2(x, y) > > def __dealloc__(self): > del self.obj > > # This compiles > def add(self, Vec2 other): > ret = Vec2() > ret.obj[0] = self.obj[0] + other.obj[0] > return ret > > # This does not > def __add__(self, Vec2 other): > ret = Vec2() > ret.obj[0] = self.obj[0] + other.obj[0] # error here > return ret > > error is "test.pyx:25:33: Cannot convert Python object to 'b2Vec2' "
See http://docs.cython.org/src/userguide/special_methods.html#special-methods _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
