The newbie's question about wrapping c++ class with pyrex
Yong Sun <[email protected]>
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
Hi, experts, I am following the tutorial at http://wiki.cython.org/WrappingCPlusPlus, and found a minor issue, cdef class Rectangle: - c_Rectangle *thisptr # hold a C++ instance which we're wrapping + cdef c_Rectangle *thisptr # hold a C++ instance which we're wrapping I need the above change to make it successfully compiled by cython. While, when I tried to compile it with pyrexc, I met following errors, $ pyrexc --cplus rect.pyx rect.pyx:4:21: Non-extern C function declared but not defined rect.pyx:5:21: Non-extern C function declared but not defined rect.pyx:6:19: Non-extern C function declared but not defined rect.pyx:7:17: Non-extern C function declared but not defined rect.pyx:18:27: Object of type 'c_Rectangle' has no attribute 'getLength' rect.pyx:20:27: Object of type 'c_Rectangle' has no attribute 'getHeight' rect.pyx:22:27: Object of type 'c_Rectangle' has no attribute 'getArea' rect.pyx:24:20: Object of type 'c_Rectangle' has no attribute 'move' BTW, I am using the latest stable version, $ pyrexc --version Pyrex version 0.9.6.4 Thank you very much! Regards, _______________________________________________ Pyrex mailing list [email protected] http://lists.copyleft.no/mailman/listinfo/pyrex
rect.pyx
(text/plain, 867 B)
cdef extern from "Rectangle.h":
ctypedef struct c_Rectangle "Rectangle":
int x0, y0, x1, y1
int getLength()
int getHeight()
int getArea()
void move(int dx, int dy)
c_Rectangle *new_Rectangle "new Rectangle" (int x0, int y0, int x1, int y1)
void del_Rectangle "delete" (c_Rectangle *rect)
cdef class Rectangle:
cdef c_Rectangle *thisptr # hold a C++ instance which we're wrapping
def __cinit__(self, int x0, int y0, int x1, int y1):
self.thisptr = new_Rectangle(x0, y0, x1, y1)
def __dealloc__(self):
del_Rectangle(self.thisptr)
def getLength(self):
return self.thisptr.getLength()
def getHeight(self):
return self.thisptr.getHeight()
def getArea(self):
return self.thisptr.getArea()
def move(self, dx, dy):
self.thisptr.move(dx, dy)