#[unsafe(no_mangle)]
pub extern "C" fn hostAdd(a: i64, b: i64) -> i64 {
a + b
}
#[unsafe(no_mangle)]
pub extern "C" fn hostMultiply(a: i64, b: i64) -> i64 {
a * b
}
#[repr(C)]
pub struct HostUserInfo {
pub id: i64,
pub name_buf: [u8; 128],
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn hostFetchUser(name_ptr: *const std::os::raw::c_char) -> HostUserInfo {
let c_str = unsafe { std::ffi::CStr::from_ptr(name_ptr) };
let name = c_str.to_str().unwrap_or("unknown");
let greeting = format!("Hello, {}!", name);
let mut buf = [0u8; 128];
let bytes = greeting.as_bytes();
let len = bytes.len().min(127);
buf[..len].copy_from_slice(&bytes[..len]);
HostUserInfo {
id: name.len() as i64,
name_buf: buf,
}
}