-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
32 lines (31 loc) · 912 Bytes
/
index.html
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
<!--
https://www.tutorialspoint.com/webassembly/webassembly_hello_world.htm
-->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WebAssembly Add Function</title>
<style>
div {
font-size : 30px; text-align : center; color: blue;
}
</style>
</head>
<body>
<div id="textcontent"></div>
<script>
fetch("twice.wasm") // Load wasm file
.then(bytes => bytes.arrayBuffer())
.then(mod => WebAssembly.compile(mod))
.then(module => {return new WebAssembly.Instance(module)})
.then(instance => {
console.log(instance);
const num = 3.0;
let result = instance.exports.twice(num);
let msg = `twice(${num}) = ${result}`;
document.getElementById("textcontent").innerHTML = msg;
});
</script>
</body>
</html>