zula-core

core shell object of zula

1 stable release

4.0.0 Nov 13, 2023
3.0.5 Nov 13, 2023
3.0.2 Aug 24, 2023
2.0.1 Aug 23, 2023
0.0.9 Aug 21, 2023
Download history 1/week @ 2024-07-26 20/week @ 2024-09-20 2/week @ 2024-09-27 1/week @ 2024-10-04

120 downloads per month
Used in zula

MIT/Apache

12KB
261 lines

zula-core is the core module of the zula shell. zula-core contains the core functionality of the zula shell, and is required for writing plugins. This api is experimental, and may introduce breaking changes.

Plugin Guide

To create a plugin, first initialize a library crate.

cargo new my_plugin --lib

Set the crate type to cdylib, and add zula-core as a dependency.

[lib]
crate-type = ["cdylib"]

[dependencies]
zula-core = "3.0.5"

Import the Plugin trait and implement it on your plugin type.

use zula-core::{Plugin, ShellState};
use std::error::Error;

pub struct MyPlugin;

impl Plugin for MyPlugin {
    //since this function is called across abi boundaries, its important to include no_mangle so
    //that rustc leaves the symbol as-is and can be called properly.
    #[no_mangle]
    fn init(&self) -> Box<dyn Plugin> {
        Box::new(Self)
    }
    fn name(&self) -> &str {
        "my_plugin"
    }
    fn call(&self, state: *mut ShellState) -> Result<(), Box<dyn Error>> {
        println!("Hello, plugin!")
    }
}

Run cargo build --release to build your plugin. The library file should be in target/release/lib<name>.so. This is the file that you'll put in your plugins folder.

Thats it! Run zula cfg inside zula to check that its loaded, and run plugin.<name> to use it. Due to weird ownership relationships, call has to take a raw pointer, so use it responsibly.

Dependencies

~0.2–8MB
~49K SLoC