ashtonmeuser / godot-wasm

Interact with WebAssembly modules from Godot
https://github.com/ashtonmeuser/godot-wasm/wiki
MIT License
193 stars 11 forks source link

Calling WASI `_start` causes some modules to exit #42

Closed ashtonmeuser closed 1 year ago

ashtonmeuser commented 1 year ago

There are two patterns of WASI Wasm modules: commands and reactors.

This is all well and good in theory but seems to be abused by many compilers targeting WebAssembly. It seems prudent to either:

  1. Not call either _start() or _initialize() and leave this entirely up to the user of Godot Wasm.
  2. Expose aa initialize setting on the Wasm class that allows a user to define the startup function to be immediately on module initialization.
  3. 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.

ashtonmeuser commented 1 year ago

Solved in https://github.com/ashtonmeuser/godot-wasm/commit/58f8002f54a3f4dfab5066d74817a740fd43d7f9 using option 3 outline above.