2015-06-25 21:58:57 +00:00
|
|
|
#![crate_type = "dylib"]
|
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(interpolate_idents)]
|
|
|
|
|
|
|
|
#[macro_use] extern crate cpython;
|
|
|
|
|
2015-08-02 22:06:15 +00:00
|
|
|
use cpython::{PythonObject, PyObject, PyRustObject, PyResult};
|
2015-06-25 21:58:57 +00:00
|
|
|
|
|
|
|
py_module_initializer!(custom_type, |_py, m| {
|
|
|
|
try!(m.add("__doc__", "Module documentation string"));
|
|
|
|
try!(m.add_type::<i32>("MyType")
|
2015-08-02 22:06:15 +00:00
|
|
|
.add("a", py_method!(a()))
|
2015-06-25 21:58:57 +00:00
|
|
|
.finish());
|
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
|
2015-08-02 22:06:15 +00:00
|
|
|
fn a<'p>(slf: &PyRustObject<'p, i32>) -> PyResult<'p, PyObject<'p>> {
|
|
|
|
println!("a() was called with self={:?}", slf.get());
|
2015-06-25 21:58:57 +00:00
|
|
|
Ok(slf.python().None())
|
|
|
|
}
|
|
|
|
|