19 lines
474 B
JavaScript
19 lines
474 B
JavaScript
const memory = new WebAssembly.Memory({ initial: 1 });
|
|
|
|
const log = (offset, length) => {
|
|
const bytes = new Uint8Array(memory.buffer, offset, length);
|
|
const string = new TextDecoder('utf8').decode(bytes);
|
|
|
|
console.log(string);
|
|
};
|
|
|
|
(async () => {
|
|
const response = await fetch('./hello.wasm');
|
|
const bytes = await response.arrayBuffer();
|
|
const { instance } = await WebAssembly.instantiate(bytes, {
|
|
env: { log, memory }
|
|
});
|
|
|
|
instance.exports.hello();
|
|
})();
|