WASM WASI Core API
This npm module implements an API facade for the WASM WASI Core VS Code extension.
History
0.11.0
With release version 0.11.0
the implementation details of the WASM support for VS Code has changed. This npm module is now a facade around the wasm-wasi-core
VS Code extension.
Example
The source code of the example can be found here
First we need to define a package.json
for the extension that wants to execute a WASM process:
{
"name": "...",
...
// depend on the wasm-wasi-core extension
"extensionDependencies": [
"ms-vscode.wasm-wasi-core"
],
// Depend on the wasm-wasi facade npm module to get easier API access to the
// core extension.
"dependencies": {
"@vscode/wasm-wasi": "..."
},
}
The actual source code to execute a WASM process looks like this
const wasm: Wasm = await Wasm.api();
const pty = wasm.createPseudoterminal();
const terminal = window.createTerminal({ name: 'Run C Example', pty, isTransient: true });
terminal.show(true);
try {
const bits = await workspace.fs.readFile(Uri.joinPath(context.extensionUri, 'hello.wasm'));
const module = await WebAssembly.compile(bits);
const process = await wasm.createProcess('hello', module, { stdio: pty.stdio });
const result = await process.run();
} catch (error) {
void window.showErrorMessage(error.message);
}