Search⌘ K
AI Features

The Start Function

Explore how the start function operates in WebAssembly by setting initial values when a module loads. Understand its role, how to define it in WAT format, convert it using WABT, and execute it in browsers. This lesson helps you grasp module initialization and its significance.

We'll cover the following...

The start function 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:

C++
(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 the ...