Last active
August 29, 2015 14:18
-
-
Save Squab/e6fd039f4e94e567a998 to your computer and use it in GitHub Desktop.
ctypes Arrays with Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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