There are two patterns of WASI Wasm modules: commands and reactors.
Commands typically have a main function that is run after which the module exists (calls wasi_snapshot_preview1.proc_exit()). This main function is triggered by the modules exported _start() function.
Reactors are longer-lived modules. If the module requires setup e.g. memory initialization, it should be done once after module instantiation and is triggered by the modules exported _initialize() function.
This is all well and good in theory but seems to be abused by many compilers targeting WebAssembly. It seems prudent to either:
Not call either _start() or _initialize() and leave this entirely up to the user of Godot Wasm.
Expose aa initialize setting on the Wasm class that allows a user to define the startup function to be immediately on module initialization.
Call _initialize(). This supports the reactor pattern as it will be interacted with by the user of Godot Wasm later via function(), global(), etc. To support the command pattern, the user has to simply call my_module.function("_start", []).
One thing is certain: Godot Wasm should not blindly call _start immediately on instantiation as it currently does.
There are two patterns of WASI Wasm modules: commands and reactors.
wasi_snapshot_preview1.proc_exit()
). This main function is triggered by the modules exported_start()
function._initialize()
function.This is all well and good in theory but seems to be abused by many compilers targeting WebAssembly. It seems prudent to either:
_start()
or_initialize()
and leave this entirely up to the user of Godot Wasm.initialize
setting on the Wasm class that allows a user to define the startup function to be immediately on module initialization._initialize()
. This supports the reactor pattern as it will be interacted with by the user of Godot Wasm later viafunction()
,global()
, etc. To support the command pattern, the user has to simply callmy_module.function("_start", [])
.One thing is certain: Godot Wasm should not blindly call
_start
immediately on instantiation as it currently does.