Skip to main content

Global Lua Namespace

Global functions.

Functions

class

class( base )

Creates a new class object.

Arguments:
  • base [ class ]: The base class to inherit from. Optional.
Internal code of the class function
function class(super)

local klass = {}

-- Copy members from super.
if super then
for k,v in pairs(super) do
klass[k] = v
end
end

local meta = {}

-- Emulate constructor syntax.
-- Triggers when a value is called like a function.
meta.__call = function(self, ...)
local instance = setmetatable({}, self)

return instance
end

-- Emulate classes using prototyping.
setmetatable(klass, meta)
klass.__index = klass

return klass
end

dofile

dofile( filename )

Opens the named file and executes its contents as a Lua chunk.
In case of errors, dofile propagates the error to its caller.

Arguments:
  • filename [ string ]: The name/path of the lua file to be loaded.

print

print( ... )

Prints data to the console. This is useful for debugging.

note

If the game is running with the -dev launch flag, any output will be added to the game logs.

Arguments:
  • ... [ any ]: Any number of arguments to be printed.

type

type( object )

Returns the type of an object as a string.
This includes standard Lua types and userdata types specific to this API.

Arguments:
  • object [ any ]: The object to check.
Returns:
  • [ string ]: The type of the object.

Other Libraries

Listed below are all available default Lua libraries.

For documentation of these libraries, see the Lua Reference Manual.

string

string.byte
string.char
string.find
string.format
string.gmatch
string.gsub
string.len
string.lower
string.match
string.rep
string.reverse
string.sub
string.upper

table

table.insert
table.maxn
table.remove
table.sort
table.concat

math

math.abs
math.acos
math.asin
math.atan
math.atan2
math.ceil
math.cos
math.cosh
math.deg
math.exp
math.floor
math.fmod
math.frexp
math.huge
math.ldexp
math.log
math.log10
math.max
math.min
math.modf
math.pi
math.pow
math.rad
math.random
math.sin
math.sinh
math.sqrt
math.tan
math.tanh
math.randomseed

bit

bit.tobit
bit.tohex
bit.bnot
bit.band
bit.bor
bit.bxor
bit.lshift
bit.rshift
bit.arshift
bit.rol
bit.ror
bit.bswap

os

os.clock
os.difftime
os.time

other

assert
error
ipairs
next
pairs
pcall
select
tonumber
tostring
unpack
_VERSION
xpcall
gcinfo