Fixed rust, named the libraries sdk's, better examples
This commit is contained in:
@@ -1,67 +1,48 @@
|
||||
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};
|
||||
use std::fmt::Write;
|
||||
use dim_sdk::{plugin_info, DimPlugin};
|
||||
|
||||
plugin_info!("Example rust project", "owo", "nyaaa");
|
||||
plugin_info!(
|
||||
Plug, // Your main global structs name that implements `DimPlugin`
|
||||
"Example rust project", // Plugin name
|
||||
"0.0.0", // Plugin Version (leave empty for none)
|
||||
"GPLv3" // Plugin license (leave empty for none)
|
||||
);
|
||||
|
||||
struct Plug {
|
||||
pub some_data: String,
|
||||
counter: usize,
|
||||
}
|
||||
|
||||
impl Plug {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
some_data: String::from("OwO")
|
||||
counter: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
impl DimPlugin for Plug {
|
||||
fn init(&mut self) {
|
||||
// Initialise data, this will run once, it will not run again after reload
|
||||
}
|
||||
fn poll(&mut self, f: &mut dim_sdk::CBuffer) -> dim_sdk::Result<()> {
|
||||
// Write to buffer the text you want to display, keep this short
|
||||
write!(f, "Hello from rust! ({})", self.counter)?;
|
||||
self.counter += 1;
|
||||
Ok(())
|
||||
}
|
||||
fn pre_reload(&mut self) {
|
||||
// Do stuff before reload, probably save important things because theres a good chance
|
||||
// (especially on rust) that if you change the data layout it will die
|
||||
}
|
||||
fn post_reload(&mut self) {
|
||||
// Do stuff after reloading plugin, state a.k.a this struct has the same data, will crash
|
||||
// if the data layout changed
|
||||
}
|
||||
fn free(&mut self) {
|
||||
// Yout probably dont need this but its for freeing things before the plugin gets unloaded
|
||||
}
|
||||
}
|
||||
|
||||
#[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() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user