37 lines
No EOL
967 B
HTML
37 lines
No EOL
967 B
HTML
<HTML>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Go and WebAssembly</title>
|
|
</head>
|
|
|
|
<body>
|
|
<script src="wasm_exec.js"></script>
|
|
<script>
|
|
if (!WebAssembly.instantiateStreaming) { // polyfill
|
|
WebAssembly.instantiateStreaming = async (resp, importObject) => {
|
|
const source = await (await resp).arrayBuffer();
|
|
return await WebAssembly.instantiate(source, importObject);
|
|
};
|
|
}
|
|
|
|
const go = new Go();
|
|
let mod, inst;
|
|
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
|
|
mod = result.module;
|
|
inst = result.instance;
|
|
document.getElementById("runButton").disabled = false;
|
|
}).catch((err) => {
|
|
console.error(err);
|
|
});
|
|
|
|
async function run() {
|
|
console.clear();
|
|
await go.run(inst);
|
|
inst = await WebAssembly.instantiate(mod, go.importObject);
|
|
}
|
|
</script>
|
|
|
|
<button onClick="run();" id="runButton" disabled>Run</button>
|
|
</body>
|
|
</HTML> |