Skip to content

WebAssembly

Jake Bentvelzen edited this page Aug 26, 2018 · 28 revisions

The easiest way is to use WasmServe with the latest Go.

Requirements

  • Go 1.11
  • Ebiten 2.0.0-alpha / master branch

Compile your game

GOOS=js GOARCH=wasm go build -o yourgame.wasm github.com/yourname/yourgame

Copy wasm_exec.js to execute the Wasm binary

cp $GOROOT/misc/wasm/wasm_exec.js .

Source: https://github.com/golang/go/tree/master/misc/wasm

Create an 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("yourgame.wasm"), go.importObject).then(result => {
  go.run(result.instance);
});
</script>

TBD

Clone this wiki locally