chore: comments
This commit is contained in:
@@ -5,8 +5,17 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get const string from rust
|
||||||
|
*/
|
||||||
const char *get_str(void);
|
const char *get_str(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mut-able string from rust
|
||||||
|
*/
|
||||||
char *get_str_mut(void);
|
char *get_str_mut(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print line
|
||||||
|
*/
|
||||||
void println(const char *str);
|
void println(const char *str);
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
use std::{ffi::{CStr, CString}, os::raw::c_char};
|
use std::{ffi::{CStr, CString}, os::raw::c_char};
|
||||||
|
|
||||||
|
/// Print line
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn println(str: *const c_char) {
|
pub unsafe extern "C" fn println(str: *const c_char) {
|
||||||
let c_str = CStr::from_ptr(str).to_str().unwrap();
|
let c_str = CStr::from_ptr(str).to_str().unwrap();
|
||||||
println!("{}", c_str);
|
println!("{}", c_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get mut-able string from rust
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn get_str_mut() -> *mut c_char {
|
pub unsafe extern "C" fn get_str_mut() -> *mut c_char {
|
||||||
let c_string = CString::new("hello world!").expect("Error!");
|
let c_string = CString::new("hello world!").expect("Error!");
|
||||||
c_string.into_raw()
|
c_string.into_raw()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get const string from rust
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn get_str() -> *const c_char {
|
pub unsafe extern "C" fn get_str() -> *const c_char {
|
||||||
let c_string = CString::new("hello world!").expect("Error!");
|
let c_string = CString::new("hello world!").expect("Error!");
|
||||||
|
|||||||
Reference in New Issue
Block a user