Start
Start is a special function that runs after the WebAssembly module is initialized. Let's take the same example that we used for the globals. We add the following content to globals.wat
:
(module ; Code is elided (func $initMutableValue (global.set $mutableValue (i32.const 200))) (start $initMutableValue) )
We define the initMutableValue
function, which sets mutableValue
to 200
. After that, we add a start block, which starts with startkeyword
followed by the name of the function.
Note
The function referenced at the start should not return any value.
Let's use WABT to convert the WebAssembly text format into a WebAssembly module with the following command:
$ /path/to/wabt/bin/wat2wasm globals.wat
Let's run the example...