Created
July 3, 2018 12:42
-
-
Save jcttrll/959c84bba82e36ebdb6801955d66c7a8 to your computer and use it in GitHub Desktop.
Trivial example of running assembled WebAssembly text in Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(module | |
(func $add (param $a i32) (param $b i32) (result i32) | |
get_local $a | |
get_local $b | |
i32.add | |
) | |
(export "add" (func $add)) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs") | |
var binary = fs.readFileSync("blah.wasm") | |
var module = new WebAssembly.Module(binary) | |
var instance = new WebAssembly.Instance(module) | |
console.log(instance.exports.add(23, 45)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To Run
Clone the WABT repository and build it:
Ensure Node.js 8 (or later) is available on your path:
Download the files in the Gist into the
build
directory and assembleblah.wast
:Run the JS loader in Node: