Files
extism/node/example.js
zach ddcbeec3de refactor!: Remove context, unify extism-runtime and extism crates (#421)
- Removes the `ExtismContext` type from runtime and all SDKs
- Removed SDK functions: `extism_context_new`, `extism_context_reset`,
`extism_context_free`
  - All SDKs have been updated, but there are still some TODOs below 
- Removes `extism_plugin_update`
- Plugins can no longer be updated - a new plugin should be created
instead
- Adds `extism_plugin_id` to uniquely identify plugins
- Merges the `extism-runtime` and `extism` crates (there is no longer an
`extism-runtime` crate)
- Makes `extism::Manifest` an alias for `extism_manifest::Manifest`
instead of a distinct type
- Adds `MemoryHandle` type to SDKs to refer to blocks of Extism memory
that can be accessed in host functions
- Improves thread-safety of Plugins, adds C++ test to call a single
plugin from multiple threads.
- Expands wasmtime bounds to include 12.0
2023-08-29 13:57:17 -07:00

40 lines
885 B
JavaScript

const {
Plugin,
HostFunction,
ValType,
} = require("./dist/index.js");
const { readFileSync } = require("fs");
function f(currentPlugin, inputs, outputs, userData) {
console.log(currentPlugin.inputString(inputs[0]));
console.log("Hello from Javascript!");
console.log(userData);
outputs[0] = inputs[0];
}
const hello_world = new HostFunction(
"hello_world",
[ValType.I64],
[ValType.I64],
f,
"Hello again!",
);
async function main() {
const functions = [hello_world];
const wasm = readFileSync("../wasm/code-functions.wasm");
const p = new Plugin(wasm, true, functions);
if (!p.functionExists("count_vowels")) {
console.log("no function 'count_vowels' in wasm");
process.exit(1);
}
const buf = await p.call("count_vowels", process.argv[2] || "this is a test");
console.log(JSON.parse(buf.toString())["count"]);
p.free();
}
main();