Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created September 28, 2020 05:41
Show Gist options
  • Save deleteman/3de7fae229a003fa463d5b1db332804e to your computer and use it in GitHub Desktop.
Save deleteman/3de7fae229a003fa463d5b1db332804e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<p class="title">Web Assembly Example</p>
<script>
WebAssembly.instantiateStreaming(fetch("./build/optimized.wasm"), {
main: {
sayHello() {
console.log("Hello from WebAssembly!");
}
},
env: {
abort(_msg, _file, line, column) {
console.error("abort called at main.ts:" + line + ":" + column);
}
},
}).then(result => {
const exports = result.instance.exports;
document.getElementById("container").textContent = "Result: " + exports.add(19, 23);
}).catch(console.error);
</script>
<p id="container"></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment