3 releases
Uses new Rust 2024
| 0.1.2 | Sep 15, 2025 |
|---|---|
| 0.1.1 | Sep 12, 2025 |
| 0.1.0 | Sep 10, 2025 |
#254 in FFI
134 downloads per month
Used in plux-rs
31KB
501 lines
Plux Lua Manager
A high-performance Lua plugin manager for Plux, providing a safe and efficient way to load, manage, and interact with Lua plugins.
Installation
Add to your Cargo.toml:
[dependencies]
plux-rs = { version = "1.0.0", features = ["derive"] }
plux-lua-manager = "0.1.1"
Features
The crate supports different Lua versions through feature flags:
lua54(default): Use Lua 5.4lua53: Use Lua 5.3lua52: Use Lua 5.2lua51: Use Lua 5.1
Quick Start
use plux_rs::{Loader, function::Request};
use plux_lua_manager::prelude::*;
// Declaring a function for lua plugin
#[plux_rs::function]
fn add(_: (), a: &i32, b: &i32) -> i32 {
a + b
}
// Declaring a function for lua plugin
#[plux_rs::function]
fn sub(_: (), a: &i32, b: &i32) -> i32 {
a - b
}
fn main() {
let mut loader = Loader::new();
loader.context(move |mut ctx| {
// Registering functions for lua plugin
ctx.register_function(add());
ctx.register_function(sub());
// Registering a entrypoint for lua plugin
ctx.register_request(Request::new("main".to_string(), vec![], None));
// Registering the manager
ctx.register_manager(LuaManager::new()).unwrap();
});
// Loading a plugin
let plugin = loader
.load_plugin_now("my_plugin-v0.1.0.lua")
.map(|bundle| loader.get_plugin_by_bundle(&bundle).unwrap())
.unwrap();
// Calling the 'main' request
plugin.call_request("main", &[]).unwrap().unwrap();
}
Plugin Structure
A typical plugin has the following structure:
my_plugin/
├── config.toml # Plugin configuration
├── main.lua # Main plugin code
└── ... # Additional Lua modules/resources
config.toml Example
name = "my_plugin"
description = "A sample plugin"
author = "Your Name"
version = "0.1.0"
# Dependencies
[dependencies]
other_plugin = "^1.0.0"
# Optional dependencies
[optional_dependencies]
optional_feature = "^2.0.0"
main.lua Example
-- Declaring a function for Plux
function mul(a, b)
return a * b;
end
function main()
print("4 + 6 = " .. add(4, 6)); -- Use the function from Plux
print("9 - 3 = " .. sub(9, 3)); -- Use the function from Plux
print("8 * 3 = " .. mul(8, 3));
end
-- Returning the functions to Plux
return {
{ name = "mul", inputs = {"a", "b"}, func = mul },
{ name = "main", inputs = {}, func = main }
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~4.5–7MB
~132K SLoC