#define WASM_EXPORT __attribute__((visibility("default"))) WASM_EXPORT int add(int a, int b) { return a + b; } #[no_mangle] pub extern fn add(x: i32, y: i32) -> i32 { x + y } export function add(x: i32, y: i32): i32 { return x + y; }
= 0; // id for the first item memory[1] = 10; // price of the first item memory[8] = 2; // id for the first item memory[9] = 770; // the second item’s price wasm.exports.add(0, 8);
const wasm = WebAssembly.instantiate(wasmFile, imports); const memory = new Uint32Array(wasm.exports.memory.buffer); memory[8] = 2; // id for the first item memory[9] = 770; // the second item’s price wasm.exports.price(8); // returns 720