This page lists all members of the global namespace.
Related help topics
![]() |
Issues an error and aborts the program when the value of its first argument is false( i.e false or nil).
|
v : | any |
Issues an error when this value is false. |
message : | string? |
The error message to display. If absent, this defaults to "assertion failed". The ? notation indicates that this type is optional: there may be zero or one instances of it. |
This function does not return any values. |
Otherwise, it returns all the arguments.
options : | string? |
The various options that can be set for the garbage collector. The possible options are:
The ? notation indicates that this type is optional: there may be zero or one instances of it. |
arg : | any? |
The values passed depending on the option set. Many options do not need arguments to be passed. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
any? |
The result of the function performed according to the options set. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
This performs different functions according to the specified options.
filename : | string? |
The name of the file to execute. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
any? |
Returns the result of the execution. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
When called without arguments, dofile executes the contents of the standard input (stdin). Returns all values returned by the chunk. In case of errors, dofile propagates the error to its caller (i.e, dofile does not run in protected mode).
message : | string |
The error messsage to display. |
level : | integer? |
Specifies the error position. With level 1 (the 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 a level 0 avoids the addition of error position information to the message. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
This function does not return any values. |
Usually, error adds some information about the error position at the beginning of the message.
f : | fun(any*:any*) |
Specifies either a Lua function or a number that specifies the function at that stack level; Level 1 is the function calling getfenv. The default for f is 1. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
table |
The current environment or global environment if f is 0, or if the passed function is not a Lua function. |
If the given function is not a Lua function, or if f is 0, getfenv returns the global environment.
object : | table |
The object whose metatable is retrieved. |
table? |
Returns the metatable of the object, if the object's metatable has a "__metatable" field, then the associated value is returned. Returns nil if the given object does not have a metatable. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
t : | table |
The table to be iterated. |
fun(any:any?) |
The iterator function. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
table |
The table with the arguments set. |
integer |
The value 0. |
Other related reference items
func : | fun(any:any) |
The loader function. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
chunkname : | string? |
The chunk to load. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
fun(any:any) |
Returns the compiled chunk, if the operation was successful. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
string |
The error message for failure. |
Each call to func must return a string that concatenates with previous results. A return of an empty string, nil, or no value signals the end of the chunk. If successful, returns the compiled chunk as a function; otherwise, returns nil plus the error message. The environment of the returned function is the global environment. chunkname is used as the chunk name for error messages and debug information. When absent, it defaults to "=(load)".
filename : | string? |
The name of the file to load. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
fun(any:any) |
Returns the compiled chunk, if the operation was successful. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
string |
The error message for failure. |
Does not execute it. This function is similar to load, but gets the chunk from filename or from the standard input, if no file name is given.
stringarg : | string |
The string to load. |
chunkname : | string? |
The chunk to load. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
fun(any:any) |
Returns the compiled chunk, if the operation was successful. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
string |
The error message for failure. |
Does not execute it. This function is similar to load, but gets the chunk from the given string. To load and run a given string, use the idiom assert(loadstring(s))() When absent, chunkname defaults to the given string.
Other related reference items
name : | string |
The name for the module. |
options : | fun(any*:any*)? |
The options for the module. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
table |
The created module. |
If there is a table in package.loaded[name], this table is the module. Otherwise, if there is a global table t with the given name, this table is the module. Otherwise creates a new table t and sets it as the value of the global name and the value of package.loaded[name]. This function also initializes t._NAME with the given name, t._M with the module (t itself), and t._PACKAGE with the package name (the full module name minus last component; see below). Finally, module sets t as the new environment of the current function and the new value of package.loaded[name], so that require returns t.
If name is a compound name (that is, one with components separated by dots), module creates (or reuses, if they already exist) tables for each component. For instance, if name is a.b.c, then module stores the module table in field c of field b of global a.
This function can receive optional options after the module name, where each option is a function to be applied over the module.
control : | boolean |
Controls if the returned userdata should have a metatable or not. |
data1 : | userdata |
Needs to be a proxy. The metatable will be shared between the proxies. |
userdata |
A zero-length user-data object. |
newproxy is a experimental, undocumented and unsupported function in the Lua base library. It can be used to create a zero-length userdata, with a optional proxy.
t : | table |
The table which is iterated over. |
index : | any? |
An index to the table t. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
any? |
The next index of the table. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
any? |
The value associated with the returned index. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
When called with nil as its second argument, next returns an initial index and its associated value. When called with the last index, or with nil in an empty table, next returns nil. If the second argument is absent, then it is interpreted as nil. In particular, next(t) can be used to check whether a table is empty.
The order in which the indices are enumerated is not specified, even for numeric indices. (To traverse a table in numeric order, use a numerical for loop or the ipairs function.) The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may clear existing fields.
Other related reference items
![]() |
Returns three values: the next function, the table t, and nil, so that the construction
for k,v in pairs(t) do body end
will iterate over the all key-value pairs of table t.
|
t : | table |
A table to iterate over for the key-value pairs. |
fun(any*:any*) |
The iterator function. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
table |
The table t with the arguments set. |
See function next for the caveats of modifying the table during its traversal.
f : | fun(any*:any*) |
A function that is called in protected mode. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
arg1 : | any* |
The arguments that is passed to the function. The * notation indicates that there may be zero or more instances of the specified type. |
boolean |
A status code reporting the status of the function call. If true, the call has succeeded without errors. In such case, pcall also returns all results from the call, after this first result. In case of any error, pcall returns false and the error message. |
any* |
The result of the function call if successful or an error message if function call resulted in a failure. The * notation indicates that there may be zero or more instances of the specified type. |
This means that any error inside f is not propagated; instead, pcall catches the error and returns a status code (a boolean).
Other related reference items
![]() |
Receives any number of arguments, and prints their values to stdout, using the tostring function to convert them to strings.
|
arg1 : | any* |
The text to output. The * notation indicates that there may be zero or more instances of the specified type. |
This function does not return any values. |
print is not intended for formatted output, but only as a quick way to show a value, typically for debugging. For formatted output, use string.format.
v1 : | any |
The first value to compare. |
v2 : | any |
The second value to compare. |
boolean |
Returns true if the values are equal and false otherwise. |
t : | table |
The table whose values are retrieved. |
index : | any |
The index to the specified table. |
any? |
The value corresponding to the specified index in the table. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
t : | table |
The table to modify. |
index : | any |
The index to the specified table, any value different from nil. |
value : | any? |
The value (any Lua value) to set for the specified index in the table. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
This function does not return any values. |
modname : | string |
The name of the module. |
any |
The value returned by the loader or an error meassage if a loader is not found. |
The function starts by looking into the package.loaded table to determine whether modname is already loaded. If it is, then require returns the value stored at package.loaded[modname]. Otherwise, it tries to find a loader for the module.
To find a loader, require is guided by the package.loaders array. By changing this array, we can change how require looks for a module. The following explanation is based on the default configuration for package.loaders.
First require queries package.preload[modname]. If it has a value, this value (which should be a function) is the loader. Otherwise require searches for a Lua loader using the path stored in package.path. If that also fails, it searches for a C loader using the path stored in package.cpath. If that also fails, it tries an all-in-one loader (see package.loaders).
Once a loader is found, require calls the loader with a single argument, modname. If the loader returns any value, require assigns the returned value to package.loaded[modname]. If the loader returns no value and has not assigned any value to package.loaded[modname], then require assigns true to this entry. In any case, require returns the final value of package.loaded[modname].
If there is any error loading or running the module, or if it cannot find any loader for the module, then require signals an error.
Other related reference items
index : | integer |
A number or string following which next arguments are returned. |
any* |
The arguments following the index. The * notation indicates that there may be zero or more instances of the specified type. |
If index is a number, this returns all arguments after index. Otherwise index is a string "#", and this function returns the total number of extra arguments it received.
f : | fun(any*:any*) |
A Lua function or a number that specifies the function at that stack level. Level 1 means that this is the current function calling setfenv. As a special case, if f is 0, setfenv changes the environment of the running thread, in which case nothing is returned by setfenv. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
t : | table |
The table with the new environment. |
This function does not return any values. |
This function returns the same function that is passed as the argument.
![]() |
Sets the metatable for the specified table.(You cannot change the metatable of other types from Lua, only from C.)
|
t : | table |
The table whose metatable is set. |
metatable : | table |
The table to set as the metatable for the given table. If nil, removes the metatable of the table t. If the original metatable has a "__metatable" field, raises an error. |
table |
The table with the metatable set. |
e : | any |
The argument to convert to a number. |
base : | integer |
An argument that specifies the base to interpret the numeral. The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. In base 10 (the default), the number can have a decimal part, as well as an optional exponent part. In other bases, only unsigned integers are accepted. |
number |
The converted number. |
If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, returns nil.
e : | any |
The argument to convert to a string. If the metatable of e has a "__tostring" field, then tostring calls the corresponding value with e as argument, and uses the result of the call as its result. |
string |
The converted string. |
For complete control of how numbers are converted, use string.format.
Other related reference items
v : | any |
The argument whose type is returned. |
string |
The type as a string, possible values are: "nil", "number", "string", "boolean", "table", "function", "thread", and "userdata". |
list : | table |
The table whose elements are retrieved. |
i : | integer? |
The index of the table element at which the function will begin unpacking values. Default value of 1. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
j : | integer? |
The index of the table element at which the function will stop unpacking values. Default value is the length of the table, as defined by the length operator #. The ? notation indicates that this type is optional: there may be zero or one instances of it. |
any* |
The unpacked elements of the table. The * notation indicates that there may be zero or more instances of the specified type. |
This function is equivalent to
return list[i], list[i+1], ..., list[j]
except that the above code can be written only for a fixed number of elements.
![]() |
This function is similar to pcall, except that a new error handler can be set.
|
f : | fun(any*:any*) |
A function that is called in protected mode. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
err : | fun(any:any) |
The error handler. The fun(...) notation indicates that this is a function that accepts parameters of the types shown to the left of the colon :, and that returns the types shown to the right of the colon.. |
boolean |
A status code reporting the status of the function call. If true, the call has succeeded without errors. In such case, xpcall also returns all results from the call, after this first result. In case of any error, xpcall returns false and the error message. |
any* |
The result of the function call if successful or an error message if function call resulted in a failure. The * notation indicates that there may be zero or more instances of the specified type. |
xpcall calls function f in protected mode, using err as the error handler. Any error inside f is not propagated; instead, xpcall catches the error, calls the err function with the original error object, and returns a status code.