Working-ish plugin thingy

This commit is contained in:
2025-08-28 22:13:45 +02:00
commit 5aaa933596
9 changed files with 1813 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "test-plugin"
version = "0.1.0"
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "test-plugin"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib"]
+29
View File
@@ -0,0 +1,29 @@
pub trait Plugin {
fn init(&mut self);
}
macro_rules! export_plugin {
($plugin_type:ty) => {
static PLUGIN: std::sync::Mutex<Option<$plugin_type>> = std::sync::Mutex::new(None);
#[unsafe(no_mangle)]
pub extern "C" fn init() {
let mut plugin = PLUGIN.lock().unwrap();
*plugin = Some(<$plugin_type>::default());
if let Some(plugin) = plugin.as_mut() {
plugin.init();
}
}
};
}
#[derive(Default)]
pub struct MyPlugin;
impl Plugin for MyPlugin {
fn init(&mut self) {
println!("MyPlugin initialized!");
}
}
export_plugin!(MyPlugin);