gut-plugin 0.1.0

Helper library that provides a macro to create plugins for Gut
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 8.87 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 311.59 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • gut-hub/gut-plugin
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jareddlc

gut-plugin

Helper library that provides a macro to create plugins for gut.

The gut plugin system loads plugins that are written in wasm that are located in the gut directory $HOME/.gut.

How to create a gut plugin

  1. Create a new library using cargo
$ cargo new my_gut_plugin --lib
  1. Add the following to the Cargo.toml:
[lib]
name = "gut_myplugin"
crate-type = ["cdylib"]

[dependencies]
gut-plugin = "0.1.0"
  1. Use the provided macro to export the function
use std::slice;
use std::str;

// gut_export!([names], [descriptions])
// names: [&str] - the names of the functions to export.
// descriptions: [&str] - the descriptions of the functions to export.
gut_plugin::gut_export!(
  ["my_plugin"],
  ["Prints the provided string"]
);

// all exported functions must have this signature:
//
// #[no_mangle]
// fn_name(ptr: i32, len: i32)
//
// this is becuase gut will invoke the function and pass a string if one is provided.
// example:
// $ gut my_plugin "world"
#[no_mangle]
fn my_plugin(ptr: i32, len: i32) {
  let slice = unsafe { slice::from_raw_parts(ptr as _, len as _) };
  let string_from_host = str::from_utf8(&slice).unwrap();

  println!("Hello {}!", string_from_host)
}
  1. Build
# you may need to add wasm32-wasi target to build wasm
$ rustup target add wasm32-wasi

# build
$ cargo build --target wasm32-wasi --release

# move to gut directory
$ cp target/wasm32-wasi/release/gut_myplugin.wasm $HOME/.gut/