Rust rewrite

This commit is contained in:
2024-06-14 18:22:20 +03:00
parent dc7f72f6ef
commit 35cb20545c
30 changed files with 1117 additions and 766 deletions

View File

@@ -0,0 +1,67 @@
use std::ffi::c_void;
use std::ffi::CStr;
use std::ffi::CString;
use std::io::BufWriter;
use std::io::Write;
use dim_plugin_helper::{plugin_info, PluginInfo};
plugin_info!("Example rust project", "owo", "nyaaa");
struct Plug {
pub some_data: String,
}
impl Plug {
pub fn new() -> Self {
Self {
some_data: String::from("OwO")
}
}
}
static mut PLUG: *mut Plug = std::ptr::null_mut();
#[no_mangle]
extern "C" fn plug_get_info() -> *const c_void {
PLUGIN_INFO.get()
}
#[no_mangle]
extern "C" fn plug_init() {
unsafe {
PLUG = (&mut Plug::new()) as *mut Plug;
}
}
#[no_mangle]
extern "C" fn plug_pre_reload() -> *const () {
unsafe {
return PLUG as *const ();
}
}
#[no_mangle]
extern "C" fn plug_post_reload(state: *mut ()) {
unsafe {
PLUG = state as *mut Plug;
}
}
#[no_mangle]
extern "C" fn plug_poll(buf: *mut i8, len: usize) {
let mut buf = dim_plugin_helper::CBuffer::from_raw_parts_mut(buf, len);
// let mut buf = StringBuffer::from_raw_parts_mut(buf, len);
let data = unsafe {(*PLUG).some_data.clone()};
let _ = write!(buf, "{}", data);
}
#[no_mangle]
extern "C" fn plug_free() {
}