improve file selection button, first version of uw8-tool to build base.wasm

This commit is contained in:
2021-11-03 23:58:44 +01:00
parent 160afba8b0
commit 348657163d
6 changed files with 231 additions and 15 deletions

View File

@@ -12,8 +12,7 @@
<div id="centered">
<canvas id="screen" width="640" height="512"></canvas>
<div id="message"></div>
<button onclick="document.getElementById('cart').click()">Load cart...</button>
<input id="cart" style="visibility: hidden" type="file" accept=".wasm,.uw8,application/wasm">
<button id="cartButton">Load cart...</button>
</div>
<div id="footer">
<a href="http://unlicense.org/" ref="license">Unlicense</a>

View File

@@ -80,13 +80,14 @@ async function runModule(data) {
let importObject = {
env: {
memory: new WebAssembly.Memory({ initial: 8, maximum: 8 }),
memory: new WebAssembly.Memory({ initial: 4, maximum: 4 }),
},
math: {
sin: Math.sin,
cos: Math.cos
}
math: {}
};
for(let n of ['acos','asin','atan','atan2','cos','exp','log','sin','tan']) {
importObject.math[n] = Math[n];
}
let instance = new WebAssembly.Instance(await WebAssembly.compile(data), importObject);
@@ -141,12 +142,17 @@ function runModuleFromHash() {
}
}
let fileInput = document.getElementById('cart');
fileInput.onchange = () => {
if(fileInput.files.length > 0) {
runModuleFromURL(URL.createObjectURL(fileInput.files[0]));
}
};
window.onhashchange = runModuleFromHash;
runModuleFromHash();
runModuleFromHash();
document.getElementById('cartButton').onclick = () => {
let fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = '.wasm,.uw8,application/wasm';
fileInput.onchange = () => {
if(fileInput.files.length > 0) {
runModuleFromURL(URL.createObjectURL(fileInput.files[0]));
}
};
fileInput.click();
};