Crate javy_plugin_api

Crate javy_plugin_api 

Source
Expand description

A crate for creating Javy plugins

Example usage:

use javy_plugin_api::{
    javy::{quickjs::prelude::Func, Runtime},
    javy_plugin, Config,
};

wit_bindgen::generate!({ world: "my-javy-plugin-v1", generate_all });

fn config() -> Config {
    let mut config = Config::default();
    config
        .text_encoding(true)
        .javy_stream_io(true);
    config
}

fn modify_runtime(runtime: Runtime) -> Runtime {
    runtime.context().with(|ctx| {
        ctx.globals().set("plugin", true).unwrap();
    });
    runtime
}

struct Component;

// Dynamically linked modules will use `my_javy_plugin_v1` as the import
// namespace.
javy_plugin!("my-javy-plugin-v1", Component, config, modify_runtime);

export!(Component);

The crate will automatically add exports for a number of Wasm functions in your crate that Javy needs to work.

§Core concepts

  • javy - a re-export of the javy crate.
  • javy_plugin - Takes a namespace to use for the module name for imports, a struct to add function exports to, a config method, and a method for updating the Javy runtime.
  • Config - to add behavior to the created javy::Runtime.

§Features

  • json - enables the json feature in the javy crate.
  • messagepack - enables the messagepack feature in the javy crate.

Re-exports§

pub use javy;

Macros§

import_namespace
Create a custom section named import_namespace with the contents of the string argument.
javy_plugin
Provides default implementations for required methods a Javy plugin.

Structs§

Config
A configuration for the Javy plugin API.

Functions§

compile_src
Compiles JS source code to QuickJS bytecode.
initialize_runtime
Initializes the Javy runtime.
invoke
Evaluates QuickJS bytecode and optionally invokes exported JS function with name.