Exports and imports
A WebAssembly module consists of export and import sections. These sections are responsible for exporting functions out of and importing functions into the WebAssembly module.
Exports
In order to call the functions defined in a WebAssembly module from JavaScript, we need to export the functions from the WebAssembly module. The export section is where we will define all the functions that are exported out of the WebAssembly module.
Let's go back to our classic add.wat
example from the previous chapter:
; add.wat (module (func $add (param $lhs i32) (param $rhs i32) (result i32) get_local $lhs get_local $rhs i32.add) (export "add" (func $add)) )
Here, we have exported the add
function using the (export "add...