╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2 3 let wasmInstance; 4 const decoder = new TextDecoder(); 5 let currentHtml = ""; 6 7 function readWasmString(ptr, len) { 8 const memory = wasmInstance.exports.memory; 9 return decoder.decode(new Uint8Array(memory.buffer, ptr, len)); 10 } 11 12 var importObject = { 13 env: { 14 _consoleLog: function(ptr, len) { 15 console.log(readWasmString(ptr, len)); 16 }, 17 _setHtml: function(ptr, len) { 18 const html = readWasmString(ptr, len); 19 if (html !== currentHtml) { 20 currentHtml = html; 21 grid.innerHTML = html; 22 } 23 }, 24 }, 25 }; 26 27 WebAssembly.instantiateStreaming(fetch("haxy.wasm"), importObject).then((result) => { 28 wasmInstance = result.instance; 29 wasmInstance.exports._start(); 30 31 document.addEventListener("keydown", (event) => { 32 if (["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End"].includes(event.key)) { 33 event.preventDefault(); 34 } 35 wasmInstance.exports._onKeyDown(event.keyCode); 36 wasmInstance.exports._tick(); 37 }); 38 }); 39