Advertisement
vedranvinko

Ruby-Rust-FFI

Mar 3rd, 2016
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. Cargo.toml
  2.  
  3. [dependencies]
  4. libc = "0.2"
  5.  
  6. [lib]
  7. name = ""
  8. crate-type = ["dylib"]
  9.  
  10. ---
  11.  
  12. lib.rs
  13.  
  14. extern crate libc;
  15. use std::ffi::{CStr, CString};
  16.  
  17. #[no_mangle]
  18. pub extern fn lib_fn(name: *const libc::c_char) {
  19. let name = unsafe { CStr::from_ptr(name) };
  20. // implementation
  21. }
  22.  
  23. ---
  24.  
  25. test.rb
  26.  
  27. require 'ffi'
  28.  
  29. module Test
  30. extend FFI::Library
  31. ffi_lib 'path/to/lib'
  32. attach_function :lib_fn, [:string], :void
  33. end
  34.  
  35. Test.lib_fn(str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement