Skip to main content

Crate lua_std

Crate lua_std 

Source
Expand description

Reference for the Lua 5.5 standard library.

Lua is a dynamically typed language: values carry types, variables do not. Every value belongs to one of the basic types documented here — nil, boolean, number, string, table, function, userdata and thread.

The standard library provides a set of global functions (listed below), functions attached to the string and table types, and the math, os, io, coroutine and utf8 libraries.

The behaviour of operators on values can be customised through metatables — see the Metatables section below.

print("hello, world")

Lua and its logo are from Lua.org — logo © 1998 Lua.org, graphic design by Alexandre Nakonechnyj.

Modules§

coroutine
The coroutine library.
io
The input and output library.
math
The mathematical library.
os
The operating system library.
utf8
Basic support for UTF-8 encoding.

Structs§

any
Stands for a value of any type.
boolean
The type of the truth values true and false.
function
The type of Lua and C functions.
nil
The type of the absence of a value.
number
The type of numeric values.
string
The type of immutable sequences of bytes.
table
The type of associative arrays — the sole data-structuring mechanism in Lua.
thread
The type of independent threads of execution, used to implement coroutines.
userdata
The type of arbitrary C data.

Statics§

_G
A global variable that holds the global environment itself.
_VERSION
A global variable containing the running Lua version, as a string — currently "Lua 5.5".

Traits§

arithmetic
Metamethods controlling the arithmetic operators.
bitwise
Metamethods controlling the bitwise operators.
callable
Metamethod making a value callable.
comparison
Metamethods controlling the comparison operators.
concatenation
Metamethod controlling the concatenation operator.
indexing
Metamethods controlling indexed access.
length
Metamethod controlling the length operator.
lifecycle
Metamethods controlling the life cycle of a value.
tostring
Metamethods controlling string conversion.

Functions§

assert
Raises an error if the value of its argument v is false (i.e. nil or false); otherwise, returns all its arguments. On error, message is used as the error object; when absent, it defaults to "assertion failed!".
collectgarbage
A generic interface to the garbage collector. Performs different jobs according to opt: "collect" runs a full collection cycle (the default), "stop" and "restart" pause and resume the collector, "count" returns the total memory in use by Lua in kilobytes, "step" performs an incremental step, "isrunning" tells whether the collector is stopped, and "incremental" / "generational" select the collector mode.
dofile
Opens the named file and executes its contents as a Lua chunk. When called without arguments, executes the contents of the standard input. Returns all values returned by the chunk. In case of errors, dofile propagates the error to its caller: it does not run in protected mode.
error
Raises an error with message as the error object. This function never returns.
getmetatable
If object does not have a metatable, returns nil. Otherwise, if the metatable has a __metatable field, returns the associated value. Otherwise, returns the metatable of the given object.
inspectextended
Renders any value as a human-readable string. Extended library — feature extended. In the spirit of the widely used inspect.lua.
ipairs
Returns three values (an iterator function, t, and 0) so that the construction
load
Loads a chunk. If chunk is a string, the chunk is that string; if it is a function, load calls it repeatedly to get the chunk pieces. If there are no syntactic errors, returns the compiled chunk as a function; otherwise, returns nil plus the error message.
next
Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an index in this table. A call returns the next index of the table and its associated value; when called with nil as its second argument, returns an initial index and its associated value. When called with the last index, or with nil in an empty table, returns nil.
pairs
Returns three values (the next function, the table t, and nil) so that the construction
pcall
Calls the function f with the given arguments in protected mode: errors inside f are not propagated. Returns a status code (a boolean) followed, on success, by all results of the call, or, on failure, by the error object.
print
Receives any number of arguments and prints their values to the standard output, converting each to a string following the same rules as tostring(), separated by tabs and followed by a newline.
rawequal
Checks whether v1 is equal to v2, without invoking the __eq metamethod. Returns a boolean.
rawget
Gets the real value of t[index], without using the __index metamethod. t must be a table.
rawlen
Returns the length of the object v, which must be a table or a string, without invoking the __len metamethod.
rawset
Sets the real value of t[index] to value, without using the __newindex metamethod. t must be a table, index any value different from nil and NaN. Returns t.
require
Loads the given module. Starts by looking into the package.loaded table to determine whether modname is already loaded; if so, returns the stored value. Otherwise, finds a loader for the module by consulting the searchers in package.searchers, runs it, and caches its result in package.loaded[modname].
select
If index is a number, returns all arguments after argument number index; a negative number indexes from the end (−1 is the last argument). Otherwise, index must be the string "#", and select returns the total number of extra arguments it received.
setmetatable
Sets the metatable for the given table. If metatable is nil, removes the metatable of the table. If the original metatable has a __metatable field, raises an error.
tonumber
When called with no base, tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, returns that number; otherwise, returns nil.
tostring
Receives a value of any type and converts it to a string in a human-readable format.
type
Returns the type of its only argument, coded as a string. The possible results are "nil", "boolean", "number", "string", "table", "function", "userdata" and "thread".
xpcall
Like pcall, but sets msgh as a message handler: in case of error, msgh is called with the error object before the stack unwinds, and its return value becomes the error object returned by xpcall.