Last active
December 20, 2015 18:39
-
-
Save cfobel/6177523 to your computer and use it in GitHub Desktop.
Cython stack-allocated struct/class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
Foo() : x(0), y(0) {} | |
Foo(int x, int y) : x(x), y(y) {} | |
int x; | |
int y; | |
}; | |
inline Foo test_return() { | |
Foo f(7, 4); | |
return f; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cdef extern from "Foo.hpp": | |
struct Foo: | |
int x | |
int y | |
Foo test_return() | |
def other(): | |
cdef Foo f | |
cdef Foo bar = test_return() | |
print f.x, f.y | |
print bar.x, bar.y | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NB The struct/class must have a default constructor to allow stack allocation or to return as an lvalue.