pub struct PluginManager { /* private fields */ }
Expand description
Manages loading, unloading, and interacting with Lua plugins.
This structure is responsible for:
- Loading dynamic libraries that contain Lua plugins.
- Managing plugin instances and ensuring they are correctly initialized and cleaned up.
- Automatically registering Lua functions provided by plugins.
Implementations§
Source§impl PluginManager
impl PluginManager
Sourcepub fn load_plugin(&mut self, path: &str) -> Result<(), Box<dyn Error>>
pub fn load_plugin(&mut self, path: &str) -> Result<(), Box<dyn Error>>
Loads a plugin from a dynamic library.
§Parameters
path
: Path to the dynamic library containing the plugin.
§Returns
Ok(())
if the plugin is successfully loaded.Err
if there is an error during loading or initialization.
§Safety
This method uses unsafe code to interact with the dynamic library and call the plugin’s
exported create_plugin
function.
Sourcepub fn get_plugin(&self, name: &str) -> Option<&dyn PluginLua>
pub fn get_plugin(&self, name: &str) -> Option<&dyn PluginLua>
Sourcepub fn register_plugin_instance(
&mut self,
plugin: Box<dyn PluginLua>,
) -> Result<(), Box<dyn Error>>
pub fn register_plugin_instance( &mut self, plugin: Box<dyn PluginLua>, ) -> Result<(), Box<dyn Error>>
Registers a plugin instance directly, bypassing file loading.
§Parameters
plugin
: A boxed instance of a plugin implementing thePluginLua
trait.
§Returns
Ok(())
if the plugin was successfully registered.Err(Box<dyn Error>)
if an error occurs during plugin initialization.
§Example
let plugin: Box<dyn PluginLua> = Box::new(MyPlugin::new());
plugin_manager.register_plugin_instance(plugin)?;
§Notes
- The plugin’s
on_load
method is called during this process to initialize the plugin. - The plugin is stored in the internal plugin map for future reference.
Trait Implementations§
Source§impl Default for PluginManager
impl Default for PluginManager
Auto Trait Implementations§
impl Freeze for PluginManager
impl !RefUnwindSafe for PluginManager
impl Send for PluginManager
impl Sync for PluginManager
impl Unpin for PluginManager
impl !UnwindSafe for PluginManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more