mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
store the path to the library in dynamic plugins
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
//! Dynamic plugins with hot-reloading ability.
|
||||
|
||||
use crate::plugin::Plugin;
|
||||
use std::ffi::OsStr;
|
||||
use std::{
|
||||
ffi::OsStr,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
/// Dynamic plugin, that is loaded from a dynamic library. Usually it is used for hot reloading,
|
||||
/// it is strongly advised not to use it in production builds, because it is slower than statically
|
||||
/// linked plugins and it could be unsafe if different compiler versions are used.
|
||||
pub struct DynamicPlugin {
|
||||
pub(super) plugin: Box<dyn Plugin>,
|
||||
path: PathBuf,
|
||||
// Keep the library loaded.
|
||||
// Must be last!
|
||||
#[allow(dead_code)]
|
||||
@@ -23,7 +27,7 @@ impl DynamicPlugin {
|
||||
P: AsRef<OsStr>,
|
||||
{
|
||||
unsafe {
|
||||
let lib = libloading::Library::new(path).map_err(|e| e.to_string())?;
|
||||
let lib = libloading::Library::new(path.as_ref()).map_err(|e| e.to_string())?;
|
||||
|
||||
let entry = lib
|
||||
.get::<PluginEntryPoint>("fyrox_plugin".as_bytes())
|
||||
@@ -31,8 +35,14 @@ impl DynamicPlugin {
|
||||
|
||||
Ok(Self {
|
||||
plugin: entry(),
|
||||
path: PathBuf::from(path.as_ref()),
|
||||
lib,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the path from which the plugin was loaded from.
|
||||
pub fn path(&self) -> &Path {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user