Global Lua standard library functions and miscellaneous extensions to them.
assert(expression, message)
If the first argument is false or nil, an error is thrown with the second argument as the message. Otherwise, all arguments are returned.
collectgarbage(opt, arg)
Performs a garbage-collection operation. The first argument specifies the operation to perform
Modifying garbage collector settings is generally not recommended unless you know what you’re doing.
defer(callback)
Registers a function to be called at lua shutdown/reload, equivalent to
client.set_event_callback("shutdown", callback)
error(message, level)
Terminates the last protected function called and returns the message. The level argument specifies where the error function gets its information about the error position. If the function containing the error is not called in a protected function, then the script which called the function will terminate. The error function itself never returns and acts like a script error. If level is 1 (default), the error position is where the error function was called. Level 2 points the error to where the function that called error was called; and so on. Passing level 0 avoids the addition of error position information to the message.
getfenv(stack)
Returns the environment of the function or stack level passed to it.
getmetatable(table)
Returns the metatable of the given table if present, otherwise it returns
nil. If it does have a metatable, and the metatable has a__metatablemetamethod, it returns that value instead.
ipairs(table)
Returns three values: an iterator function, the table
table, and 0. Each time the iterator function is called, it returns the next numerical index-value in the table.
When used in a generic for-in-loop, the return values can be used to iterate over each numerical index in the table.
load(chunk, chunk_name, mode, env)
Loads a chunk of Lua source code from a string or a reader function.
next(table, key)
Returns the first key/value pair in the table. If a key argument was specified then returns the next element in the table based on the key provided.
pairs(table)
Returns three values: the next function, the
table, andnil. Each time the next function is called, it returns a key-value pair from the table.
pcall(func, arg1, ...)
Calls the function
funcwith the given arguments in “protected mode”. This means that any error insidefuncwill not propagate; instead,pcallcatches the error and returns a status code and the error message. If the call succeeds without errors, it returns true followed by any values returned byfunc. If there is an error, it returns false followed by the error message.
print(...)
Logs a message to the console. Equivalent to
client.logwith the “Console” type.
printf(format, ...)
Logs a formatted message to the console. It accepts the same parameters as
string.format
rawequal(v1, v2)
Checks whether
v1andv2are equal without invoking any metamod.
rawget(table, key)
Gets the raw value of a table field, without invoking the
__indexmetamethod.
rawlen(table)
Gets the raw length of a table, without invoking the
__lenmetamethod.
rawset(table, key, value)
Sets the raw value of a table field, without invoking the
__newindexmetamethod.
readfile(filename)
Reads the contents of a file and returns it as a string, or
nilif the file doesn’t exist.
require(module_name)
Loads a Lua module.
select(index, ...)
Returns all the arguments passed to it after the first index. If the first index is
"#", it returns the total number of arguments it received (includingnil).
setfenv(stack, table)
Sets the environment of the function to the given table.
setmetatable(table, metatable)
Sets the metatable for the given
table. Ifmetatableisnil, the metatable of it is removed. This function returns the tabletblwhich was passed to it. Iftblalready has a metatable with the__metatablemetamethod, calling this ontablecauses an error.
tonumber(value, base)
Tries to convert
valueto a number. If the argument is invalid, it returnsnil.
tostring(value)
Receives an argument of any type and converts it to a string. For complete control of how numbers are converted, use
string.formatinstead.
toticks(seconds)
Converts seconds to ticks.
totime(ticks)
Converts ticks to seconds.
type(value)
Returns the type of the given value as a string.
unpack(table, i, j)
Returns the items with numeric keys from the given
table, fromitoj.
writefile(filename, content)
Writes the given content to a file, overwriting it or creating it if it doesn’t exist.
xpcall(func, err_handler, arg1, ...)
Calls
funcin “protected mode”. This means that any error insidefuncis not propagated; instead,xpcallcatches the error, calls the “error handler” function passed to it, then returns back to the caller. If the first return value is true, the function call succeeded with no errors and the other return values will be the return values from the function. If the first return value is false, the second one will be the error message.