Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
rust-chsarp-interop/rust-interop/src/lib.rs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
23 lines (20 sloc)
606 Bytes
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
| extern crate libc; | |
| // use cstr::cstr; | |
| use std::ffi::CStr; | |
| use std::ffi; | |
| use libc::*; | |
| pub extern fn greeting(){ | |
| println!("Hello Wolrd! rust speaking."); | |
| } | |
| #[no_mangle] | |
| pub extern "C" fn printc(c_buf: *const c_char){ | |
| let c_str: &CStr = unsafe { CStr::from_ptr(c_buf) }; | |
| let str_slice: &str = c_str.to_str().unwrap(); | |
| //let str_buf: String = str_slice.to_owned(); // if necessary | |
| println!("c# string is is {}", str_slice); | |
| } | |
| #[no_mangle] | |
| pub extern "C" fn takeFunctionPointerAndCallIt(function_pointer: extern fn() -> ()) -> extern fn() { | |
| function_pointer(); | |
| return greeting; | |
| } |