Skip to content

Instantly share code, notes, and snippets.

@mcpherrinm
Created June 13, 2014 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mcpherrinm/0116cef42d27583bdcde to your computer and use it in GitHub Desktop.
Save mcpherrinm/0116cef42d27583bdcde to your computer and use it in GitHub Desktop.
calling rust from python
mm@cereal:~/dytest$ rustc -C prefer-dynamic --crate-type=dylib fooz.rs
mm@cereal:~/dytest$ cat fooz.rs
#[no_mangle]
pub extern "C" fn foo(x: int) {
println!("Cowabunga, {}", x);
}
mm@cereal:~/dytest$ cat test.py
import ctypes
fooz = ctypes.CDLL("/home/mm/dytest/libfooz-afaf02c9-0.0.so")
fooz.foo(3)
mm@cereal:~/dytest$ python test.py
Cowabunga, 3
mm@cereal:~/dytest$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment