mirror of
https://github.com/extism/extism.git
synced 2026-04-23 03:00:11 -04:00
23 lines
685 B
JavaScript
23 lines
685 B
JavaScript
import { withContext, Context } from "./dist/index.js";
|
|
import { readFileSync } from "fs";
|
|
|
|
withContext(async function (context) {
|
|
let wasm = readFileSync("../wasm/code.wasm");
|
|
let p = context.plugin(wasm);
|
|
|
|
if (!p.functionExists("count_vowels")) {
|
|
console.log("no function 'count_vowels' in wasm");
|
|
process.exit(1);
|
|
}
|
|
|
|
let buf = await p.call("count_vowels", process.argv[2] || "this is a test");
|
|
console.log(JSON.parse(buf.toString())["count"]);
|
|
p.free();
|
|
});
|
|
|
|
// or, use a context like this:
|
|
let ctx = new Context();
|
|
let wasm = readFileSync("../wasm/code.wasm");
|
|
let p = ctx.plugin(wasm);
|
|
// ... where the context can be passed around to various functions etc.
|