Skip to content

Instantly share code, notes, and snippets.

@bryanburgers
Created November 28, 2023 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanburgers/ec1be23f116591264ef710a77f49c1fc to your computer and use it in GitHub Desktop.
Save bryanburgers/ec1be23f116591264ef710a77f49c1fc to your computer and use it in GitHub Desktop.
Runner for wasm articles
const fs = require("node:fs");
const filename = process.argv[2];
const wasmBuffer = fs.readFileSync(filename);
WebAssembly.instantiate(wasmBuffer).then((wasmModule) => {
const { main } = wasmModule.instance.exports;
const output = main();
console.log(output);
});
# wasm-tools comes from https://github.com/bytecodealliance/wasm-tools
# wat2wasm from https://github.com/WebAssembly/wabt would also work
%.wasm: %.wat
wasm-tools parse $^ -o $@
%: %.wasm
node index.js $^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment