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 thejavy
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 createdjavy::Runtime
.
§Features
json
- enables thejson
feature in thejavy
crate.messagepack
- enables themessagepack
feature in thejavy
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.