aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc/luaref.txt
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/doc/luaref.txt')
-rw-r--r--runtime/doc/luaref.txt606
1 files changed, 299 insertions, 307 deletions
diff --git a/runtime/doc/luaref.txt b/runtime/doc/luaref.txt
index aafdd5c43e..467b5760cf 100644
--- a/runtime/doc/luaref.txt
+++ b/runtime/doc/luaref.txt
@@ -1,5 +1,5 @@
*luaref.txt* Nvim
- *luaref* *Lua-Reference*
+ *luaref*
LUA REFERENCE MANUAL
@@ -16,14 +16,14 @@
Copyright (c) 2006 Lua.org, PUC-Rio.
- See |luaref-doc| for information on this manual.
- See |luaref-copyright| for copyright and licenses.
+ See |lua-ref-doc| for information on this manual.
+ See |lua-ref-copyright| for copyright and licenses.
Type |gO| to see the table of contents.
==============================================================================
-1 INTRODUCTION *luaref-intro*
+1 INTRODUCTION *luaref-intro*
Lua is an extension programming language designed to support general
procedural programming with data description facilities. It also offers good
@@ -47,13 +47,13 @@ Lua's official web site, www.lua.org.
Like any other reference manual, this document is dry in places. For a
discussion of the decisions behind the design of Lua, see references at
-|luaref-bibliography|. For a detailed introduction to programming in Lua, see
+|lua-ref-bibliography|. For a detailed introduction to programming in Lua, see
Roberto's book, Programming in Lua.
Lua means "moon" in Portuguese and is pronounced LOO-ah.
==============================================================================
-2 THE LANGUAGE *luaref-language*
+2 THE LANGUAGE *lua-language*
This section describes the lexis, the syntax, and the semantics of Lua. In
other words, this section describes which tokens are valid, how they can be
@@ -63,9 +63,9 @@ The language constructs will be explained using the usual extended BNF
notation, in which `{ a }` means 0 or more `a`'s, and `[ a ]` means an optional `a`.
==============================================================================
-2.1 Lexical Conventions *luaref-langLexConv*
+2.1 Lexical Conventions *lua-lexical*
- *luaref-names* *luaref-identifiers*
+ *lua-names* *lua-identifiers*
Names (also called identifiers) in Lua can be any string of letters, digits,
and underscores, not beginning with a digit. This coincides with the
definition of identifiers in most languages. (The definition of letter depends
@@ -92,7 +92,7 @@ The following strings denote other tokens:
( ) { } [ ]
; : , . .. ...
<
- *luaref-literal*
+ *lua-literal*
Literal strings can be delimited by matching single or double quotes, and can
contain the following C-like escape sequences:
@@ -146,14 +146,14 @@ coded as 49), the five literals below denote the same string:
alo
123"]==]
<
- *luaref-numconstant*
+ *lua-numconstant*
A numerical constant may be written with an optional decimal part and an
optional decimal exponent. Lua also accepts integer hexadecimal constants, by
prefixing them with `0x`. Examples of valid numerical constants are
>
3 3.0 3.1416 314.16e-2 0.31416E1 0xff 0x56
<
- *luaref-comment*
+ *lua-comment*
A comment starts with a double hyphen (`--`) anywhere outside a string. If the
text immediately after `--` is not an opening long bracket, the comment is a
short comment, which runs until the end of the line. Otherwise, it is a long
@@ -161,7 +161,7 @@ comment, which runs until the corresponding closing long bracket. Long
comments are frequently used to disable code temporarily.
==============================================================================
-2.2 Values and Types *luaref-langValTypes*
+2.2 Values and Types *lua-values*
Lua is a dynamically typed language. This means that variables do not have
types; only values do. There are no type definitions in the language. All
@@ -171,9 +171,9 @@ All values in Lua are first-class values. This means that all values can be
stored in variables, passed as arguments to other functions, and returned as
results.
- *luaref-types* *luaref-nil*
- *luaref-true* *luaref-false*
- *luaref-number* *luaref-string*
+ *lua-types* *lua-nil*
+ *lua-true* *lua-false*
+ *lua-number* *lua-string*
There are eight basic types in Lua: `nil`, `boolean`, `number`, `string`,
`function`, `userdata`, `thread`, and `table`. Nil is the type of the value
`nil`, whose main property is to be different from any other value; it usually
@@ -184,27 +184,27 @@ numbers. (It is easy to build Lua interpreters that use other internal
representations for numbers, such as single-precision float or long integers;
see file `luaconf.h`.) String represents arrays of characters. Lua is 8-bit
clean: strings may contain any 8-bit character, including embedded zeros
-(`\0`) (see |luaref-literal|).
+(`\0`) (see |lua-literal|).
Lua can call (and manipulate) functions written in Lua and functions written
-in C (see |luaref-langFuncCalls|).
+in C (see |lua-function|).
- *luaref-userdatatype*
+ *lua-userdatatype*
The type userdata is provided to allow arbitrary C data to be stored in Lua
variables. This type corresponds to a block of raw memory and has no
pre-defined operations in Lua, except assignment and identity test. However,
by using metatables, the programmer can define operations for userdata values
-(see |luaref-langMetatables|). Userdata values cannot be created or modified
-in Lua, only through the C API. This guarantees the integrity of data owned by
-the host program.
+(see |lua-metatable|). Userdata values cannot be created or modified in Lua,
+only through the C API. This guarantees the integrity of data owned by the
+host program.
- *luaref-thread*
+ *lua-thread*
The type `thread` represents independent threads of execution and it is used to
-implement coroutines (see |luaref-langCoro|). Do not confuse Lua threads with
+implement coroutines (see |lua-coroutine|). Do not confuse Lua threads with
operating-system threads. Lua supports coroutines on all systems, even those
that do not support threads.
- *luaref-table*
+ *lua-table*
The type `table` implements associative arrays, that is, arrays that can be
indexed not only with numbers, but with any value (except `nil`). Tables can
be heterogeneous; that is, they can contain values of all types (except
@@ -213,11 +213,11 @@ used to represent ordinary arrays, symbol tables, sets, records, graphs,
trees, etc. To represent records, Lua uses the field name as an index. The
language supports this representation by providing `a.name` as syntactic sugar
for `a["name"]`. There are several convenient ways to create tables in Lua
-(see |luaref-langTableConst|).
+(see |lua-tableconstructor|).
Like indices, the value of a table field can be of any type (except `nil`). In
particular, because functions are first-class values, table fields may contain
-functions. Thus tables may also carry methods (see |luaref-langFuncDefs|).
+functions. Thus tables may also carry methods (see |lua-function-define|).
Tables, functions, threads and (full) userdata values are objects: variables
do not actually contain these values, only references to them. Assignment,
@@ -225,10 +225,10 @@ parameter passing, and function returns always manipulate references to such
values; these operations do not imply any kind of copy.
The library function `type` returns a string describing the type of a given
-value (see |luaref-type()|).
+value (see |lua-type()|).
------------------------------------------------------------------------------
-2.2.1 Coercion *luaref-langCoercion*
+2.2.1 Coercion *lua-coercion*
Lua provides automatic conversion between string and number values at run
time. Any arithmetic operation applied to a string tries to convert that
@@ -239,7 +239,7 @@ converted to strings, use the `format` function from the string library (see
|string.format()|).
==============================================================================
-2.3 Variables *luaref-langVariables*
+2.3 Variables *lua-variables*
Variables are places that store values. There are three kinds of variables in
Lua: global variables, local variables, and table fields.
@@ -249,12 +249,12 @@ function's formal parameter, which is a particular form of local variable):
>
var ::= Name
<
-Name denotes identifiers, as defined in |luaref-langLexConv|.
+Name denotes identifiers, as defined in |lua-lexical|.
Any variable is assumed to be global unless explicitly declared as a local
-(see |luaref-langLocalDec|). Local variables are lexically scoped: local
+(see |lua-local|). Local variables are lexically scoped: local
variables can be freely accessed by functions defined inside their scope (see
-|luaref-langVisibRules|).
+|lua-visibility|).
Before the first assignment to a variable, its value is `nil`.
@@ -265,21 +265,21 @@ Square brackets are used to index a table:
The first expression (`prefixexp`) should result in a table value; the second
expression (`exp`) identifies a specific entry inside that table. The
expression denoting the table to be indexed has a restricted syntax; see
-|luaref-langExpressions| for details.
+|lua-expressions| for details.
The syntax `var.NAME` is just syntactic sugar for `var["NAME"]` :
>
var ::= prefixexp . Name
<
All global variables live as fields in ordinary Lua tables, called environment
-tables or simply environments (see |luaref-langEnvironments|). Each function
+tables or simply environments (see |lua-environments|). Each function
has its own reference to an environment, so that all global variables in this
function will refer to this environment table. When a function is created, it
inherits the environment from the function that created it. To get the
environment table of a Lua function, you call `getfenv` (see
-|lua_getfenv()|). To replace it, you call `setfenv` (see |luaref-setfenv()|).
+|lua_getfenv()|). To replace it, you call `setfenv` (see |setfenv()|).
(You can only manipulate the environment of C functions through the debug
-library; see |luaref-libDebug|.)
+library; see |lua-lib-debug|.)
An access to a global variable `x` is equivalent to `_env.x`, which in turn is
equivalent to
@@ -291,19 +291,19 @@ not defined in Lua. We use it here only for explanatory purposes.)
The meaning of accesses to global variables and table fields can be changed
via metatables. An access to an indexed variable `t[i]` is equivalent to a
-call `gettable_event(t,i)`. (See |luaref-langMetatables| for a complete
-description of the `gettable_event` function. This function is not defined or
-callable in Lua. We use it here only for explanatory purposes.)
+call `gettable_event(t,i)`. (See |lua-metatable| for a complete description of
+the `gettable_event` function. This function is not defined or callable in
+Lua. We use it here only for explanatory purposes.)
==============================================================================
-2.4 Statements *luaref-langStats*
+2.4 Statements *lua-statement*
Lua supports an almost conventional set of statements, similar to those in
Pascal or C. This set includes assignment, control structures, function
calls, and variable declarations.
------------------------------------------------------------------------------
-2.4.1 Chunks *luaref-chunk* *luaref-langChunks*
+2.4.1 Chunks *lua-chunk*
The unit of execution of Lua is called a chunk. A chunk is simply a sequence
of statements, which are executed sequentially. Each statement can be
@@ -314,7 +314,7 @@ optionally followed by a semicolon:
There are no empty statements and thus `;;` is not legal.
Lua handles a chunk as the body of an anonymous function with a variable
-number of arguments (see |luaref-langFuncDefs|). As such, chunks can define
+number of arguments (see |lua-function-define|). As such, chunks can define
local variables, receive arguments, and return values.
A chunk may be stored in a file or in a string inside the host program. When a
@@ -327,24 +327,24 @@ details. Programs in source and compiled forms are interchangeable; Lua
automatically detects the file type and acts accordingly.
------------------------------------------------------------------------------
-2.4.2 Blocks *luaref-block* *luaref-langBlocks*
+2.4.2 Blocks *lua-block*
A block is a list of statements; syntactically, a block is the same as a
chunk:
>
block ::= chunk
<
- *luaref-do* *luaref-end*
+ *lua-do* *lua-end*
A block may be explicitly delimited to produce a single statement:
>
stat ::= do block end
<
Explicit blocks are useful to control the scope of variable declarations.
Explicit blocks are also sometimes used to add a `return` or `break` statement
-in the middle of another block (see |luaref-langContStructs|).
+in the middle of another block (see |lua-control|).
------------------------------------------------------------------------------
-2.4.3 Assignment *luaref-langAssign*
+2.4.3 Assignment *lua-assign*
Lua allows multiple assignment. Therefore, the syntax for assignment defines a
list of variables on the left side and a list of expressions on the right
@@ -354,7 +354,7 @@ side. The elements in both lists are separated by commas:
varlist1 ::= var { , var }
explist1 ::= exp { , exp }
<
-Expressions are discussed in |luaref-langExpressions|.
+Expressions are discussed in |lua-expressions|.
Before the assignment, the list of values is adjusted to the length of the
list of variables. If there are more values than needed, the excess values are
@@ -362,7 +362,7 @@ thrown away. If there are fewer values than needed, the list is extended with
as many `nil`s as needed. If the list of expressions ends with a function
call, then all values returned by this call enter in the list of values,
before the adjustment (except when the call is enclosed in parentheses; see
-|luaref-langExpressions|).
+|lua-expressions|).
The assignment statement first evaluates all its expressions and only then are
the assignments performed. Thus the code
@@ -379,9 +379,9 @@ exchanges the values of `x` and `y`.
The meaning of assignments to global variables and table fields can be changed
via metatables. An assignment to an indexed variable `t[i] = val` is
-equivalent to `settable_event(t,i,val)`. (See |luaref-langMetatables| for a
-complete description of the `settable_event` function. This function is not
-defined or callable in Lua. We use it here only for explanatory purposes.)
+equivalent to `settable_event(t,i,val)`. (See |lua-metatable| for a complete
+description of the `settable_event` function. This function is not defined or
+callable in Lua. We use it here only for explanatory purposes.)
An assignment to a global variable `x = val` is equivalent to the
assignment `_env.x = val`, which in turn is equivalent to
@@ -392,10 +392,10 @@ where `_env` is the environment of the running function. (The `_env` variable is
not defined in Lua. We use it here only for explanatory purposes.)
------------------------------------------------------------------------------
-2.4.4 Control Structures *luaref-langContStructs*
+2.4.4 Control Structures *lua-control*
- *luaref-if* *luaref-then* *luaref-else* *luaref-elseif*
- *luaref-while* *luaref-repeat* *luaref-until*
+ *lua-if* *lua-then* *lua-else* *lua-elseif*
+ *lua-while* *lua-repeat* *lua-until*
The control structures `if`, `while`, and `repeat` have the usual meaning and
familiar syntax:
>
@@ -404,7 +404,7 @@ familiar syntax:
stat ::= if exp then block { elseif exp then block }
[ else block ] end
<
-Lua also has a `for` statement, in two flavors (see |luaref-langForStat|).
+Lua also has a `for` statement, in two flavors (see |lua-for|).
The condition expression of a control structure may return any value.
Both `false` and `nil` are considered false. All values different
@@ -415,14 +415,14 @@ In the `repeat-until` loop, the inner block does not end at the `until` keyword,
but only after the condition. So, the condition can refer to local variables
declared inside the loop block.
- *luaref-return*
+ *lua-return*
The `return` statement is used to return values from a function or a chunk
(which is just a function). Functions and chunks may return more than one
value, so the syntax for the `return` statement is
`stat ::=` `return` `[explist1]`
- *luaref-break*
+ *lua-break*
The `break` statement is used to terminate the execution of a `while`, `repeat`,
or `for` loop, skipping to the next statement after the loop:
@@ -437,7 +437,7 @@ middle of a block, then an explicit inner block can be used, as in the idioms
the last statements in their (inner) blocks.
------------------------------------------------------------------------------
-2.4.5 For Statement *luaref-for* *luaref-langForStat*
+2.4.5 For Statement *for* *lua-for*
The `for` statement has two forms: one numeric and one generic.
@@ -477,8 +477,8 @@ Note the following:
after the `for` ends or is broken. If you need this value, assign it to
another variable before breaking or exiting the loop.
- *luaref-in*
-The generic `for` statement works over functions, called iterators. On each
+ *for-in*
+The generic `for` statement works over functions, called |iterator|s. On each
iteration, the iterator function is called to produce a new value, stopping
when this new value is `nil`. The generic `for` loop has the following syntax:
>
@@ -513,17 +513,17 @@ Note the following:
them to other variables before breaking or exiting the loop.
------------------------------------------------------------------------------
-2.4.6 Function Calls as Statements *luaref-langFuncStat*
+2.4.6 Function Calls as Statements *lua-funcstatement*
To allow possible side-effects, function calls can be executed as statements:
>
stat ::= functioncall
<
In this case, all returned values are thrown away. Function calls are
-explained in |luaref-langFuncCalls|.
+explained in |lua-function|.
------------------------------------------------------------------------------
-2.4.7 Local Declarations *luaref-local* *luaref-langLocalDec*
+2.4.7 Local Declarations *lua-local*
Local variables may be declared anywhere inside a block. The declaration may
include an initial assignment:
@@ -532,18 +532,17 @@ include an initial assignment:
namelist ::= Name { , Name }
<
If present, an initial assignment has the same semantics of a multiple
-assignment (see |luaref-langAssign|). Otherwise, all variables are initialized
+assignment (see |lua-assign|). Otherwise, all variables are initialized
with `nil`.
-A chunk is also a block (see |luaref-langChunks|), and so local variables can be
+A chunk is also a block (see |lua-chunk|), and so local variables can be
declared in a chunk outside any explicit block. The scope of such local
variables extends until the end of the chunk.
-The visibility rules for local variables are explained in
-|luaref-langVisibRules|.
+The visibility rules for local variables are explained in |lua-visibility|.
==============================================================================
-2.5 Expressions *luaref-langExpressions*
+2.5 Expressions *lua-expressions*
The basic expressions in Lua are the following:
>
@@ -558,22 +557,21 @@ The basic expressions in Lua are the following:
exp ::= unop exp
prefixexp ::= var | functioncall | ( exp )
<
-Numbers and literal strings are explained in |luaref-langLexConv|; variables are
-explained in |luaref-langVariables|; function definitions are explained in
-|luaref-langFuncDefs|; function calls are explained in |luaref-langFuncCalls|;
-table constructors are explained in |luaref-langTableConst|. Vararg expressions,
+Numbers and literal strings are explained in |lua-lexical|; variables are
+explained in |lua-variables|; function definitions are explained in
+|lua-function-define|; function calls are explained in |lua-function|;
+table constructors are explained in |lua-tableconstructor|. Vararg expressions,
denoted by three dots (`...`), can only be used inside vararg functions;
-they are explained in |luaref-langFuncDefs|.
+they are explained in |lua-function-define|.
-Binary operators comprise arithmetic operators (see |luaref-langArithOp|),
-relational operators (see |luaref-langRelOp|), logical operators (see
-|luaref-langLogOp|), and the concatenation operator (see |luaref-langConcat|).
-Unary operators comprise the unary minus (see |luaref-langArithOp|), the unary
-`not` (see |luaref-langLogOp|), and the unary length operator (see
-|luaref-langLength|).
+Binary operators comprise arithmetic operators (see |lua-arithmetic|),
+relational operators (see |lua-relational|), logical operators (see
+|lua-logicalop|), and the concatenation operator (see |lua-concat|).
+Unary operators comprise the unary minus (see |lua-arithmetic|), the unary
+`not` (see |lua-logicalop|), and the unary length operator (see |lua-length|).
Both function calls and vararg expressions may result in multiple values. If
-the expression is used as a statement (see |luaref-langFuncStat|)
+the expression is used as a statement (see |lua-funcstatement|)
(only possible for function calls), then its return list is adjusted to zero
elements, thus discarding all returned values. If the expression is used as
the last (or the only) element of a list of expressions, then no adjustment is
@@ -606,12 +604,12 @@ An expression enclosed in parentheses always results in only one value. Thus,
return any values.)
------------------------------------------------------------------------------
-2.5.1 Arithmetic Operators *luaref-langArithOp*
+2.5.1 Arithmetic Operators *lua-arithmetic*
Lua supports the usual arithmetic operators: the binary `+` (addition),
`-` (subtraction), `*` (multiplication), `/` (division), `%` (modulo)
and `^` (exponentiation); and unary `-` (negation). If the operands are numbers,
-or strings that can be converted to numbers (see |luaref-langCoercion|), then all
+or strings that can be converted to numbers (see |lua-coercion|), then all
operations have the usual meaning. Exponentiation works for any exponent. For
instance, `x^(-0.5)` computes the inverse of the square root of `x`. Modulo is
defined as
@@ -622,7 +620,7 @@ That is, it is the remainder of a division that rounds the quotient towards
minus infinity.
------------------------------------------------------------------------------
-2.5.2 Relational Operators *luaref-langRelOp*
+2.5.2 Relational Operators *lua-relational*
The relational operators in Lua are
>
@@ -639,9 +637,9 @@ create a new object (a table, userdata, or function), this new object is
different from any previously existing object.
You can change the way that Lua compares tables and userdata using the "eq"
-metamethod (see |luaref-langMetatables|).
+metamethod (see |lua-metatable|).
-The conversion rules of coercion |luaref-langCoercion| do not apply to
+The conversion rules of coercion |lua-coercion| do not apply to
equality comparisons. Thus, `"0"==0` evaluates to `false`, and `t[0]` and
`t["0"]` denote different entries in a table.
@@ -650,19 +648,19 @@ The operator `~=` is exactly the negation of equality (`==`).
The order operators work as follows. If both arguments are numbers, then they
are compared as such. Otherwise, if both arguments are strings, then their
values are compared according to the current locale. Otherwise, Lua tries to
-call the "lt" or the "le" metamethod (see |luaref-langMetatables|).
+call the "lt" or the "le" metamethod (see |lua-metatable|).
------------------------------------------------------------------------------
-2.5.3 Logical Operators *luaref-langLogOp*
+2.5.3 Logical Operators *lua-logicalop*
The logical operators in Lua are
>
and or not
<
-Like the control structures (see |luaref-langContStructs|), all logical operators
+Like the control structures (see |lua-control|), all logical operators
consider both `false` and `nil` as false and anything else as true.
- *luaref-not* *luaref-and* *luaref-or*
+ *lua-not* *lua-and* *lua-or*
The negation operator `not` always returns `false` or `true`. The conjunction
operator `and` returns its first argument if this value is `false` or `nil`;
otherwise, `and` returns its second argument. The disjunction
@@ -683,15 +681,15 @@ evaluated only if necessary. Here are some examples:
(In this manual, `-->` indicates the result of the preceding expression.)
------------------------------------------------------------------------------
-2.5.4 Concatenation *luaref-langConcat*
+2.5.4 Concatenation *lua-concat*
The string concatenation operator in Lua is denoted by two dots (`..`).
If both operands are strings or numbers, then they are converted to strings
-according to the rules mentioned in |luaref-langCoercion|. Otherwise, the
-"concat" metamethod is called (see |luaref-langMetatables|).
+according to the rules mentioned in |lua-coercion|. Otherwise, the
+"concat" metamethod is called (see |lua-metatable|).
------------------------------------------------------------------------------
-2.5.5 The Length Operator *luaref-langLength*
+2.5.5 The Length Operator *lua-#* *lua-length*
The length operator is denoted by the unary operator `#`. The length of a
string is its number of bytes (that is, the usual meaning of string length
@@ -706,7 +704,7 @@ indices that directly precedes a `nil` value (that is, it may consider any
such `nil` value as the end of the array).
------------------------------------------------------------------------------
-2.5.6 Precedence *luaref-langPrec*
+2.5.6 Precedence *lua-precedence*
Operator precedence in Lua follows the table below, from lower to higher
priority:
@@ -725,7 +723,7 @@ The concatenation (`..`) and exponentiation (`^`) operators are right
associative. All other binary operators are left associative.
------------------------------------------------------------------------------
-2.5.7 Table Constructors *luaref-langTableConst*
+2.5.7 Table Constructors *lua-tableconstructor*
Table constructors are expressions that create tables. Every time a
constructor is evaluated, a new table is created. Constructors can be used to
@@ -761,14 +759,14 @@ is equivalent to
<
If the last field in the list has the form `exp` and the expression is a
function call, then all values returned by the call enter the list
-consecutively (see |luaref-langFuncCalls|). To avoid this, enclose the function
-call in parentheses (see |luaref-langExpressions|).
+consecutively (see |lua-function|). To avoid this, enclose the function
+call in parentheses (see |lua-expressions|).
The field list may have an optional trailing separator, as a convenience for
machine-generated code.
------------------------------------------------------------------------------
-2.5.8 Function Calls *luaref-function* *luaref-langFuncCalls*
+2.5.8 Function Calls *lua-function*
A function call in Lua has the following syntax:
>
@@ -778,7 +776,7 @@ In a function call, first `prefixexp` and `args` are evaluated. If the value
of `prefixexp` has type `function`, then this function is called with the given
arguments. Otherwise, the `prefixexp` "call" metamethod is called, having as
first parameter the value of `prefixexp`, followed by the original call
-arguments (see |luaref-langMetatables|).
+arguments (see |lua-metatable|).
The form
>
@@ -810,7 +808,7 @@ Lua would see that as a single statement, `a = f(g).x(a)`. So, if you want two
statements, you must add a semi-colon between them. If you actually want to
call `f`, you must remove the line break before `(g)`.
- *luaref-tailcall*
+ *lua-tailcall*
A call of the form `return` `functioncall` is called a tail call. Lua
implements proper tail calls (or proper tail recursion): in a tail call, the
called function reuses the stack entry of the calling function. Therefore,
@@ -829,7 +827,7 @@ of the following examples are tail calls:
<
------------------------------------------------------------------------------
-2.5.9 Function Definitions *luaref-langFuncDefs*
+2.5.9 Function Definitions *lua-function-define*
The syntax for function definition is
>
@@ -873,7 +871,7 @@ not to
(This only makes a difference when the body of the function contains
references to `f`.)
- *luaref-closure*
+ *lua-closure*
A function definition is an executable expression, whose value has type
`function`. When Lua pre-compiles a chunk, all its function bodies are
pre-compiled too. Then, whenever Lua executes the function definition, the
@@ -887,7 +885,7 @@ values:
>
parlist1 ::= namelist [ , ... ] | ...
<
- *luaref-vararg*
+ *lua-vararg*
When a function is called, the list of arguments is adjusted to the length of
the list of parameters, unless the function is a variadic or vararg function,
which is indicated by three dots (`...`) at the end of its parameter list. A
@@ -922,11 +920,11 @@ vararg expression:
g(3, 4, 5, 8) a=3, b=4, ... --> 5 8
g(5, r()) a=5, b=1, ... --> 2 3
<
-Results are returned using the `return` statement (see |luaref-langContStructs|).
+Results are returned using the `return` statement (see |lua-control|).
If control reaches the end of a function without encountering
a `return` statement, then the function returns with no results.
- *luaref-colonsyntax*
+ *lua-colonsyntax*
The colon syntax is used for defining methods, that is, functions that have an
implicit extra parameter `self`. Thus, the statement
@@ -937,7 +935,7 @@ is syntactic sugar for
`t.a.b.c:f = function (self, (` `params` `)` `body` `end`
==============================================================================
-2.6 Visibility Rules *luaref-langVisibRules*
+2.6 Visibility Rules *lua-visibility*
Lua is a lexically scoped language. The scope of variables begins at the first
statement after their declaration and lasts until the end of the innermost
@@ -959,7 +957,7 @@ block that includes the declaration. Consider the following example:
Notice that, in a declaration like `local x = x`, the new `x` being declared is
not in scope yet, and so the second `x` refers to the outside variable.
- *luaref-upvalue*
+ *lua-upvalue*
Because of the lexical scoping rules, local variables can be freely accessed
by functions defined inside their scope. A local variable used by an inner
function is called an upvalue, or external local variable, inside the inner
@@ -980,7 +978,7 @@ function). Each of these closures uses a different `y` variable, while all of
them share the same `x`.
==============================================================================
-2.7 Error Handling *luaref-langError*
+2.7 Error Handling *lua-errors*
Because Lua is an embedded extension language, all Lua actions start from
C code in the host program calling a function from the Lua library (see
@@ -989,11 +987,11 @@ execution, control returns to C, which can take appropriate measures (such as
print an error message).
Lua code can explicitly generate an error by calling the `error` function (see
-|luaref-error()|). If you need to catch errors in Lua, you can use
-the `pcall` function (see |luaref-pcall()|).
+|error()|). If you need to catch errors in Lua, you can use the `pcall`
+function (see |pcall()|).
==============================================================================
-2.8 Metatables *luaref-metatable* *luaref-langMetatables*
+2.8 Metatables *metatable* *lua-metatable*
Every value in Lua may have a metatable. This metatable is an ordinary Lua
table that defines the behavior of the original table and userdata under
@@ -1008,10 +1006,10 @@ previous example, the event is "add" and the metamethod is the function that
performs the addition.
You can query the metatable of any value through the `getmetatable` function
-(see |luaref-getmetatable()|).
+(see |getmetatable()|).
You can replace the metatable of tables through the `setmetatable` function (see
-|luaref-setmetatable()|). You cannot change the metatable of other types from Lua
+|setmetatable()|). You cannot change the metatable of other types from Lua
(except using the debug library); you must use the C API for that.
Tables and userdata have individual metatables (although multiple tables and
@@ -1037,7 +1035,7 @@ by a Lua function describing how the interpreter executes that operation.
The code shown here in Lua is only illustrative; the real behavior is hard
coded in the interpreter and it is much more efficient than this simulation.
All functions used in these descriptions (`rawget`, `tonumber`, etc.) are
-described in |luaref-libBasic|. In particular, to retrieve the metamethod of a
+described in |lua-lib-core|. In particular, to retrieve the metamethod of a
given object, we use the expression
>
metatable(obj)[event]
@@ -1307,7 +1305,7 @@ called when Lua calls a value.
<
==============================================================================
-2.9 Environments *luaref-environment* *luaref-langEnvironments*
+2.9 Environments *lua-environments*
Besides metatables, objects of types thread, function, and userdata have
another table associated with them, called their environment. Like metatables,
@@ -1319,16 +1317,15 @@ convenience feature for programmers to associate a table to a userdata.
Environments associated with threads are called global environments. They are
used as the default environment for their threads and non-nested functions
-created by the thread (through `loadfile` |luaref-loadfile()|, `loadstring`
-|luaref-loadstring()| or `load` |luaref-load()|) and can be directly accessed by C
-code (see |luaref-apiPseudoIndices|).
+created by the thread (through |loadfile()|, |loadstring()| or |load()|) and
+can be directly accessed by C code (see |lua-pseudoindex|).
Environments associated with C functions can be directly accessed by C code
-(see |luaref-apiPseudoIndices|). They are used as the default environment for
+(see |lua-pseudoindex|). They are used as the default environment for
other C functions created by the function.
Environments associated with Lua functions are used to resolve all accesses to
-global variables within the function (see |luaref-langVariables|). They are
+global variables within the function (see |lua-variables|). They are
used as the default environment for other Lua functions created by the
function.
@@ -1339,7 +1336,7 @@ environment of other objects (userdata, C functions, other threads) you must
use the C API.
==============================================================================
-2.10 Garbage Collection *luaref-langGC*
+2.10 Garbage Collection *lua-gc*
Lua performs automatic memory management. This means that you do not have to
worry neither about allocating memory for new objects nor about freeing it
@@ -1367,16 +1364,16 @@ The default, 2, means that the collector runs at "twice" the speed of memory
allocation.
You can change these numbers by calling `lua_gc` (see |lua_gc()|) in C or
-`collectgarbage` (see |luaref-collectgarbage()|) in Lua. Both get percentage
-points as arguments (so an argument of 100 means a real value of 1). With
-these functions you can also control the collector directly (e.g., stop and
-restart it).
+`collectgarbage` (see |collectgarbage()|) in Lua. Both get percentage points
+as arguments (so an argument of 100 means a real value of 1). With these
+functions you can also control the collector directly (e.g., stop and restart
+it).
------------------------------------------------------------------------------
-2.10.1 Garbage-Collection Metamethods *luaref-langGCMeta*
+2.10.1 Garbage-Collection Metamethods *lua-gc-meta*
Using the C API, you can set garbage-collector metamethods for userdata (see
-|luaref-langMetatables|). These metamethods are also called finalizers.
+|lua-metatable|). These metamethods are also called finalizers.
Finalizers allow you to coordinate Lua's garbage collection with external
resource management (such as closing files, network or database connections,
or freeing your own memory).
@@ -1400,7 +1397,7 @@ cycle. That is, the first finalizer to be called is the one associated with
the userdata created last in the program.
------------------------------------------------------------------------------
-2.10.2 - Weak Tables *luaref-weaktable* *luaref-langWeaktables*
+2.10.2 - Weak Tables *lua-weaktable*
A weak table is a table whose elements are weak references. A weak reference
is ignored by the garbage collector. In other words, if the only references to
@@ -1422,7 +1419,7 @@ field `__mode`. Otherwise, the weak behavior of the tables controlled by this
metatable is undefined.
==============================================================================
-2.11 Coroutines *luaref-coroutine* *luaref-langCoro*
+2.11 Coroutines *lua-coroutine*
Lua supports coroutines, also called collaborative multithreading. A coroutine
in Lua represents an independent thread of execution. Unlike threads in
@@ -1502,7 +1499,7 @@ When you run it, it produces the following output:
<
==============================================================================
-3 THE APPLICATION PROGRAM INTERFACE *luaref-API*
+3 THE APPLICATION PROGRAM INTERFACE *lua-API*