WebAssembly 在线Editor
WebAssembly Studiohttps://webassembly.studio/ C源码:
WASM_EXPORT
int add( int a, int b){
return a + b;
}
JS调用
fetch('./math.wasm').then(response =>
response.arrayBuffer()
).then( bytes => WebAssembly.instantiate(bytes) ).then( results => {
instance = results.instance;
const add = instance.exports.add;
int result = add(1, 2);
console.log(" 1 + 2 = " + result );
}).catch(console.error);