Functions

Function

(func $add11 (param $p i32) (result i32) 
// name of func, paramter, return value (returns the last value on the stack)
    get_local $p
    i32.const 11
    i32.add)

// call function with param of 4
i32.const 4
call $add11

Function Export Example

(func (export "add11") (param $p i32) (result i32)
    get_local $p
    i32.const 11
    i32.add)
WebAssembly.instantiate(wasmModule.toBinary({}).buffer, importObject).then(function(res) {
    console.log(res.instance.exports.add11(2));
  });

Function Import Example

Last updated

Was this helpful?