vedranvinko icon

Ruby-Rust-FFI

vedranvinko | PRO | 03/03/16 08:06:16 PM UTC | 0 ⭐ | 526 👁️ | Never ⏰ | []
text |

450 B

|

None

|

0 👍

/

0 👎

Cargo.toml
 [dependencies]
libc = "0.2"
 [lib]
name = ""
crate-type = ["dylib"]
 ---
 lib.rs
 extern crate libc;
use std::ffi::{CStr, CString};
 #[no_mangle]
pub extern fn lib_fn(name: *const libc::c_char) {
	let name = unsafe { CStr::from_ptr(name) };
	// implementation
}
 ---
 test.rb
 require 'ffi'
 module Test
	extend FFI::Library
	ffi_lib 'path/to/lib'
	attach_function :lib_fn, [:string], :void
end
 Test.lib_fn(str)

Comments