From bdf876bcc5fca82ffb354ee4cf3844c8e6ef0d59 Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Mon, 18 Mar 2024 16:05:11 +0300 Subject: [PATCH] store the path to the library in dynamic plugins --- fyrox-impl/src/plugin/dynamic.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fyrox-impl/src/plugin/dynamic.rs b/fyrox-impl/src/plugin/dynamic.rs index d226a2efa..7a836c535 100644 --- a/fyrox-impl/src/plugin/dynamic.rs +++ b/fyrox-impl/src/plugin/dynamic.rs @@ -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, + path: PathBuf, // Keep the library loaded. // Must be last! #[allow(dead_code)] @@ -23,7 +27,7 @@ impl DynamicPlugin { P: AsRef, { 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::("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 + } }