Created
December 27, 2013 07:27
-
-
Save jc00ke/8143706 to your computer and use it in GitHub Desktop.
Rust/Ruby FFI
This file contains hidden or 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
require 'ffi' | |
module Rust | |
module Uuid | |
extend FFI::Library | |
ffi_lib './librust_uuid-2b1863329f7b31d9-0.1.so' | |
attach_function :asdf, [], :string | |
attach_function :uuid_str, [], :void | |
end | |
end | |
puts Rust::Uuid.asdf | |
puts Rust::Uuid.uuid_str |
This file contains hidden or 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
#[link(name="rust_uuid", vers="0.1")]; | |
extern mod extra; | |
use extra::uuid::Uuid; | |
#[no_mangle] | |
fn uuid_rust() -> ~str { | |
let uuid1 = Uuid::new_v4(); | |
uuid1.to_str() | |
} | |
#[no_mangle] | |
pub extern fn asdf() -> &'static str { | |
return "asdf" | |
} | |
#[no_mangle] | |
pub extern fn uuid_str() { | |
uuid_rust(); | |
} | |
#[fixed_stack_segment] | |
fn main() { | |
println(uuid_rust()); | |
println(asdf()); | |
} |
$> ruby uuid.rb
asdf
You've met with a terrible fate, haven't you?
fatal runtime error: runtime tls key not initialized
[1] 26242 abort (core dumped) ruby uuid.rb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
uuid.rs
compiled as a library with$> rustc --lib uuid.rs