Skip to content

Instantly share code, notes, and snippets.

@Squab
Last active August 29, 2015 14:18
Show Gist options
  • Save Squab/e6fd039f4e94e567a998 to your computer and use it in GitHub Desktop.
Save Squab/e6fd039f4e94e567a998 to your computer and use it in GitHub Desktop.
ctypes Arrays with Rust
from ctypes import *
thelib = CDLL("liblib.dylib")
floatstruct = c_float * 3
f = floatstruct(0.32, 0.44, 0.55)
thelib.arr.restype = c_float
p = pointer(f)
print thelib.arr(p)
# 0.550000011921
#![crate_type = "dylib"]
#[no_mangle]
pub extern fn arr(x: &[f32; 3]) -> f32 {
let a = *x;
a[2]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment