feat: added readme and docs to plugin_api

This commit is contained in:
Byson94
2025-10-08 20:25:00 +05:30
parent ca63ebe504
commit 45657e145c
5 changed files with 40 additions and 6 deletions

2
Cargo.lock generated
View File

@@ -527,7 +527,7 @@ dependencies = [
[[package]]
name = "ewwii_plugin_api"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"rhai",
]

View File

@@ -1,10 +1,10 @@
[package]
name = "ewwii_plugin_api"
version = "0.1.0"
version = "0.1.1"
authors = ["byson94 <byson94wastaken@gmail.com>"]
edition = "2021"
license = "GPL-3.0-or-later"
description = "The full ewwii plugin API shared library"
description = "The full ewwii plugin API shared library for building plugins"
repository = "https://github.com/byson94/ewwii"
homepage = "https://github.com/byson94/ewwii"

View File

@@ -0,0 +1,31 @@
# ewwii_plugin_api
A shared interface providing traits for building plugins for ewwii.
## Example
A simple example showing how to use this interface is provided below:
```rust
use ewwii_plugin_api::{EwwiiAPI, Plugin};
pub struct DummyStructure;
impl Plugin for DummyStructure {
// critical for ewwii to launch the plugin
fn init(&self, host: &dyn EwwiiAPI) {
// will be printed by the host
host.log("Plugin says Hello!");
host.rhai_engine_action(Box::new(|engine| {
let ast = engine.compile("1+1");
println!("Compiled AST: {:#?}", ast);
}));
}
}
// Critical for ewwii to see the plugin
#[unsafe(no_mangle)]
pub extern "C" fn create_plugin() -> Box<dyn Plugin> {
Box::new(DummyStructure)
}
```

View File

@@ -2,14 +2,17 @@ use rhai::Engine;
/// The shared trait defining the Ewwii plugin API
pub trait EwwiiAPI: Send + Sync {
// General stuff
// == General stuff == //
/// Print a message from the host
fn log(&self, msg: &str);
// Rhai Manipulation Stuff
// == Rhai Manipulation Stuff == //
/// Perform an action on the current real-time rhai engine
fn rhai_engine_action(&self, f: Box<dyn FnOnce(&mut Engine) + Send>) -> Result<(), String>;
}
/// The API format that the plugin should follow
pub trait Plugin: Send + Sync {
/// Function ran by host to startup plugin (and its a must-have for plugin loading)
fn init(&self, host: &dyn EwwiiAPI);
}

View File

@@ -41,7 +41,7 @@ pub fn register_all_widgets(engine: &mut Engine, all_nodes: &Rc<RefCell<Vec<Widg
register_primitive!("input", Input);
register_primitive!("progress", Progress);
register_primitive!("combo_box_text", ComboBoxText);
register_primitive!("slider", Slider);
register_primitive!("scale", Slider);
register_primitive!("checkbox", Checkbox);
register_primitive!("calendar", Calendar);
register_primitive!("graph", Graph);