@obinexusltd/wasm-polycall
v1.0.0
Published
WebAssembly host import binding for libpolycall.
Downloads
71
Maintainers
Readme
wasm-polycall
@obinexusltd/wasm-polycall is the WebAssembly host-import binding for
libpolycall. It is a thin adapter:
WASM modules import polycall_ffi_run_config, and the JavaScript host shim maps
that import to a host callback that represents polycall_ffi_run_config(config_path, 1).
libpolycall release host:
https://github.com/obinexus/libpolycall/releases#release-libpolycall-1.0.0
Install
npm install @obinexusltd/wasm-polycallOr inspect/run the package CLI with npx:
npx @obinexusltd/wasm-polycall --help
npx @obinexusltd/wasm-polycall host-smoke
npx @obinexusltd/wasm-polycall inspect ./dist/module.wasmHost import contract
WASM modules may import the function from either env or polycall:
(import "env" "polycall_ffi_run_config"
(func $polycall_ffi_run_config (param i32 i32) (result i32)))The first i32 is a pointer to a NUL-terminated UTF-8 config path in WASM
linear memory. The second i32 is the libpolycall FFI mode; this adapter uses
mode 1 for config execution.
JavaScript API
const {
createPolycallHost,
writeCString
} = require("@obinexusltd/wasm-polycall");
const memory = new WebAssembly.Memory({ initial: 1 });
const host = createPolycallHost({
memory,
runConfig(configPath, mode) {
console.log({ configPath, mode });
return mode === 1 ? 0 : 1;
}
});
const pointer = writeCString(memory, "wasm-polycallrc", 0);
const status = host.imports.env.polycall_ffi_run_config(pointer, 1);For compiled modules, use instantiatePolycallModule(input, options). It
provides both supported import namespaces and attaches exported memory
automatically when the module exports memory.
Package layout
wasm-polycall/
|-- bin/
| `-- wasm-polycall.js
|-- dist/
| `-- README.md
|-- examples/
| |-- module.wat
| `-- run.js
|-- generated/
| `-- polycall/
| |-- abi.json
| `-- polycall_ffi.h
|-- src/
| `-- wasm_polycall.js
|-- tests/
|-- index.js
|-- package.json
|-- polycall-binding.json
|-- wasm-polycallrc
`-- README.mdVerification
npm test
npm pack --dry-run --jsonnpm test checks package metadata, source-directory indexing, host import
behavior, and the npm bin command used by npx.
Publishing
The package is configured for public scoped publishing:
npm publish --access publicLicense
MIT © Nnamdi Michael Okpala
