Add common struct
This commit is contained in:
parent
cdb82d6ccc
commit
4b94fa645c
10 changed files with 65 additions and 25 deletions
|
@ -1,15 +1,10 @@
|
|||
use glob::glob;
|
||||
use hotload_plugin::HotloadPlugin;
|
||||
use std::env::current_exe;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Plugin {
|
||||
pub version: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
pub struct PluginManager {
|
||||
pub plugins: Vec<Plugin>,
|
||||
pub plugins: Vec<*const HotloadPlugin>,
|
||||
}
|
||||
|
||||
impl PluginManager {
|
||||
|
@ -21,25 +16,19 @@ impl PluginManager {
|
|||
let lib_folder = parent_path.join("*.so");
|
||||
for lib_file in glob(lib_folder.to_str().unwrap()).unwrap() {
|
||||
let plugin = Self::load_library(lib_file.unwrap());
|
||||
println!("Loaded plugin {:?}", plugin);
|
||||
plugins.push(plugin);
|
||||
}
|
||||
|
||||
PluginManager { plugins }
|
||||
}
|
||||
|
||||
fn load_library(lib_file: PathBuf) -> Plugin {
|
||||
fn load_library(lib_file: PathBuf) -> *const HotloadPlugin {
|
||||
println!("Loading library {:?}", lib_file);
|
||||
unsafe {
|
||||
let lib = libloading::Library::new(lib_file).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(),
|
||||
name: name_func(),
|
||||
}
|
||||
let register_func: libloading::Symbol<extern "C" fn() -> *const HotloadPlugin> =
|
||||
lib.get(b"register").unwrap();
|
||||
register_func()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue