1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { umdImport } from "https://esm.town/v/easrng/umdImport";
const loadWABT = (await umdImport(
"https://unpkg.com/wabt@1.0.32/index.js"
)) as typeof import("https://unpkg.com/wabt@1.0.32/index.d.ts");
const wabt = await loadWABT();
const wat = `
(module
(func (export "add") (param $lhs i32) (param $rhs i32) (result i32)
local.get $lhs
local.get $rhs
i32.add))
`;
const module = wabt.parseWat("add", wat);
const it = module.toBinary({});
const importObject = {};
WebAssembly.instantiate(module.toBinary({}).buffer, importObject).then(
function (res) {
console.log(res.instance.exports.add(5, 3));
}
);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
January 2, 2024