print, require, on, inspect, class and the standard library a mod gets.
Every script mod runs in its own sandbox: a private global table with the safe parts of Lua's standard library
and the game API. Globals you create are yours alone; another mod cannot see or break them (use mod.exports and
mods.get to share). The API tables (world, ui, ...) are copies, so replacing world.spawn in your mod changes only
your own copy.
Available:assert error ipairs next pairs pcall xpcall select tonumber tostring type rawequal rawget rawset rawlen
setmetatable getmetatable unpack _VERSION, the libraries string table math utf8 coroutine, os.clock os.time os.date
os.difftime and debug.traceback.
Not available:io, the rest of os (no execute, remove, exit, getenv), package, dofile, loadfile,
the rest of debug, binary chunks. A mod reads files from its own folder with mod.read, and saves data with
mod.save / mod.load.
Limits: a single call into a mod (an event handler, a timer, the main chunk) may run for 3 seconds (10 when the mod
loads); after that it is stopped with the error "the script ran for too long (an endless loop?)". All mods share 1 GB
of Lua memory. An event handler that fails 20 times in a row is removed (the console says so).
Loads a Lua file of your mod once and returns its result; later calls return the same value. The module runs in your mod's sandbox (its globals are your globals).
Parameter
Type
name
string
a module of your mod: "util" loads util.lua, "ai.raptor" loads ai/raptor.lua (or ai/raptor/init.lua); "@othermod/name" loads a module from another enabled mod's folder
Returns
any
what the module returned (true when it returned nothing)
-- util.lua: local M = {} function M.double(x) return x * 2 end return Mlocal util = require("util")
print(util.double(21)) -- 42