Add plugin name
This commit is contained in:
parent
39248b2ca3
commit
cdb82d6ccc
3 changed files with 20 additions and 6 deletions
|
@ -2,3 +2,8 @@
|
||||||
pub extern fn version() -> String {
|
pub extern fn version() -> String {
|
||||||
"0.2.0".to_string()
|
"0.2.0".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn name() -> String {
|
||||||
|
"test name".to_string()
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
mod plugin_manager;
|
mod plugin_manager;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
plugin_manager::PluginManager::new();
|
let plugin_manager = plugin_manager::PluginManager::new();
|
||||||
|
|
||||||
|
println!("Plugins number : {}", plugin_manager.plugins.len());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
use glob::glob;
|
||||||
use std::env::current_exe;
|
use std::env::current_exe;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use glob::glob;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Plugin {
|
pub struct Plugin {
|
||||||
pub version: String
|
pub version: String,
|
||||||
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PluginManager {
|
pub struct PluginManager {
|
||||||
|
@ -12,7 +13,7 @@ pub struct PluginManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PluginManager {
|
impl PluginManager {
|
||||||
pub fn new() {
|
pub fn new() -> PluginManager {
|
||||||
println!("Loading librairies...");
|
println!("Loading librairies...");
|
||||||
let mut plugins = Vec::new();
|
let mut plugins = Vec::new();
|
||||||
let current_path = current_exe().unwrap();
|
let current_path = current_exe().unwrap();
|
||||||
|
@ -23,15 +24,21 @@ impl PluginManager {
|
||||||
println!("Loaded plugin {:?}", plugin);
|
println!("Loaded plugin {:?}", plugin);
|
||||||
plugins.push(plugin);
|
plugins.push(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PluginManager { plugins }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_library(lib_file: PathBuf) -> Plugin {
|
fn load_library(lib_file: PathBuf) -> Plugin {
|
||||||
println!("Loading library {:?}", lib_file);
|
println!("Loading library {:?}", lib_file);
|
||||||
unsafe {
|
unsafe {
|
||||||
let lib = libloading::Library::new(lib_file).unwrap();
|
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 {
|
Plugin {
|
||||||
version: version_func()
|
version: version_func(),
|
||||||
|
name: name_func(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue