Version: alpha
FUNCTION | |
---|---|
assert() | asserts that condition is not nil and not false |
collectgarbage() | collects garbage |
dofile() | executes a Lua file |
error() | raises an error message |
getfenv() | returns the current environment table |
getmetatable() | returns the metatable for the object |
ipairs() | iterates over a numerically keyed table |
load() | loads a chunk by calling a function repeatedly |
loadfile() | loads a Lua file and parses it |
loadstring() | compiles a string of Lua code |
next() | returns next key / value pair in a table |
pairs() | traverse all items in a table |
pcall() | calls a function in protected mode |
print() | prints its arguments |
rawequal() | compares two values for equality without invoking metamethods |
rawget() | gets the value of a table item without invoking metamethods |
rawset() | sets the value of a table item without invoking metamethods |
select() | returns items in a list |
setfenv() | sets a function's environment |
setmetatable() | sets the metatable for a table |
tonumber() | converts a string (of the given base) to a number |
tostring() | converts its argument to a string |
type() | returns the type of a variable |
unpack() | unpacks a table into individual items |
xpcall() | calls a function with a custom error handler |
module() | creates a Lua module |
require() | loads a module |
CONSTANT | |
---|---|
_G | global variable that holds the global environment |
_VERSION | global variable containing the running Lua version |
assert(v,[message])
PARAMETERS
v |
|
[message] |
collectgarbage([opt],[arg])
PARAMETERS
[opt] |
|
[arg] |
dofile([filename])
PARAMETERS
[filename] |
error(message,[level])
PARAMETERS
message |
|
[level] |
getfenv([f])
PARAMETERS
[f] |
getmetatable(object)
"__metatable"
field,
returns the associated value.
Otherwise, returns the metatable of the given object.
PARAMETERS
object |
ipairs(t)
for i,v in ipairs(t) do body end
1,t[1]
), (2,t[2]
), ...,
up to the first integer key absent from the table.
PARAMETERS
t |
load(func,[chunkname])
PARAMETERS
func |
|
[chunkname] |
loadfile([filename])
PARAMETERS
[filename] |
loadstring(string,[chunkname])
assert(loadstring(s))()
PARAMETERS
string |
|
[chunkname] |
next(table,[index])
next(t)
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 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.
PARAMETERS
table |
|
[index] |
pairs(t)
for k,v in pairs(t) do body end
PARAMETERS
t |
pcall(f,arg1,...)
f
is not propagated;
instead, pcall catches the error
and returns a status code.
Its first result is the status code (a boolean),
which is true if the call succeeds 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 plus the error message.
PARAMETERS
f |
|
arg1 |
|
... |
print(...)
PARAMETERS
... |
rawequal(v1,v2)
PARAMETERS
v1 |
|
v2 |
rawget(table,index)
table[index]
,
without invoking any metamethod.
table must be a table;
index may be any value.
PARAMETERS
table |
|
index |
rawset(table,index,value)
table[index]
to value,
without invoking any metamethod.
table must be a table,
index any value different from nil,
and value any Lua value.
This function returns table.
PARAMETERS
table |
|
index |
|
value |
select(index,...)
"#"
,
and select returns the total number of extra arguments it received.
PARAMETERS
index |
|
... |
setfenv(f,table)
PARAMETERS
f |
|
table |
setmetatable(table,metatable)
"__metatable"
field,
raises an error.
This function returns table.
PARAMETERS
table |
|
metatable |
tonumber(e,[base])
PARAMETERS
e |
|
[base] |
tostring(e)
"__tostring"
field,
then tostring calls the corresponding value
with e as argument,
and uses the result of the call as its result.
PARAMETERS
e |
type(v)
PARAMETERS
v |
unpack(list,[i],[j])
return list[i], list[i+1], ..., list[j]
PARAMETERS
list |
|
[i] |
|
[j] |
xpcall(f,err)
PARAMETERS
f |
|
err |
module(name,[...])
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.
PARAMETERS
name |
|
[...] |
require(modname)
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 .
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.
PARAMETERS
modname |
global variable that holds the global environment
A global variable (not a function) that
holds the global environment (that is, _G._G = _G
).
Lua itself does not use this variable;
changing its value does not affect any environment,
nor vice-versa.
(Use setfenv to change environments.)
global variable containing the running Lua version
A global variable (not a function) that holds a string containing the current interpreter version. The current contents of this variable is "Lua 5.1".