Updated WebAssembly (markdown)

Hajime Hoshi 2018-07-06 03:54:44 +09:00
parent 43a4af26f1
commit 30279bf2dd

@ -1,14 +1,31 @@
This document is TBD. Write about Go 1.11 beta. As there are differences between the latest Go and Go 1.11 beta, I recommend to use the latest Go here.
# Get the latest Go # Get the latest Go
1. Checkout [neelance's wasm-wip branch of the Go compiler](https://github.com/neelance/go/tree/wasm-wip) 1. Checkout the latest Go (https://go.googlesource.com/go)
2. Compile the compiler by running `./all.bash` 2. Compile the compiler by running `./make.bash`
After that, use the compiled `go` binary. After that, use the compiled `go` binary.
# Get the template HTML # Create an HTML
https://github.com/neelance/go/tree/wasm-wip/misc/wasm ```html
<!DOCTYPE html>
<script src="wasm_exec.js"></script>
<script>
// Polyfill
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
WebAssembly.instantiateStreaming(fetch("sprites.wasm"), go.importObject).then(result => {
go.run(result.instance);
});
</script>
```
TBD TBD