How it works
Your mod (Workshop) AllTheLanguages (Workshop) ------------------- -------------------------- module .json {id, name, ..., wasm} bootstrap autoTool --register--> Registry decodes and instantiates modules one Lua file per part --scriptClass--> ScriptClass turns exports into a game script class Runtime drives every mod's ticks GDT the bridge between WASM and Lua WASM engine runs the module, written in Lua1. Bootstrap
Section titled "1. Bootstrap"Scrap Mechanic only runs a mod's Lua when one of its scripted objects exists. Every WASM mod
therefore ships a hidden "autoTool": true tool. The game creates one per player, so nothing
needs to be placed. Its script calls:
sm.allthelanguages.register(sm.json.open("$CONTENT_DATA/mod.json"))Registering is idempotent, so running once per player is harmless. atl-build adds this tool for you.
2. Registry
Section titled "2. Registry"The registry decodes the bytecode, waits for any dependencies (other WASM mod ids), then
instantiates the module with the loader's GDT.
3. Runtime
Section titled "3. Runtime"The loader's own autoTool calls each mod's lifecycle exports (server_onCreate,
server_onFixedUpdate(dt), client_onUpdate(dt), ...). One tool instance per side is
elected driver, so every export runs once per tick, not once per player.
4. Script classes
Section titled "4. Script classes"Parts and tools are implemented in WASM too. A two-line Lua file asks the mod for a class by name:
dofile("$CONTENT_b6e3437f-3460-4ec3-ade6-5e12e20765c5/Scripts/AllTheLanguages/Init.lua")HelloBlock = sm.allthelanguages.register(sm.json.open("$CONTENT_DATA/mod.json")):scriptClass("HelloBlock")C++ and Rust mods describe their classes through atl_class_describe / atl_class_call.
Compiled C mods export <Class>_<method> functions instead. The game-side class only gets the
methods the mod implements, plus create and destroy, which the loader uses to free
per-instance state once both the server and client sides are gone.
5. Faults
Section titled "5. Faults"A trap disables only the mod that trapped. The loader logs a crash report with a WASM-level
traceback and stops calling that mod. mod:reload() restarts it with fresh memory.
A mod can opt out of being disabled with "trapPolicy": "continue" in its
metadata: a failing call then fails on its own and the mod keeps
running.
The WASM engine
Section titled "The WASM engine"AllTheLanguages runs modules in a WebAssembly engine written in pure Lua. It compiles each function to Lua closures on its first call. Every call into the game goes through the GDT, which costs one round trip to the host.