1
0
Fork 0

Add plugin name

This commit is contained in:
Florian RICHER 2022-01-28 21:34:13 +01:00
parent 39248b2ca3
commit cdb82d6ccc
3 changed files with 20 additions and 6 deletions

View file

@ -2,3 +2,8 @@
pub extern fn version() -> String {
"0.2.0".to_string()
}
#[no_mangle]
pub extern fn name() -> String {
"test name".to_string()
}

View file

@ -1,5 +1,7 @@
mod plugin_manager;
fn main() {
plugin_manager::PluginManager::new();
let plugin_manager = plugin_manager::PluginManager::new();
println!("Plugins number : {}", plugin_manager.plugins.len());
}

View file

@ -1,10 +1,11 @@
use glob::glob;
use std::env::current_exe;
use std::path::PathBuf;
use glob::glob;
#[derive(Debug, Clone)]
pub struct Plugin {
pub version: String
pub version: String,
pub name: String,
}
pub struct PluginManager {
@ -12,7 +13,7 @@ pub struct PluginManager {
}
impl PluginManager {
pub fn new() {
pub fn new() -> PluginManager {
println!("Loading librairies...");
let mut plugins = Vec::new();
let current_path = current_exe().unwrap();
@ -23,15 +24,21 @@ impl PluginManager {
println!("Loaded plugin {:?}", plugin);
plugins.push(plugin);
}
PluginManager { plugins }
}
fn load_library(lib_file: PathBuf) -> Plugin {
println!("Loading library {:?}", lib_file);
unsafe {
let lib = libloading::Library::new(lib_file).unwrap();
let version_func : libloading::Symbol<extern fn() -> String> = lib.get(b"version").unwrap();
let version_func: libloading::Symbol<extern "C" fn() -> String> =
lib.get(b"version").unwrap();
let name_func: libloading::Symbol<extern "C" fn() -> String> =
lib.get(b"name").unwrap();
Plugin {
version: version_func()
version: version_func(),
name: name_func(),
}
}
}