Optimised thingy

This commit is contained in:
2025-08-29 01:15:40 +02:00
parent 8cffa11669
commit 68bf864a52
6 changed files with 57 additions and 43 deletions
+27
View File
@@ -1,9 +1,36 @@
#[cfg(feature = "loader")]
use wasmtime::{Instance, Store};
#[cfg(feature = "loader")]
use wasmtime_wasi::preview1::WasiP1Ctx;
#[cfg(feature = "loader")]
pub mod loader;
pub trait PluginApi {
fn init(&mut self);
}
pub enum PluginInstance {
#[cfg(feature = "loader")]
Wasm(Instance, Store<WasiP1Ctx>),
StatiC(Box<dyn PluginApi>),
}
impl PluginApi for PluginInstance {
fn init(&mut self) {
match self {
#[cfg(feature = "loader")]
PluginInstance::Wasm(instance, store) => {
let init = instance
.get_typed_func::<(), ()>(&mut *store, "init")
.unwrap();
init.call(store, ()).unwrap();
}
PluginInstance::StatiC(plugin) => plugin.init(),
}
}
}
#[macro_export]
macro_rules! export_plugin {
($plugin_type:ty) => {