feat: dotalib

This commit is contained in:
2021-01-10 18:21:01 +08:00
parent 9dc7182b86
commit 58ea520a63
4 changed files with 39 additions and 4 deletions

View File

@@ -1,4 +1,21 @@
use std::{ffi::{CStr, CString}, os::raw::c_char};
#[no_mangle]
pub unsafe extern "C" fn print_hello_world() {
println!("Hello World!");
pub unsafe extern "C" fn println(str: *const c_char) {
let c_str = CStr::from_ptr(str).to_str().unwrap();
println!("{}", c_str);
}
#[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()
}
#[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()
}