Skip to content

Globals

Global environment containing built-in constants, libraries, objects, and functions available in Traintastics Lua.

Constants

LUA_VERSION

Lua version and copyright, e.g. "Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio"

VERSION

Traintastic version, e.g. "0.1.0-master-380-e669a73b"

VERSION_MAJOR

Traintastic major version, e.g. 0

VERSION_MINOR

Traintastic minor version, e.g. 1

VERSION_PATCH

Traintastic patch level, e.g. 0

Libraries

class

Class library

enum

Enum library

log

Log library

math

Math library

set

Set library

string

String library

table

Table library

Objects

pv

The persistent variable table.

world

The global World object.

Functions

assert(condition [, message])

Raises an error if the given condition is false or nil; otherwise returns its argument(s).

Parameters:

  • condition
    A value that is tested for truth; if false or nil, the function errors.

  • message
    Optional error message (string) to use if the assertion fails.

ipairs(table)

Returns an iterator function for array-like tables, iterating in order of numerical indices starting from 1.

Parameters:

  • table
    A numerically indexed table.

Return values
Three values: an iterator function, the table itself, and the initial index (0).

next(table [, index])

Allows traversal of all key–value pairs in a table; returns the next key and its value.

Parameters:

  • table
    The table to iterate.

  • index
    The last key returned; iteration resumes after this key (optional, use nil to start).

Return values
The next key and its corresponding value in the table, or nil when no more entries.

pairs(table)

Returns an iterator function to traverse all key–value pairs in a table in no particular order.

Parameters:

  • table
    The table to iterate over.

Return values
Three values: an iterator function, the table itself, and an initial nil key.

tonumber(value [, base])

Tries to convert its argument to a number; returns the number or nil if conversion fails.

Parameters:

  • value
    A string or number to convert.

  • base
    An optional base (2–36) to interpret the string in (default is base 10).

Return values
The converted number, or nil if the input is not a valid numeric representation.

tostring(value)

Returns a string representation of its argument.

Parameters:

  • value
    The value to convert to string.

Return values
A string representation of the given value.

type(value)

Returns the type name of its argument as a string (such as 'nil', 'number', 'string', 'boolean', 'table', 'function', etc.).

Parameters:

  • value
    The value whose type is to be returned.

Return values
A string describing the type of the input value, or 'nil' if the value is nil.