use plux_mock::MockManager;
use plux_rs::prelude::*;
use std::collections::HashMap;
use crate::plugins::{hello_v1, utils::get_plugin_path};
mod plugins;
#[plux_rs::function]
fn greet(name: &String, age: &i32) {
println!("Hello, {}! You are {} years old.", name, age);
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut plugins = HashMap::new();
hello_v1::insert_plugin(&mut plugins);
let mut loader = SimpleLoader::new();
loader.context(move |mut ctx| {
ctx.register_manager(MockManager::from_plugins(plugins))?;
ctx.register_function(greet("world".to_string()));
ctx.register_request(Request::new("main".to_string(), vec![], None));
Ok::<(), Box<dyn std::error::Error>>(())
})?;
let plugin = loader
.load_plugin_now(
get_plugin_path(hello_v1::FILENAME)
.to_str()
.unwrap(),
)
.map(|bundle| loader.get_plugin_by_bundle(&bundle).unwrap())
.unwrap();
println!("Plugin loaded - Path: {:?}, Bundle: {}",
plugin.info().path,
plugin.info().bundle);
if let Err(e) = plugin.call_request("main", &[])? {
eprintln!("Plugin error: {}", e.to_string());
}
loader.unload_plugin_by_bundle(&hello_v1::BUNDLE)?;
loader.stop()?;
Ok(())
}