Skip to content

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.

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.

Returns the Mod registered under id, or nil.

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.

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.

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.

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.

scriptClass plus drive: the returned class also drives every mod's mod-wide lifecycle. Used for a custom game's game script.

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.

Calls export name with numeric arguments and returns its results. Raises an error if there is no such export or the call fails.

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.

Restarts the mod with fresh memory. Use it after the mod has trapped.

true once the mod is instantiated and hasn't trapped.

true if the module exports name.