Fix buffer protocol inheritance

Fixes #878.
This commit is contained in:
Dean Moldovan
2017-05-28 16:35:02 +02:00
parent 6d2411f1ac
commit 427e4afc69
3 changed files with 28 additions and 2 deletions

View File

@@ -74,6 +74,11 @@ private:
float *m_data;
};
class SquareMatrix : public Matrix {
public:
SquareMatrix(ssize_t n) : Matrix(n, n) { }
};
struct PTMFBuffer {
int32_t value = 0;
@@ -141,6 +146,10 @@ test_initializer buffers([](py::module &m) {
})
;
// Derived classes inherit the buffer protocol and the buffer access function
py::class_<SquareMatrix, Matrix>(m, "SquareMatrix")
.def(py::init<ssize_t>());
py::class_<PTMFBuffer>(m, "PTMFBuffer", py::buffer_protocol())
.def(py::init<>())
.def_readwrite("value", &PTMFBuffer::value)