If you know Lua
Luawe follows the design of Lua, and a Lua 5.4 programmer can read and write it at once. It is not Lua, though: it is a language of its own, written from nothing for the Wayfarer Engine, with a few things added, a few left out, and one or two that behave differently. This page is the whole list.
Added
const makes a variable that cannot be given a new value. Lua's own spelling works as well.
const SPEED = 4
local limit <const> = 10
print(SPEED, limit)It prints
4 10continue goes to a loop's next round.
Compound assignment: += -= *= /= //= %= ^= ..=.
Strings with values in them, between backticks: whatever is between { and } is an expression.
local name, lives = "Sky", 3
print(`{name} has {lives} lives, {lives * 100} points`)It prints
Sky has 3 lives, 300 points!= is another way to write ~=.
A for loop goes through a table directly: for key, value in t do. pairs and ipairs still exist.
Numbers can be written in base 2 (0b1010) and with _ between digits (1_000_000).
More in the libraries: string.split and string.trim; table.find, table.clone, table.clear and table.count; math.clamp, math.round, math.sign, math.lerp and math.map.
Waiting is built in. Every script is a task, wait(seconds) pauses it, and the task library starts more. Events (signal.new(), and the game's own) connect functions to things that happen. A coroutine can wait too.
Different
One kind of number. There are no integers apart from floats: every number is a 64-bit float, // rounds down and still gives a number, and math.type does not exist. Whole numbers print without a point, exactly, up to 2^53.
No arithmetic on strings. "10" + 1 is an error, not 11. Use tonumber. Joining with .. still accepts numbers.
Tables keep their order. pairs and the plain for give a table's keys in the order they were put in, always, on every computer.
Each script has its own globals. There is no _G and no _ENV. Scripts share through shared and scripts.<name>: see scripts working together.
Random numbers are not in math. The random library has the level's generator (random.number(), random.whole(1, 6), random.chance(0.25), random.pick(list), random.shuffle(list)) and generators of your own with a seed (random.new(7)), which give the same numbers on every computer.
collectgarbage() only tells how much memory is kept, in KB. There is nothing to tune.
A task cannot run for ever. One that does not wait for too long is stopped, and pcall does not catch that.
Left out
gotoand labels.- The bit operators (
&,|,~,<<,>>). io,os,package,require,load,loadstring,dofile: a script cannot reach files, the system or more code. This is on purpose, and it is what makes a downloaded level safe. See limits and safety.debug, exceptdebug.traceback.string.pack,string.unpack,string.dump;table.move;math.random,math.randomseed,math.tointeger,math.type,math.ult.- From
utf8, onlylen,sub,charandcodepointare there (subis new). - The metatable entries
__gc,__close,__mode,__pairs,__name, and the ones of the bit operators. Variables cannot be<close>.
The same
Everything else: local, functions and closures, ..., several results and several assignment, tables and their constructors, metatables (__index, __newindex, __call, __tostring, __len, __eq, __lt, __le, __concat, __unm and the arithmetic ones), pcall, error and assert, coroutines, the string library with its patterns and string.format, [[long strings]], --[[ long comments ]], the precedence of the operators, and that only false and nil are false.
Error messages follow Lua's wording (attempt to index a nil value (variable 'door')), so what you know about reading them still holds.