-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
40 lines (40 loc) · 1.1 KB
/
index.html
File metadata and controls
40 lines (40 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>O program in WebAssembly</title>
</head>
<body>
<pre id="log"></pre>
<script>
const logElem = document.getElementById("log");
function logLine(text) {
logElem.textContent += text + "\n";
console.log(text);
}
async function main() {
try {
const response = await fetch("out5.wasm");
const bytes = await response.arrayBuffer();
const module = await WebAssembly.instantiate(bytes, {
env: {
print_i32: function(x) {
logLine("output: " + x);
}
}
});
if (module.instance.exports._start) {
module.instance.exports._start();
} else if (module.instance.exports.main) {
module.instance.exports.main();
} else {
logLine("No _start or main export in wasm module");
}
} catch (e) {
logLine("Error: " + e);
}
}
main();
</script>
</body>
</html>