19 lines
602 B
JavaScript
19 lines
602 B
JavaScript
const imports = {
|
|
guppy: {
|
|
print: (arg) => console.log (arg)
|
|
}
|
|
}
|
|
|
|
// Assume add.wasm file exists that contains a single function adding 2 provided arguments
|
|
const fs = require('node:fs');
|
|
|
|
// Use the readFileSync function to read the contents of the "add.wasm" file
|
|
const wasmBuffer = fs.readFileSync('u.wasm');
|
|
|
|
// Use the WebAssembly.instantiate method to instantiate the WebAssembly module
|
|
WebAssembly.instantiate(wasmBuffer, imports).then(wasmModule => {
|
|
// Exported function lives under instance.exports object
|
|
const { main } = wasmModule.instance.exports;
|
|
main ()
|
|
});
|