Skip to content

Instantly share code, notes, and snippets.

@shadowmint
Created April 11, 2014 06:51
Show Gist options
  • Save shadowmint/10445024 to your computer and use it in GitHub Desktop.
Save shadowmint/10445024 to your computer and use it in GitHub Desktop.
doug:rust-libs doug$ cat junk.rs
#![crate_id = "junk#0.1"]
use std::libc::c_int;
#[no_mangle]
pub extern fn dothing(a: c_int, b:c_int) -> c_int {
return a + b;
}
doug:rust-libs doug$ rustc --crate-type=dylib junk.rs
doug:rust-libs doug$ ls
README.md junk.rs libjunk-7ac869a1-0.1.rlib main.rs
doc libjunk-7ac869a1-0.1.dylib main
doug:rust-libs doug$ python
Python 2.7.6 (default, Nov 20 2013, 09:06:02)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> lib = ctypes.CDLL("libjunk-7ac869a1-0.1.dylib")
>>> lib
<CDLL 'libjunk-7ac869a1-0.1.dylib', handle 7ff4c3718fd0 at 101aa1a90>
>>> lib.dothing(1, 2)
3
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment