2015-06-25 21:58:57 +00:00
|
|
|
#![crate_type = "dylib"]
|
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(interpolate_idents)]
|
|
|
|
|
|
|
|
#[macro_use] extern crate cpython;
|
|
|
|
|
2015-10-25 16:55:29 +00:00
|
|
|
use cpython::{Python, PyObject, PyRustObject, PyResult};
|
2015-06-25 21:58:57 +00:00
|
|
|
|
2015-10-25 16:55:29 +00:00
|
|
|
py_module_initializer!(custom_type, |py, m| {
|
2015-10-26 22:52:18 +00:00
|
|
|
try!(m.add(py, "__doc__", "Module documentation string"));
|
|
|
|
try!(m.add_type::<i32>(py, "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-10-25 16:55:29 +00:00
|
|
|
fn a(py: Python, slf: &PyRustObject<i32>) -> PyResult<PyObject> {
|
|
|
|
println!("a() was called with self={:?}", slf.get(py));
|
|
|
|
Ok(py.None())
|
2015-06-25 21:58:57 +00:00
|
|
|
}
|
|
|
|
|