Struct PluginManager

Source
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

Source

pub fn new() -> Self

Creates a new PluginManager.

Source

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.

Source

pub fn unload_plugin(&mut self, name: &str) -> Result<(), Box<dyn Error>>

Unloads a plugin by its name.

§Parameters
  • name: Name of the plugin to be unloaded.
§Returns
  • Ok(()) if the plugin is successfully unloaded.
  • Err if the plugin fails to clean up resources or is not found.
Source

pub fn get_plugin(&self, name: &str) -> Option<&dyn PluginLua>

Retrieves a reference to a loaded plugin by its name.

§Parameters
  • name: Name of the plugin.
§Returns
  • Some(&dyn PluginLua) if the plugin is found.
  • None if the plugin is not loaded.
Source

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 the PluginLua 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.
Source

pub fn register_all_plugins( &self, lua: &Lua, name: &str, ) -> Result<(), Box<dyn Error>>

Registers all Lua functions from all loaded plugins with the given Lua state.

§Parameters
  • lua: The Lua state where the functions should be registered.
§Returns
  • Ok(()) if all functions are registered successfully.
  • Err if there is an error during registration.

Trait Implementations§

Source§

impl Default for PluginManager

Source§

fn default() -> Self

Creates a default instance of PluginManager.

Source§

impl Drop for PluginManager

Source§

fn drop(&mut self)

Ensures that all plugins are unloaded and cleaned up when the PluginManager is dropped.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T