Let's explore a simple example of logging some text from a WebAssembly program.
We must:
console.log
.Here's an example of what that receiving JavaScript function would look like:
wasm_log(start,len) {
// extract text from memory location and length
const utf8dec = new TextDecoder("utf-8");
let buffer = module.instance.exports.memory.buffer;
let memory = new Uint8Array(buffer);
let text = utf8dec.decode(memory.subarray(start,start+len));
console.log(text);
}