Add Ruby to Rust example

This commit is contained in:
Alex Crichton
2015-04-19 10:38:48 -07:00
parent 930924cdf5
commit 515ebb2db1
4 changed files with 32 additions and 0 deletions

4
ruby-to-rust/src/lib.rs Normal file
View File

@@ -0,0 +1,4 @@
#[no_mangle]
pub extern fn double_input(input: i32) -> i32 {
input * 2
}

11
ruby-to-rust/src/main.rb Normal file
View File

@@ -0,0 +1,11 @@
require 'ffi'
module Hello
extend FFI::Library
ffi_lib 'target/libdouble_input.so'
attach_function :double_input, [ :int ], :int
end
input = 4
output = Hello.double_input(input)
puts "#{input} * 2 = #{output}"