Tiny Strats Modding

The mod language

A Luau subset. Typed Luau parses: annotations, type/export type, generics and :: casts are accepted and ignored.

Syntax

Supported: local, multiple assignment, compound assignment (+= -= *= /= //= %= ^= ..=), if/elseif/else, while, repeat/until, numeric and generic for (including for k, v in t generalized iteration and __iter), break, continue, functions, closures, varargs, methods (a:b()), string interpolation (`x = {x}`), if-then-else expressions, metatables (__index, __newindex, __call, operators, __tostring, __eq, __lt, __le, __len, __concat, __iter).

Not supported: goto, attributes, type function, nested interpolated strings.

Standard library

print warn error assert pcall xpcall tostring tonumber type typeof select next pairs ipairs unpack rawget rawset rawequal rawlen getmetatable setmetatable require time, plus string (incl. split), table, math (per-mod random), os (time clock date), utf8, bit32, task (wait spawn defer delay cancel), coroutine, Random and a debug.traceback stub. There is no game, workspace, script, Instance, getfenv/setfenv, loadstring or real debug library.

type(handle) is "userdata"; typeof(handle) is its class ("Unit", "Team", ...).

Tasks

main is already a thread. task.spawn(fn, ...) runs fn on a new thread right away, task.defer(fn, ...) on the next frame and task.delay(seconds, fn, ...) after a delay; all three return a thread for task.cancel. task.wait(seconds?) pauses the current thread. Loops that never call task.wait still cannot freeze the server: they are time-sliced (see limits).

task.spawn(function()
	while true do
		task.wait(5)
		print("five seconds passed")
	end
end)

local unit = Units.Died:Wait() -- pauses this thread until the next unit dies

Coroutines

coroutine: create resume yield status isyieldable running wrap close. A coroutine is a value of type "thread". It runs nested on the thread that resumes it and shares that thread's step budget, so a coroutine with an endless loop is time-sliced like any other code. task.wait and Signal:Wait() work inside a coroutine (the whole mod thread waits, then the coroutine continues). Limits: 2048 live coroutines per mod, 12 deep when coroutines resume coroutines. Inside hooks and callbacks that must return a value (the damage hook), coroutine.yield between a coroutine and its resumer works, but task.wait is still rejected. Stopping the mod closes every coroutine. A coroutine cannot yield from inside a metamethod or table.sort comparator.

local function range(n)
	return coroutine.wrap(function()
		for i = 1, n do
			coroutine.yield(i)
		end
	end)
end

for i in range(3) do
	print(i)
end

Random

Random.new(seed?) returns a generator (separate state from math.random; the same seed gives the same sequence): :NextNumber(min?, max?), :NextInteger(min, max), :NextUnitVector(), :Shuffle(array) (in place), :Clone().

debug

Only debug.traceback(message?). It returns the message plus the current script:line (no real stack is exposed), so xpcall(f, debug.traceback) works.

Multiple scripts

A mod is a set of named scripts; main runs first and others are loaded with require("name"). A module runs once and its return value is cached.

Interop

Using another mod's modules: a mod can be given an interop id (the box next to the mod name; letters, digits, _ and -, at most 32 characters, empty = shares nothing). While that mod runs, other mods can require("<interopId>:<script>").