-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCythonExample.pyx
More file actions
33 lines (28 loc) · 929 Bytes
/
CythonExample.pyx
File metadata and controls
33 lines (28 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
cdef extern from "cpp_test.h":
cdef cppclass Test:
Test()
Test(int test1)
int test1
int returnFive()
Test add "operator+"(Test other)
Test sub "operator-"(Test other)
cdef class pyTest:
cdef Test* thisptr # hold a C++ instance
def __cinit__(self, int test1):
self.thisptr = new Test(test1)
def __dealloc__(self):
del self.thisptr
def __add__(pyTest left, pyTest other):
cdef Test t = left.thisptr.add(other.thisptr[0])
cdef pyTest tt = pyTest(t.test1)
return tt
def __sub__(pyTest left, pyTest other):
cdef Test t = left.thisptr.sub(other.thisptr[0])
cdef pyTest tt = pyTest(t.test1)
return tt
def __repr__(self):
return "pyTest[%s]" % (self.thisptr.test1)
def returnFive(self):
return self.thisptr.returnFive()
def printMe(self):
return "hello world"