Lua API
Load the loader before using it:
dofile("$CONTENT_b6e3437f-3460-4ec3-ade6-5e12e20765c5/Scripts/AllTheLanguages/Init.lua")Loading it more than once is harmless.
sm.allthelanguages
Section titled "sm.allthelanguages"register(meta, wasm)
Section titled "register(meta, wasm)"local mod = sm.allthelanguages.register(sm.json.open("$CONTENT_DATA/mod.json"))Registers a module and returns its Mod. meta is a mod.json table.
The bytecode comes from wasm, or from meta.wasm when wasm is omitted. meta.id must be
a non-empty string.
Registering the same id with the same bytecode again returns the existing mod, so calling it once per player is fine. Registering an id with different bytecode replaces the module.
A mod whose dependencies aren't registered yet waits, and loads once they are.
getMod(id)
Section titled "getMod(id)"Returns the Mod registered under id, or nil.
getMods()
Section titled "getMods()"Returns a list of every registered Mod, in the order they were registered.
scriptClass(modId, name, fields, base)
Section titled "scriptClass(modId, name, fields, base)"The same as getMod(modId):scriptClass(name, fields, base). Raises an error if no mod is
registered under modId.
drive(cls)
Section titled "drive(cls)"Makes a Lua class drive every registered mod's mod-wide lifecycle, as the loader's runtime
tool does. Returns cls. Used by custom games. Each tick runs once,
however many classes drive it.
bindCallback(slot)
Section titled "bindCallback(slot)"Adds a method for callback slot slot to the class of the script currently running a WASM
call, and returns the method's name. The C++ and Rust SDKs use it for
GUI and engine callbacks; mods don't call it directly.
VERSION
Section titled "VERSION"The loader's version string.
mod:scriptClass(name, fields, base)
Section titled "mod:scriptClass(name, fields, base)"Returns a game-side script class for the WASM class name. Copies fields (a table of
engine settings such as connectionInput, or a world's terrainScript) onto the class. When
base is given, the class extends that Lua class.
The class only gets the callbacks the WASM class implements. If the module failed to decode, isn't ready, or has no class by that name, the error is logged and the class has no methods.
mod:gameClass(name, fields, base)
Section titled "mod:gameClass(name, fields, base)"scriptClass plus drive: the returned class also drives every mod's mod-wide lifecycle.
Used for a custom game's game script.
mod:terrainScript(name)
Section titled "mod:terrainScript(name)"Returns a table of terrain functions (Init, Load, GetHeightAt, ...) for the WASM terrain
class name. Only the functions the class implements are present. Assign them to the globals
the engine calls.
mod:call(name, ...)
Section titled "mod:call(name, ...)"Calls export name with numeric arguments and returns its results. Raises an error if there is
no such export or the call fails.
mod:makeCallback(name)
Section titled "mod:makeCallback(name)"Returns a Lua function that calls export name with any Lua values, using the value-handle
convention script classes use. Raises an error if there is no such export.
mod:reload()
Section titled "mod:reload()"Restarts the mod with fresh memory. Use it after the mod has trapped.
mod:isReady()
Section titled "mod:isReady()"true once the mod is instantiated and hasn't trapped.
mod:hasExport(name)
Section titled "mod:hasExport(name)"true if the module exports name.