24 lines
598 B
Rust
24 lines
598 B
Rust
use std::{ffi::{CStr, CString}, os::raw::c_char};
|
|
|
|
/// Print line
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn println(str: *const c_char) {
|
|
let c_str = CStr::from_ptr(str).to_str().unwrap();
|
|
println!("{}", c_str);
|
|
}
|
|
|
|
/// Get mut-able string from rust
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn get_str_mut() -> *mut c_char {
|
|
let c_string = CString::new("hello world!").expect("Error!");
|
|
c_string.into_raw()
|
|
}
|
|
|
|
/// Get const string from rust
|
|
#[no_mangle]
|
|
pub unsafe extern "C" fn get_str() -> *const c_char {
|
|
let c_string = CString::new("hello world!").expect("Error!");
|
|
c_string.as_ptr()
|
|
}
|
|
|