35 lines
836 B
JavaScript
35 lines
836 B
JavaScript
(async () => {
|
|
let instance = await WebAssembly.instantiateStreaming(fetch("module.wasm"));
|
|
const memSize = new Int32Array(
|
|
instance.instance.exports.memory.buffer,
|
|
instance.instance.exports.WASMGLmemory.value + 4,
|
|
1
|
|
)[0]
|
|
|
|
let mem = new Int32Array(
|
|
instance.instance.exports.memory.buffer,
|
|
instance.instance.exports.WASMGLmemory.value,
|
|
memSize
|
|
);
|
|
|
|
let ptr = alloc(mem, 4);
|
|
setstr(mem, ptr, 4, "game");
|
|
|
|
console.log(String.fromCharCode(instance.instance.exports.initialize(ptr, 4)));
|
|
})();
|
|
|
|
function alloc(mem, size) {
|
|
const head = mem[2];
|
|
console.log(head);
|
|
mem[2] += size;
|
|
|
|
return head;
|
|
}
|
|
|
|
function setstr(mem, ptr, size, str) {
|
|
for (let i = 0; i < size; i++) {
|
|
mem[ptr] = str.charCodeAt(i);
|
|
++ptr;
|
|
}
|
|
}
|