-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
57 lines (50 loc) · 1.93 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lanf="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>First Pull Request</title>
</head>
<body>
<h2>Welcome to First Pull Request!</h2>
<p>According to our <a href="https://github.com/alex1yaremchuk/first-pull-request/blob/main/javascript/src/index.js" target="_blank">
JS add function</a> <b><span id="calculator-result"></span></b></p>
<p>According to our <a href="https://github.com/alex1yaremchuk/first-pull-request/blob/main/zig/index.zig" target="_blank">Zig add function</a> <b><span id="zig-result"></span></b></p>
<p>Feel free to fix anything that doesn't look right!</p>
<p>Look for an open issue <a href="https://github.com/alex1yaremchuk/first-pull-request/issues" target="_blank">here</a>.</p>
<p>Become a contributor! <a href="https://github.com/alex1yaremchuk/first-pull-request">repo's here</a></p>
<script>
async function loadWasm() {
console.log('1');
const response = await fetch('index.wasm');
const buffer = await response.arrayBuffer();
const typedArray = new Uint8Array(buffer);
const config = {
env: {
memoryBase: 0,
tableBase: 0,
memory: new WebAssembly.Memory({
initial: 2,
maximum: 2,
}),
table: new WebAssembly.Table({
initial: 0,
element: 'anyfunc',
}),
}
}
WebAssembly.instantiate(typedArray, config).then(result => {
const add = result.instance.exports.add;
document.getElementById('zig-result').textContent = `5 + 7 = ${add(5, 7)}`;
});
}
loadWasm();
</script>
<script type="module">
import { add } from './javascript/src/index.js'
console.log(document.getElementById('calculator-result'));
document.getElementById('calculator-result').textContent =
`1 + 2 = ${add(1, 2)}`
</script>
</body>
</html>