Skip to content

chrispaig3/lp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LibPlugin

Image

An embeddable plugin system for Rust applications.

  • LibPlugin handles the majority of boilerplate required for implementing a functional plugin system; offering some flexibility in design & configuration.

Still under early development; I would recommend against using it for anything serious at the moment.

  • Supported Formats:
    • Toml
    • Ron
    • Json

Basic Usage

use lp::{PluginManager, Toml};

fn main() {
    let toml = Toml::parse("plugin_manifest.toml")
        .expect("Failed to parse plugin manifest");

    toml.plugin.register(|plugin| {
        // custom logic to handle registering the plugin
    });

    toml.plugin.run(|plugin| {
        // custom logic to handle executing the plugin
    });

    toml.plugin.unregister(|plugin| {
        // custom logic to handle unregistering the plugin
    });
}

Advanced Usage

// add to your project: cargo add lp -F dynamic-loading
use lp::{
    PluginManager, Toml,
    load::{Lib, Loadable, Symbol},
};

fn main() {
    let hello_symbol = "hello_fn";
    let toml = Toml::parse("plugin.toml").expect("File not found");
    toml.plugin.register(|plugin| {
        type UnsafeFn = unsafe extern "C" fn() -> *const std::ffi::c_char;

        if let Some(path) = &plugin.path {
            let hello_lib = unsafe {
                Lib::<Symbol<'static, UnsafeFn>>::load(path, hello_symbol)
                    .expect("Failed to load hello function")
            };

            if let Some(hello_fn) = &hello_lib.f {
                let result = unsafe { hello_fn() };
                println!("hello function loaded!");

                println!("{}", unsafe {
                    std::ffi::CStr::from_ptr(result).to_string_lossy()
                });
            }
        }
    });
}

Example: Plugin Manifest

  • TOML
[plugin]
name = "example"
version = "0.1.0"
authors = ["Author Name"]
description = "An example plugin"
license = "MIT"
path = "/path/to/plugin"
  • RON
Ron(
    plugin: Plugin(
        name: "example",
        version: "0.1.0",
        authors: Some(["Author Name"]),
        description: Some("An example plugin"),
        license: Some("MIT"),
        path: Some("/path/to/plugin"),
    ),
)
  • JSON
{
    "plugin": {
        "name": "example",
        "version": "0.1.0",
        "authors": ["Author Name"],
        "description": "An example plugin",
        "license": "MIT",
        "path": "/path/to/plugin"
    }
}

Roadmap

  • v1.0.0 API refactor
  • v1.1.0 Add opt-in support for MCP via rmcp
  • Enhance Docs

About

LibPlugin is an embeddable plugin system for Rust applications

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published