2016-03-06 05:29:43 +00:00
|
|
|
#![crate_type = "dylib"]
|
|
|
|
|
|
|
|
#[macro_use] extern crate cpython;
|
|
|
|
|
2016-03-12 17:14:21 +00:00
|
|
|
use cpython::{PyObject, PyResult};
|
2016-03-06 05:29:43 +00:00
|
|
|
|
2016-03-06 09:29:28 +00:00
|
|
|
py_module_initializer!(custom_class, initcustom_class, PyInit_custom_class, |py, m| {
|
2016-03-06 05:29:43 +00:00
|
|
|
try!(m.add(py, "__doc__", "Module documentation string"));
|
|
|
|
try!(m.add_class::<MyType>(py));
|
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
|
2016-03-12 17:14:21 +00:00
|
|
|
py_class!(class MyType |py| {
|
|
|
|
data data: i32;
|
|
|
|
def __new__(_cls, arg: i32) -> PyResult<MyType> {
|
|
|
|
MyType::create_instance(py, arg)
|
2016-03-06 09:29:28 +00:00
|
|
|
}
|
2016-03-12 17:14:21 +00:00
|
|
|
def a(&self) -> PyResult<PyObject> {
|
2016-03-06 09:29:28 +00:00
|
|
|
println!("a() was called with self={:?}", self.data(py));
|
|
|
|
Ok(py.None())
|
2016-03-12 17:14:21 +00:00
|
|
|
}
|
2016-03-06 05:29:43 +00:00
|
|
|
});
|
|
|
|
|