Skip to Content

Runtime and conventions

LuaJIT 2.1 runtime, available libraries, threading, signature notation and how API arguments are converted.


Scripts use LuaJIT 2.1, which implements Lua 5.1 with LuaJIT extensions, including 64-bit literals such as 1ULL and -1LL.

All standard libraries are available, including io, os, debug and package. LuaJIT modules are available through require, including bit, jit, ffi and string.buffer. ffi is not a global. jit.util is withheld: require('jit.util'), package.loaded['jit.util'], package.preload['jit.util'] and jit.util raise jit.util is not available to scripts; the rest of jit (jit.on, jit.off, jit.flush, jit.status, jit.opt, jit.version) is unchanged.

Security: scripts are not sandboxed. They have access to the filesystem, native libraries and the game process. Run only trusted scripts.

Each script has a separate Lua state. All API callbacks execute on the game's main thread, not on the render or input thread.

Signature notation

  • arg? denotes an optional argument.
  • Multiple return values are separated by commas. For example, nil, reason returns two values.
  • integer denotes a whole numeric value unless a cdata type is specified.
  • vector, vector2d, vector4d, angle and color are FFI value types, the only value types.
  • Object methods use : unless documented otherwise. Namespaces use ..

Argument conversion

Unless an API entry specifies stricter validation, bound functions use these conversions for a required parameter:

ParameterAccepted values
StringA string or a number converted to text. Any other value is read as "", except where a parameter takes a C string (memory.pattern, memory.interface, memory.export, engine.get_netvar_offset): there anything but a string or number raises stack index N, expected string, received <type>. Functions implemented directly in C raise Lua's bad argument #N error instead.
NumberA number or a numeric string, rounded where an integer is required. Other types are read as 0; functions implemented directly in C raise bad argument #N.
BooleanLua truthiness: only false and nil are false, so 0 and "" are true.

An optional parameter (arg?) of a string, number or boolean type is stricter about the type and lenient about the outcome: a value of another type (a numeric string for a number, a number for a boolean, a fractional number for an integer) reads as if the argument were omitted, so the default applies, and nothing is raised. A function with several forms (entitylist.list, entitylist.pawns, trace.line, ray_t, trace_filter_t) picks the form whose parameter types match exactly; when none does it raises sol: no matching function call takes this number of arguments and the specified types. Value parameters (vectors, angles, colours) are read the same way everywhere:

ParameterAccepted values
VectorThe matching FFI value (vector, vector2d or vector4d), a pointer to it (vector*), a reference such as an element of a vector[n] array, or a table with named ({x=, y=, z=}) or positional ({1, 2, 3}) components. Anything else raises expected vector, vector* or {x, y, z} (or the vector2d / vector4d analogue); functions implemented directly in C raise vector, vector* or {x, y, z} expected.
AngleAs for vectors; tables may also use pitch, yaw and roll.
Colourcolor, a pointer or reference to it, or a table with named ({r=, g=, b=, a=}) or positional channels. Missing alpha defaults to 255; channels are clamped to 0..255.
64-bit maskA non-negative whole number below 2^64, or int64_t / uint64_t cdata. Signed cdata is interpreted by its bit pattern, so -1LL sets all bits.

These conversions apply to API parameters, not necessarily to constructors. In particular, color({255, 0, 0}) has alpha 0, while color(255, 0, 0) has alpha 255.

On this page