Version 0.1.0
This commit is contained in:
parent
b83a5d9bad
commit
b7090799b6
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
|
||||
name = "cpython"
|
||||
version = "0.0.6"
|
||||
version = "0.1.0"
|
||||
description = "Bindings to Python"
|
||||
authors = ["Daniel Grunwald <daniel@danielgrunwald.de>"]
|
||||
readme = "README.md"
|
||||
|
@ -21,6 +21,7 @@ exclude = [
|
|||
".cargo/config",
|
||||
"python27-sys",
|
||||
"python3-sys",
|
||||
"extensions"
|
||||
]
|
||||
build = "build.rs"
|
||||
|
||||
|
|
19
README.md
19
README.md
|
@ -28,7 +28,7 @@ To use `cpython`, add this to your `Cargo.toml`:
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
cpython = { git = "https://github.com/dgrunwald/rust-cpython.git" }
|
||||
cpython = "0.1"
|
||||
```
|
||||
|
||||
Example program displaying the value of `sys.version`:
|
||||
|
@ -58,16 +58,19 @@ fn hello(py: Python) -> PyResult<()> {
|
|||
|
||||
Example library with python bindings:
|
||||
|
||||
The following two files will build with `cargo build`, and will generate a python-compatible library. (On macOS, you will need to rename the output from \*.dynlib to \*.so)
|
||||
The following two files will build with `cargo build`, and will generate a python-compatible library.
|
||||
On Mac OS, you will need to rename the output from \*.dynlib to \*.so.
|
||||
On Windows, you will need to rename the output from \*.dll to \*.pyd.
|
||||
|
||||
**`Cargo.toml`:**
|
||||
```toml
|
||||
[lib]
|
||||
name = "rust2py"
|
||||
crate-type = ["dylib"]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
cpython = { git = "https://github.com/dgrunwald/rust-cpython.git" }
|
||||
[dependencies.cpython]
|
||||
path = "../.."
|
||||
features = ["extension-module"]
|
||||
```
|
||||
|
||||
**`src/lib.rs`**
|
||||
|
@ -77,7 +80,7 @@ cpython = { git = "https://github.com/dgrunwald/rust-cpython.git" }
|
|||
use cpython::{PyResult, Python};
|
||||
|
||||
// add bindings to the generated python module
|
||||
// N.B: names: "rust2py" must be the lib name in Cargo.toml
|
||||
// N.B: names: "librust2py" must be the name of the `.so` or `.pyd` file
|
||||
py_module_initializer!(librust2py, initlibrust2py, PyInit_librust2py, |py, m| {
|
||||
try!(m.add(py, "__doc__", "This module is implemented in Rust."));
|
||||
try!(m.add(py, "sum_as_string", py_fn!(py, sum_as_string_py(a: i64, b:i64))));
|
||||
|
@ -90,7 +93,9 @@ fn sum_as_string(a:i64, b:i64) -> String {
|
|||
}
|
||||
|
||||
// rust-cpython aware function. All of our python interface could be
|
||||
// declared in a separate module.
|
||||
// declared in a separate module.
|
||||
// Note that the py_fn!() macro automatically converts the arguments from
|
||||
// Python objects to Rust values; and the Rust return value back into a Python object.
|
||||
fn sum_as_string_py(_: Python, a:i64, b:i64) -> PyResult<String> {
|
||||
let out = sum_as_string(a, b);
|
||||
Ok(out)
|
||||
|
|
Loading…
Reference in New Issue