From e73575f62ecbfa813e43e904561e5b05b10b760e Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 10 Jan 2021 19:06:06 +0800 Subject: [PATCH] chore: comments --- __ffi/dotalib/dotalib.h | 9 +++++++++ __ffi/dotalib/src/lib.rs | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/__ffi/dotalib/dotalib.h b/__ffi/dotalib/dotalib.h index e0dd3f8..f8b3dea 100644 --- a/__ffi/dotalib/dotalib.h +++ b/__ffi/dotalib/dotalib.h @@ -5,8 +5,17 @@ #include +/** + * Get const string from rust + */ const char *get_str(void); +/** + * Get mut-able string from rust + */ char *get_str_mut(void); +/** + * Print line + */ void println(const char *str); diff --git a/__ffi/dotalib/src/lib.rs b/__ffi/dotalib/src/lib.rs index 3650fb2..0b4883e 100644 --- a/__ffi/dotalib/src/lib.rs +++ b/__ffi/dotalib/src/lib.rs @@ -1,18 +1,20 @@ 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!");