#plugin #traits #load #interface #phaneron #node #loaded

phaneron-plugin

Interfaces for implementing Phaneron plugins in Rust

1 unstable release

0.1.2 Apr 26, 2023
0.1.1 Apr 26, 2023

#276 in Video


Used in 4 crates

MIT license

29KB
609 lines

Phaneron Plugin Library

This crate serves to provide a way to create plugins for Phaneron using rust.


lib.rs:

This module defines the interfaces to be implemented for a Phaneron plugin to be successfully loaded.

To create a plugin you must have a function annotated with the #[export_root_module] from the abi_stable crate. This function should return a PhaneronPluginRootModule which acts as the handle which can be used to initialize your plugin. This first function should not perform any additional work such as loading assets etc. as your plugin will be given an opportunity to initialize itself later.

You should then have a load function that is annotated using the #[sabi_external_fn] macro from the abi_stable crate. This function is the initializer for your plugin and is where you can load assets that are globally required and pre-allocate large amounts of memory if required. This function is allowed to fail and will only be called once. If it fails then the plugin will not be loaded and Phaneron will not attempt to load the plugin again. If failing, please return some useful error message.

#[export_root_module]
fn instantiate_root_module() -> PhaneronPluginRootModuleRef {
    PhaneronPluginRootModule { load }.leak_into_prefix()
}

#[sabi_extern_fn]
pub fn load(context: PhaneronPluginContext) -> RResult<PhaneronPlugin, RString> {
    log::set_logger(phaneron_plugin::get_logger(&context)).unwrap();
    log::set_max_level(LevelFilter::Trace);
    let plugin = DemoPlugin {};

    ROk(PhaneronPlugin_TO::from_value(plugin, TD_Opaque))
}

#
#

The returned plugin is of type DemoPlugin in this instance, which implements the PhaneronPlugin trait. This object will be used to create nodes from your plugin and manage its lifecycle. Refer to the documentation of PhaneronPlugin.

Dependencies

~4–10MB
~103K SLoC