aboutsummaryrefslogtreecommitdiff
path: root/manual.tex
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-01 14:41:34 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-01 14:41:34 -0300
commit88b185ada15b76d6bfe8bb5e2d38935cf32e618a (patch)
tree7e02b1633ef2c08f43755ebaf3bfe2a8ad83afa5 /manual.tex
parentef3c45d5230b08d87b53d67c04f34873c3d24933 (diff)
downloadlua-88b185ada15b76d6bfe8bb5e2d38935cf32e618a.tar.gz
lua-88b185ada15b76d6bfe8bb5e2d38935cf32e618a.tar.bz2
lua-88b185ada15b76d6bfe8bb5e2d38935cf32e618a.zip
more uniform source (more macros...)
Diffstat (limited to 'manual.tex')
-rw-r--r--manual.tex263
1 files changed, 132 insertions, 131 deletions
diff --git a/manual.tex b/manual.tex
index 747a3e82..6573c472 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 2.7 1997/06/27 18:39:34 roberto Exp roberto $ 1% $Id: manual.tex,v 2.8 1997/06/27 22:38:49 roberto Exp roberto $
2 2
3\documentstyle[fullpage,11pt,bnf]{article} 3\documentstyle[fullpage,11pt,bnf]{article}
4 4
@@ -6,14 +6,15 @@
6\newcommand{\See}[1]{Section~\ref{#1}} 6\newcommand{\See}[1]{Section~\ref{#1}}
7\newcommand{\see}[1]{(see \See{#1})} 7\newcommand{\see}[1]{(see \See{#1})}
8\newcommand{\M}[1]{\emph{#1}} 8\newcommand{\M}[1]{\emph{#1}}
9\newcommand{\T}[1]{{\tt #1}}
9\newcommand{\Math}[1]{$#1$} 10\newcommand{\Math}[1]{$#1$}
10\newcommand{\nil}{{\bf nil}} 11\newcommand{\nil}{{\bf nil}}
11\newcommand{\Line}{\rule{\linewidth}{.5mm}} 12\newcommand{\Line}{\rule{\linewidth}{.5mm}}
12\def\tecgraf{{\sf TeC\kern-.21em\lower.7ex\hbox{Graf}}} 13\def\tecgraf{{\sf TeC\kern-.21em\lower.7ex\hbox{Graf}}}
13 14
14\newcommand{\Index}[1]{#1\index{#1}} 15\newcommand{\Index}[1]{#1\index{#1}}
15\newcommand{\IndexVerb}[1]{{\tt #1}\index{#1}} 16\newcommand{\IndexVerb}[1]{\T{#1}\index{#1}}
16\newcommand{\Def}[1]{{\em #1}\index{#1}} 17\newcommand{\Def}[1]{\emph{#1}\index{#1}}
17\newcommand{\Deffunc}[1]{\index{#1}} 18\newcommand{\Deffunc}[1]{\index{#1}}
18 19
19\newcommand{\ff}{$\bullet$\ } 20\newcommand{\ff}{$\bullet$\ }
@@ -38,7 +39,7 @@ Waldemar Celes
38\tecgraf\ --- Computer Science Department --- PUC-Rio 39\tecgraf\ --- Computer Science Department --- PUC-Rio
39} 40}
40 41
41\date{\small \verb$Date: 1997/06/27 18:39:34 $} 42\date{\small \verb$Date: 1997/06/27 22:38:49 $}
42 43
43\maketitle 44\maketitle
44 45
@@ -127,8 +128,8 @@ L.~H.~de Figueiredo.
127 128
128Lua is implemented as a library, written in C. 129Lua is implemented as a library, written in C.
129Being an extension language, Lua has no notion of a ``main'' program: 130Being an extension language, Lua has no notion of a ``main'' program:
130it only works {\em embedded\/} in a host client, 131it only works \emph{embedded} in a host client,
131called the {\em embedding\/} program. 132called the \emph{embedding} program.
132This host program can invoke functions to execute a piece of 133This host program can invoke functions to execute a piece of
133code in Lua, can write and read Lua variables, 134code in Lua, can write and read Lua variables,
134and can register C functions to be called by Lua code. 135and can register C functions to be called by Lua code.
@@ -167,9 +168,9 @@ this default can be changed \see{tag-method}.
167 168
168The unit of execution of Lua is called a \Def{chunk}. 169The unit of execution of Lua is called a \Def{chunk}.
169The syntax% 170The syntax%
170\footnote{As usual, \rep{{\em a}} means 0 or more {\em a\/}'s, 171\footnote{As usual, \rep{\emph{a}} means 0 or more \emph{a}'s,
171\opt{{\em a}} means an optional {\em a} and \oneormore{{\em a}} means 172\opt{\emph{a}} means an optional \emph{a} and \oneormore{\emph{a}} means
172one or more {\em a\/}'s.} 173one or more \emph{a}'s.}
173for chunks is: 174for chunks is:
174\begin{Produc} 175\begin{Produc}
175\produc{chunk}{\rep{stat \Or function} \opt{ret}} 176\produc{chunk}{\rep{stat \Or function} \opt{ret}}
@@ -203,10 +204,10 @@ Besides a type, all values also have a \Index{tag}.
203 204
204There are six \Index{basic types} in Lua: \Def{nil}, \Def{number}, 205There are six \Index{basic types} in Lua: \Def{nil}, \Def{number},
205\Def{string}, \Def{function}, \Def{userdata}, and \Def{table}. 206\Def{string}, \Def{function}, \Def{userdata}, and \Def{table}.
206{\em Nil\/} is the type of the value \nil, 207\emph{Nil} is the type of the value \nil,
207whose main property is to be different from any other value. 208whose main property is to be different from any other value.
208{\em Number\/} represents real (floating-point) numbers, 209\emph{Number} represents real (floating-point) numbers,
209while {\em string\/} has the usual meaning. 210while \emph{string} has the usual meaning.
210The function \verb|type| returns a string describing the type 211The function \verb|type| returns a string describing the type
211of a given value \see{pdf-type}. 212of a given value \see{pdf-type}.
212 213
@@ -222,15 +223,15 @@ all Lua functions have the same tag,
222and all C functions have the same tag, 223and all C functions have the same tag,
223which is different from the tag of a Lua function. 224which is different from the tag of a Lua function.
224 225
225The type {\em userdata\/} is provided to allow 226The type \emph{userdata} is provided to allow
226arbitrary \Index{C pointers} to be stored in Lua variables. 227arbitrary \Index{C pointers} to be stored in Lua variables.
227It corresponds to a \verb|void*| and has no pre-defined operations in Lua, 228It corresponds to a \verb|void*| and has no pre-defined operations in Lua,
228besides assignment and equality test. 229besides assignment and equality test.
229However, by using {\em tag methods}, 230However, by using \emph{tag methods},
230the programmer may define operations for {\em userdata\/} values 231the programmer may define operations for \emph{userdata} values
231\see{tag-method}. 232\see{tag-method}.
232 233
233The type {\em table\/} implements \Index{associative arrays}, 234The type \emph{table} implements \Index{associative arrays},
234that is, \Index{arrays} that can be indexed not only with numbers, 235that is, \Index{arrays} that can be indexed not only with numbers,
235but with any value (except \nil). 236but with any value (except \nil).
236Therefore, this type may be used not only to represent ordinary arrays, 237Therefore, this type may be used not only to represent ordinary arrays,
@@ -245,8 +246,8 @@ The form \verb|t:f(x)| is syntactic sugar for \verb|t.f(t,x)|,
245which calls the method \verb|f| from the table \verb|t| passing 246which calls the method \verb|f| from the table \verb|t| passing
246itself as the first parameter \see{func-def}. 247itself as the first parameter \see{func-def}.
247 248
248It is important to notice that tables are {\em objects}, and not values. 249It is important to notice that tables are \emph{objects}, and not values.
249Variables cannot contain tables, only {\em references\/} to them. 250Variables cannot contain tables, only \emph{references} to them.
250Assignment, parameter passing and returns always manipulate references 251Assignment, parameter passing and returns always manipulate references
251to tables, and do not imply any kind of copy. 252to tables, and do not imply any kind of copy.
252Moreover, tables must be explicitly created before used 253Moreover, tables must be explicitly created before used
@@ -322,16 +323,16 @@ Examples of valid numerical constants are:
322All lines that start with a \verb|$| are handled by a pre-processor. 323All lines that start with a \verb|$| are handled by a pre-processor.
323The \verb|$| can be followed by any of the following directives: 324The \verb|$| can be followed by any of the following directives:
324\begin{description} 325\begin{description}
325\item[{\tt debug}] --- turn on some debugging facilities \see{pragma}. 326\item[\T{debug}] --- turn on some debugging facilities \see{pragma}.
326\item[{\tt nodebug}] --- turn off some debugging facilities \see{pragma}. 327\item[\T{nodebug}] --- turn off some debugging facilities \see{pragma}.
327\item[{\tt if \M{cond}}] --- starts a conditional part. 328\item[{\tt if \M{cond}}] --- starts a conditional part.
328If \M{cond} is false, then this part is skipped by the lexical analyzer. 329If \M{cond} is false, then this part is skipped by the lexical analyzer.
329\item[{\tt ifnot \M{cond}}] --- starts a conditional part. 330\item[{\tt ifnot \M{cond}}] --- starts a conditional part.
330If \M{cond} is true, then this part is skipped by the lexical analyzer. 331If \M{cond} is true, then this part is skipped by the lexical analyzer.
331\item[{\tt end}] --- ends a conditional part. 332\item[\T{end}] --- ends a conditional part.
332\item[{\tt else}] --- starts an ``else'' conditional part, 333\item[\T{else}] --- starts an ``else'' conditional part,
333switching the ``skip'' status. 334switching the ``skip'' status.
334\item[{\tt endinput}] --- ends the lexical parse of the file. 335\item[\T{endinput}] --- ends the lexical parse of the file.
335\end{description} 336\end{description}
336 337
337Directives can be freely nested. 338Directives can be freely nested.
@@ -340,8 +341,8 @@ in that case, even the matching \verb|$end| is not parsed.
340 341
341A \M{cond} part may be: 342A \M{cond} part may be:
342\begin{description} 343\begin{description}
343\item[{\tt nil}] --- always false. 344\item[\T{nil}] --- always false.
344\item[{\tt 1}] --- always true. 345\item[\T{1}] --- always true.
345\item[\M{name}] --- true if the value of the 346\item[\M{name}] --- true if the value of the
346global variable \M{name} is different from \nil. 347global variable \M{name} is different from \nil.
347Notice that \M{name} is evaluated before the chunk starts its execution. 348Notice that \M{name} is evaluated before the chunk starts its execution.
@@ -369,7 +370,7 @@ Functions in Lua can return many values.
369Because there are no type declarations, 370Because there are no type declarations,
370the system does not know how many values a function will return, 371the system does not know how many values a function will return,
371or how many parameters it needs. 372or how many parameters it needs.
372Therefore, sometimes, a list of values must be {\em adjusted\/}, at run time, 373Therefore, sometimes, a list of values must be \emph{adjusted}, at run time,
373to a given length. 374to a given length.
374If there are more values than are needed, then the last values are thrown away. 375If there are more values than are needed, then the last values are thrown away.
375If there are more needs than values, then the list is extended with as 376If there are more needs than values, then the list is extended with as
@@ -416,7 +417,7 @@ Therefore, it can be used to exchange two values, as in
416 x, y = y, x 417 x, y = y, x
417\end{verbatim} 418\end{verbatim}
418The two lists may have different lengths. 419The two lists may have different lengths.
419Before the assignment, the list of values is {\em adjusted\/} to 420Before the assignment, the list of values is \emph{adjusted} to
420the length of the list of variables \see{adjust}. 421the length of the list of variables \see{adjust}.
421 422
422A single name can denote a global or a local variable, 423A single name can denote a global or a local variable,
@@ -440,7 +441,7 @@ an assignment \verb|t[i] = val| is equivalent to
440\verb|settable_event(t, i, val)|. 441\verb|settable_event(t, i, val)|.
441See \See{tag-method} for a description of these functions% 442See \See{tag-method} for a description of these functions%
442\footnote{Function \verb|setglobal| is pre-defined in Lua. 443\footnote{Function \verb|setglobal| is pre-defined in Lua.
443Function {\tt settable\_event} is used only for explanation purposes.}. 444Function \T{settable\_event} is used only for explanatory purposes.}.
444 445
445The syntax \verb|var.NAME| is just syntactic sugar for 446The syntax \verb|var.NAME| is just syntactic sugar for
446\verb|var["NAME"]|: 447\verb|var["NAME"]|:
@@ -452,7 +453,7 @@ The syntax \verb|var.NAME| is just syntactic sugar for
452The \Index{condition expression} of a control structure may return any value. 453The \Index{condition expression} of a control structure may return any value.
453All values different from \nil\ are considered true; 454All values different from \nil\ are considered true;
454only \nil\ is considered false. 455only \nil\ is considered false.
455{\tt if}'s, {\tt while}'s and {\tt repeat}'s have the usual meaning. 456\T{if}'s, \T{while}'s and \T{repeat}'s have the usual meaning.
456 457
457\index{while-do}\index{repeat-until}\index{if-then-else} 458\index{while-do}\index{repeat-until}\index{if-then-else}
458\begin{Produc} 459\begin{Produc}
@@ -463,7 +464,7 @@ only \nil\ is considered false.
463\produc{elseif}{\rwd{elseif} exp1 \rwd{then} block} 464\produc{elseif}{\rwd{elseif} exp1 \rwd{then} block}
464\end{Produc} 465\end{Produc}
465 466
466A {\tt return} is used to return values from a function or a chunk. 467A \T{return} is used to return values from a function or a chunk.
467\label{return} 468\label{return}
468Because they may return more than one value, 469Because they may return more than one value,
469the syntax for a \Index{return statement} is: 470the syntax for a \Index{return statement} is:
@@ -516,7 +517,7 @@ an access to an indexed variable \verb|t[i]| is equivalent to
516a call \verb|gettable_event(t, i)|. 517a call \verb|gettable_event(t, i)|.
517See \See{tag-method} for a description of these functions% 518See \See{tag-method} for a description of these functions%
518\footnote{Function \verb|getglobal| is pre-defined in Lua. 519\footnote{Function \verb|getglobal| is pre-defined in Lua.
519Function {\tt gettable\_event} is used only for explanation purposes.}. 520Function \T{gettable\_event} is used only for explanatory purposes.}.
520 521
521The non-terminal \M{exp1} is used to indicate that the values 522The non-terminal \M{exp1} is used to indicate that the values
522returned by an expression must be adjusted to one single value: 523returned by an expression must be adjusted to one single value:
@@ -554,7 +555,7 @@ Tables, userdata and functions are compared by reference,
554that is, two tables are considered equal only if they are the same table. 555that is, two tables are considered equal only if they are the same table.
555The operator \verb|~=| is exactly the negation of equality (\verb|==|). 556The operator \verb|~=| is exactly the negation of equality (\verb|==|).
556Note that the conversion rules of Section~\ref{coercion} 557Note that the conversion rules of Section~\ref{coercion}
557{\em do not\/} apply to equality comparisons. 558\emph{do not} apply to equality comparisons.
558Thus, \verb|"0"==0| evaluates to false. 559Thus, \verb|"0"==0| evaluates to false.
559 560
560The other operators work as follows. 561The other operators work as follows.
@@ -620,7 +621,7 @@ The general syntax for constructors is:
620\produc{ffieldlist}{\opt{ffieldlist1}} 621\produc{ffieldlist}{\opt{ffieldlist1}}
621\end{Produc} 622\end{Produc}
622 623
623The form {\em lfieldlist1\/} is used to initialize lists. 624The form \emph{lfieldlist1} is used to initialize lists.
624\begin{Produc} 625\begin{Produc}
625\produc{lfieldlist1}{exp \rep{\ter{,} exp} \opt{\ter{,}}} 626\produc{lfieldlist1}{exp \rep{\ter{,} exp} \opt{\ter{,}}}
626\end{Produc}% 627\end{Produc}%
@@ -639,7 +640,7 @@ is essentially equivalent to:
639 a = temp 640 a = temp
640\end{verbatim} 641\end{verbatim}
641 642
642The form {\em ffieldlist1\/} initializes other fields in a table: 643The form \emph{ffieldlist1} initializes other fields in a table:
643\begin{Produc} 644\begin{Produc}
644\produc{ffieldlist1}{ffield \rep{\ter{,} ffield} \opt{\ter{,}}} 645\produc{ffieldlist1}{ffield \rep{\ter{,} ffield} \opt{\ter{,}}}
645\produc{ffield}{\ter{[} exp \ter{]} \ter {=} exp \Or name \ter{=} exp} 646\produc{ffield}{\ter{[} exp \ter{]} \ter {=} exp \Or name \ter{=} exp}
@@ -666,7 +667,7 @@ A \Index{function call} has the following syntax:
666\produc{functioncall}{var realParams} 667\produc{functioncall}{var realParams}
667\end{Produc}% 668\end{Produc}%
668Here, \M{var} can be any variable (global, local, indexed, etc). 669Here, \M{var} can be any variable (global, local, indexed, etc).
669If its value has type {\em function\/}, 670If its value has type \emph{function},
670then this function is called. 671then this function is called.
671Otherwise, the ``function'' tag method is called, 672Otherwise, the ``function'' tag method is called,
672having as first parameter the value of \M{var}, 673having as first parameter the value of \M{var},
@@ -721,7 +722,7 @@ The syntax for function definition is:
721When Lua pre-compiles a chunk, 722When Lua pre-compiles a chunk,
722all its function bodies are pre-compiled, too. 723all its function bodies are pre-compiled, too.
723Then, when Lua ``executes'' the function definition, 724Then, when Lua ``executes'' the function definition,
724its body is stored, with type {\em function}, 725its body is stored, with type \emph{function},
725into the variable \verb|var|. 726into the variable \verb|var|.
726It is in this sense that 727It is in this sense that
727a function definition is an assignment to a global variable. 728a function definition is an assignment to a global variable.
@@ -1200,17 +1201,17 @@ there is no guarantee that such pointer will be valid after the block ends
1200(see below). 1201(see below).
1201 1202
1202\verb|lua_getcfunction| converts a \verb|lua_Object| to a C function. 1203\verb|lua_getcfunction| converts a \verb|lua_Object| to a C function.
1203This \verb|lua_Object| must have type {\em CFunction\/}; 1204This \verb|lua_Object| must have type \emph{CFunction};
1204otherwise, the function returns 0 (the \verb|NULL| pointer). 1205otherwise, the function returns 0 (the \verb|NULL| pointer).
1205The type \verb|lua_CFunction| is explained in Section~\ref{LuacallC}. 1206The type \verb|lua_CFunction| is explained in Section~\ref{LuacallC}.
1206 1207
1207\verb|lua_getuserdata| converts a \verb|lua_Object| to \verb|void*|. 1208\verb|lua_getuserdata| converts a \verb|lua_Object| to \verb|void*|.
1208This \verb|lua_Object| must have type {\em userdata\/}; 1209This \verb|lua_Object| must have type \emph{userdata};
1209otherwise, the function returns 0 (the \verb|NULL| pointer). 1210otherwise, the function returns 0 (the \verb|NULL| pointer).
1210 1211
1211Because Lua has automatic memory management and garbage collection, 1212Because Lua has automatic memory management and garbage collection,
1212a \verb|lua_Object| has a limited scope, 1213a \verb|lua_Object| has a limited scope,
1213and is only valid inside the {\em block\/} where it was created. 1214and is only valid inside the \emph{block} where it was created.
1214A C function called from Lua is a block, 1215A C function called from Lua is a block,
1215and its parameters are valid only until its end. 1216and its parameters are valid only until its end.
1216It is good programming practice to convert Lua objects to C values 1217It is good programming practice to convert Lua objects to C values
@@ -1352,7 +1353,7 @@ lua_Object lua_getglobal (char *varname);
1352As in Lua, this function may trigger a tag method. 1353As in Lua, this function may trigger a tag method.
1353To read the real value of any global variable, 1354To read the real value of any global variable,
1354without invoking any tag method, 1355without invoking any tag method,
1355this function has a {\em raw\/} version: 1356this function has a \emph{raw} version:
1356\Deffunc{lua_rawgetglobal} 1357\Deffunc{lua_rawgetglobal}
1357\begin{verbatim} 1358\begin{verbatim}
1358lua_Object lua_rawgetglobal (char *varname); 1359lua_Object lua_rawgetglobal (char *varname);
@@ -1367,7 +1368,7 @@ void lua_setglobal (char *varname);
1367As in Lua, this function may trigger a tag method. 1368As in Lua, this function may trigger a tag method.
1368To set the real value of any global variable, 1369To set the real value of any global variable,
1369without invoking any tag method, 1370without invoking any tag method,
1370this function has a {\em raw\/} version: 1371this function has a \emph{raw} version:
1371\Deffunc{lua_rawgetglobal} 1372\Deffunc{lua_rawgetglobal}
1372\begin{verbatim} 1373\begin{verbatim}
1373void lua_rawsetglobal (char *varname); 1374void lua_rawsetglobal (char *varname);
@@ -1384,7 +1385,7 @@ and returns the contents of the table at that index.
1384As in Lua, this operation may trigger a tag method. 1385As in Lua, this operation may trigger a tag method.
1385To get the real value of any table index, 1386To get the real value of any table index,
1386without invoking any tag method, 1387without invoking any tag method,
1387this function has a {\em raw\/} version: 1388this function has a \emph{raw} version:
1388\Deffunc{lua_rawgetglobal} 1389\Deffunc{lua_rawgetglobal}
1389\begin{verbatim} 1390\begin{verbatim}
1390lua_Object lua_rawgettable (void); 1391lua_Object lua_rawgettable (void);
@@ -1401,7 +1402,7 @@ void lua_settable (void);
1401Again, the tag method for ``settable'' may be called. 1402Again, the tag method for ``settable'' may be called.
1402To set the real value of any table index, 1403To set the real value of any table index,
1403without invoking any tag method, 1404without invoking any tag method,
1404this function has a {\em raw\/} version: 1405this function has a \emph{raw} version:
1405\Deffunc{lua_rawsettable} 1406\Deffunc{lua_rawsettable}
1406\begin{verbatim} 1407\begin{verbatim}
1407void lua_rawsettable (void); 1408void lua_rawsettable (void);
@@ -1543,7 +1544,7 @@ void lua_unref (int ref);
1543The function \verb|lua_ref| creates a reference 1544The function \verb|lua_ref| creates a reference
1544to the object that is on the top of the stack, 1545to the object that is on the top of the stack,
1545and returns this reference. 1546and returns this reference.
1546If \verb|lock| is true, the object is {\em locked\/}: 1547If \verb|lock| is true, the object is \emph{locked}:
1547this means the object will not be garbage collected. 1548this means the object will not be garbage collected.
1548Notice that an unlocked reference may be garbage collected. 1549Notice that an unlocked reference may be garbage collected.
1549Whenever the referenced object is needed, 1550Whenever the referenced object is needed,
@@ -1584,7 +1585,7 @@ declared in \verb|lualib.h|.
1584 1585
1585\subsection{Predefined Functions} \label{predefined} 1586\subsection{Predefined Functions} \label{predefined}
1586 1587
1587\subsubsection*{\ff {\tt call (func, arg, [retmode])}}\Deffunc{call} 1588\subsubsection*{\ff \T{call (func, arg, [retmode])}}\Deffunc{call}
1588This function calls function \verb|func| with 1589This function calls function \verb|func| with
1589the arguments given by the table \verb|arg|. 1590the arguments given by the table \verb|arg|.
1590The call is equivalent to 1591The call is equivalent to
@@ -1597,7 +1598,7 @@ then Lua stops getting arguments at the first nil value.
1597If \verb|retmode| is absent, 1598If \verb|retmode| is absent,
1598all results from \verb|func| are just returned by the call. 1599all results from \verb|func| are just returned by the call.
1599If \verb|retmode| is equal to \verb|"pack"|, 1600If \verb|retmode| is equal to \verb|"pack"|,
1600the results are {\em packed\/} in a single table.\index{packed results} 1601the results are \emph{packed} in a single table.\index{packed results}
1601That is, \verb|call| returns just one table; 1602That is, \verb|call| returns just one table;
1602at index \verb|n|, the table has the total number of results 1603at index \verb|n|, the table has the total number of results
1603from the call; 1604from the call;
@@ -1610,7 +1611,7 @@ t = {x=1}
1610a = call(next, {t,nil;n=2}, "pack") --> a={"x", 1; n=2} 1611a = call(next, {t,nil;n=2}, "pack") --> a={"x", 1; n=2}
1611\end{verbatim} 1612\end{verbatim}
1612 1613
1613\subsubsection*{\ff {\tt collectgarbage ([limit])}}\Deffunc{collectgarbage} 1614\subsubsection*{\ff \T{collectgarbage ([limit])}}\Deffunc{collectgarbage}
1614Forces a garbage collection cycle. 1615Forces a garbage collection cycle.
1615Returns the number of objects collected. 1616Returns the number of objects collected.
1616An optional argument, \verb|limit|, is a number that 1617An optional argument, \verb|limit|, is a number that
@@ -1621,7 +1622,7 @@ this limit.
1621\verb|collectgarbage| is equivalent to 1622\verb|collectgarbage| is equivalent to
1622the API function \verb|lua_collectgarbage|. 1623the API function \verb|lua_collectgarbage|.
1623 1624
1624\subsubsection*{\ff {\tt dofile (filename)}}\Deffunc{dofile} 1625\subsubsection*{\ff \T{dofile (filename)}}\Deffunc{dofile}
1625This function receives a file name, 1626This function receives a file name,
1626opens it, and executes its contents as a Lua chunk, 1627opens it, and executes its contents as a Lua chunk,
1627or as pre-compiled chunks. 1628or as pre-compiled chunks.
@@ -1634,7 +1635,7 @@ or a non \nil\ value if the chunk returns no values.
1634It issues an error when called with a non string argument. 1635It issues an error when called with a non string argument.
1635\verb|dofile| is equivalent to the API function \verb|lua_dofile|. 1636\verb|dofile| is equivalent to the API function \verb|lua_dofile|.
1636 1637
1637\subsubsection*{\ff {\tt dostring (string [, errmethod])}}\Deffunc{dostring} 1638\subsubsection*{\ff \T{dostring (string [, errmethod])}}\Deffunc{dostring}
1638This function executes a given string as a Lua chunk. 1639This function executes a given string as a Lua chunk.
1639If there is any error executing the string, it returns \nil. 1640If there is any error executing the string, it returns \nil.
1640Otherwise, it returns the values returned by the chunk, 1641Otherwise, it returns the values returned by the chunk,
@@ -1644,11 +1645,11 @@ while \verb|string| runs.
1644As a particular case, if \verb|errmethod| is \nil, 1645As a particular case, if \verb|errmethod| is \nil,
1645no error messages will be issued during the execution of the string. 1646no error messages will be issued during the execution of the string.
1646 1647
1647\subsubsection*{\ff {\tt newtag ()}}\Deffunc{newtag}\label{pdf-newtag} 1648\subsubsection*{\ff \T{newtag ()}}\Deffunc{newtag}\label{pdf-newtag}
1648Returns a new tag. 1649Returns a new tag.
1649\verb|newtag| is equivalent to the API function \verb|lua_newtag|. 1650\verb|newtag| is equivalent to the API function \verb|lua_newtag|.
1650 1651
1651\subsubsection*{\ff {\tt next (table, index)}}\Deffunc{next} 1652\subsubsection*{\ff \T{next (table, index)}}\Deffunc{next}
1652This function allows a program to traverse all fields of a table. 1653This function allows a program to traverse all fields of a table.
1653Its first argument is a table and its second argument 1654Its first argument is a table and its second argument
1654is an index in this table. 1655is an index in this table.
@@ -1665,7 +1666,7 @@ semantically, there is no difference between a
1665field not present in a table or a field with value \nil. 1666field not present in a table or a field with value \nil.
1666Therefore, the function only considers fields with non \nil\ values. 1667Therefore, the function only considers fields with non \nil\ values.
1667The order in which the indices are enumerated is not specified, 1668The order in which the indices are enumerated is not specified,
1668{\em not even for numeric indices} 1669\emph{not even for numeric indices}
1669(to traverse a table in numeric order, 1670(to traverse a table in numeric order,
1670use a counter). 1671use a counter).
1671If the table is modified in any way during a traversal, 1672If the table is modified in any way during a traversal,
@@ -1673,7 +1674,7 @@ the semantics of \verb|next| is undefined.
1673 1674
1674This function cannot be written with the standard API. 1675This function cannot be written with the standard API.
1675 1676
1676\subsubsection*{\ff {\tt nextvar (name)}}\Deffunc{nextvar} 1677\subsubsection*{\ff \T{nextvar (name)}}\Deffunc{nextvar}
1677This function is similar to the function \verb|next|, 1678This function is similar to the function \verb|next|,
1678but iterates over the global variables. 1679but iterates over the global variables.
1679Its single argument is the name of a global variable, 1680Its single argument is the name of a global variable,
@@ -1686,11 +1687,11 @@ otherwise the semantics of \verb|nextvar| is undefined.
1686 1687
1687This function cannot be written with the standard API. 1688This function cannot be written with the standard API.
1688 1689
1689\subsubsection*{\ff {\tt tostring (e)}}\Deffunc{tostring} 1690\subsubsection*{\ff \T{tostring (e)}}\Deffunc{tostring}
1690This function receives an argument of any type and 1691This function receives an argument of any type and
1691converts it to a string in a reasonable format. 1692converts it to a string in a reasonable format.
1692 1693
1693\subsubsection*{\ff {\tt print (e1, e2, ...)}}\Deffunc{print} 1694\subsubsection*{\ff \T{print (e1, e2, ...)}}\Deffunc{print}
1694This function receives any number of arguments, 1695This function receives any number of arguments,
1695and prints their values in a reasonable format. 1696and prints their values in a reasonable format.
1696Each value is printed in a new line. 1697Each value is printed in a new line.
@@ -1699,14 +1700,14 @@ but as a quick way to show a value,
1699for instance for error messages or debugging. 1700for instance for error messages or debugging.
1700See Section~\ref{libio} for functions for formatted output. 1701See Section~\ref{libio} for functions for formatted output.
1701 1702
1702\subsubsection*{\ff {\tt tonumber (e)}}\Deffunc{tonumber} 1703\subsubsection*{\ff \T{tonumber (e)}}\Deffunc{tonumber}
1703This function receives one argument, 1704This function receives one argument,
1704and tries to convert it to a number. 1705and tries to convert it to a number.
1705If the argument is already a number or a string convertible 1706If the argument is already a number or a string convertible
1706to a number \see{coercion}, then it returns that number; 1707to a number \see{coercion}, then it returns that number;
1707otherwise, it returns \nil. 1708otherwise, it returns \nil.
1708 1709
1709\subsubsection*{\ff {\tt type (v)}}\Deffunc{type}\label{pdf-type} 1710\subsubsection*{\ff \T{type (v)}}\Deffunc{type}\label{pdf-type}
1710This function allows Lua to test the type of a value. 1711This function allows Lua to test the type of a value.
1711It receives one argument, and returns its type, coded as a string. 1712It receives one argument, and returns its type, coded as a string.
1712The possible results of this function are 1713The possible results of this function are
@@ -1718,79 +1719,79 @@ The possible results of this function are
1718and \verb|"userdata"|. 1719and \verb|"userdata"|.
1719\verb|type| is equivalent to the API function \verb|lua_type|. 1720\verb|type| is equivalent to the API function \verb|lua_type|.
1720 1721
1721\subsubsection*{\ff {\tt tag (v)}}\Deffunc{tag} 1722\subsubsection*{\ff \T{tag (v)}}\Deffunc{tag}
1722This function allows Lua to test the tag of a value \see{TypesSec}. 1723This function allows Lua to test the tag of a value \see{TypesSec}.
1723It receives one argument, and returns its tag (a number). 1724It receives one argument, and returns its tag (a number).
1724\verb|tag| is equivalent to the API function \verb|lua_tag|. 1725\verb|tag| is equivalent to the API function \verb|lua_tag|.
1725 1726
1726\subsubsection*{\ff {\tt settag (t, tag)}}\Deffunc{settag} 1727\subsubsection*{\ff \T{settag (t, tag)}}\Deffunc{settag}
1727This function sets the tag of a given table \see{TypesSec}. 1728This function sets the tag of a given table \see{TypesSec}.
1728\verb|tag| must be a value created with \verb|newtag| 1729\verb|tag| must be a value created with \verb|newtag|
1729\see{pdf-newtag}. 1730\see{pdf-newtag}.
1730For security reasons, 1731For security reasons,
1731it is impossible to change the tag of a userdata from Lua. 1732it is impossible to change the tag of a userdata from Lua.
1732 1733
1733\subsubsection*{\ff {\tt assert (v)}}\Deffunc{assert} 1734\subsubsection*{\ff \T{assert (v)}}\Deffunc{assert}
1734This function issues an {\em ``assertion failed!''} error 1735This function issues an \emph{``assertion failed!''} error
1735when its argument is \nil. 1736when its argument is \nil.
1736 1737
1737\subsubsection*{\ff {\tt error (message)}}\Deffunc{error}\label{pdf-error} 1738\subsubsection*{\ff \T{error (message)}}\Deffunc{error}\label{pdf-error}
1738This function issues an error message and terminates 1739This function issues an error message and terminates
1739the last called function from the library 1740the last called function from the library
1740(\verb|lua_dofile|, \verb|lua_dostring|, or \verb|lua_callfunction|). 1741(\verb|lua_dofile|, \verb|lua_dostring|, or \verb|lua_callfunction|).
1741It never returns. 1742It never returns.
1742\verb|error| is equivalent to the API function \verb|lua_error|. 1743\verb|error| is equivalent to the API function \verb|lua_error|.
1743 1744
1744\subsubsection*{\ff {\tt rawgettable (table, index)}}\Deffunc{rawgettable} 1745\subsubsection*{\ff \T{rawgettable (table, index)}}\Deffunc{rawgettable}
1745Gets the real value of \verb|table[index]|, 1746Gets the real value of \verb|table[index]|,
1746without invoking any tag method. 1747without invoking any tag method.
1747\verb|table| must be a table, 1748\verb|table| must be a table,
1748and \verb|index| is any value different from \nil. 1749and \verb|index| is any value different from \nil.
1749 1750
1750\subsubsection*{\ff {\tt rawsettable (table, index, value)}}\Deffunc{rawsettable} 1751\subsubsection*{\ff \T{rawsettable (table, index, value)}}\Deffunc{rawsettable}
1751Sets the real value \verb|table[index]=value|, 1752Sets the real value \verb|table[index]=value|,
1752without invoking any tag method. 1753without invoking any tag method.
1753\verb|table| must be a table, 1754\verb|table| must be a table,
1754\verb|index| is any value different from \nil, 1755\verb|index| is any value different from \nil,
1755and \verb|value| is any Lua value. 1756and \verb|value| is any Lua value.
1756 1757
1757\subsubsection*{\ff {\tt rawsetglobal (name, value)}}\Deffunc{rawsetglobal} 1758\subsubsection*{\ff \T{rawsetglobal (name, value)}}\Deffunc{rawsetglobal}
1758This function assigns the given value to a global variable. 1759This function assigns the given value to a global variable.
1759The string \verb|name| does not need to be a syntactically valid variable name. 1760The string \verb|name| does not need to be a syntactically valid variable name.
1760Therefore, this function can set global variables with strange names like 1761Therefore, this function can set global variables with strange names like
1761\verb|"m v 1"| or \verb|34|. 1762\verb|"m v 1"| or \verb|34|.
1762It returns the value of its second argument. 1763It returns the value of its second argument.
1763 1764
1764\subsubsection*{\ff {\tt setglobal (name, value)}}\Deffunc{setglobal} 1765\subsubsection*{\ff \T{setglobal (name, value)}}\Deffunc{setglobal}
1765This function assigns the given value to a global variable, 1766This function assigns the given value to a global variable,
1766or calls a tag method. 1767or calls a tag method.
1767Its full semantics is explained in \See{tag-method}. 1768Its full semantics is explained in \See{tag-method}.
1768 1769
1769\subsubsection*{\ff {\tt rawgetglobal (name)}}\Deffunc{rawgetglobal} 1770\subsubsection*{\ff \T{rawgetglobal (name)}}\Deffunc{rawgetglobal}
1770This function retrieves the value of a global variable. 1771This function retrieves the value of a global variable.
1771The string \verb|name| does not need to be a 1772The string \verb|name| does not need to be a
1772syntactically valid variable name. 1773syntactically valid variable name.
1773 1774
1774\subsubsection*{\ff {\tt getglobal (name)}}\Deffunc{getglobal} 1775\subsubsection*{\ff \T{getglobal (name)}}\Deffunc{getglobal}
1775This function retrieves the value of a global variable, 1776This function retrieves the value of a global variable,
1776or calls a tag method. 1777or calls a tag method.
1777Its full semantics is explained in \See{tag-method}. 1778Its full semantics is explained in \See{tag-method}.
1778 1779
1779\subsubsection*{\ff {\tt seterrormethod (newmethod)}} 1780\subsubsection*{\ff \T{seterrormethod (newmethod)}}
1780\label{pdf-seterrormethod} 1781\label{pdf-seterrormethod}
1781Sets the error handler \see{error}. 1782Sets the error handler \see{error}.
1782\verb|newmethod| must be a function or \nil, 1783\verb|newmethod| must be a function or \nil,
1783in which case the error handler does nothing. 1784in which case the error handler does nothing.
1784Returns the old error handler. 1785Returns the old error handler.
1785 1786
1786\subsubsection*{\ff {\tt settagmethod (tag, event, newmethod)}} 1787\subsubsection*{\ff \T{settagmethod (tag, event, newmethod)}}
1787\Deffunc{settagmethod} 1788\Deffunc{settagmethod}
1788This function sets a new tag method to the given pair \M{<tag, event>}. 1789This function sets a new tag method to the given pair \M{<tag, event>}.
1789It returns the old method. 1790It returns the old method.
1790If \verb|newmethod| is \nil, 1791If \verb|newmethod| is \nil,
1791it restores the default behavior for the given event. 1792it restores the default behavior for the given event.
1792 1793
1793\subsubsection*{\ff {\tt gettagmethod (tag, event)}} 1794\subsubsection*{\ff \T{gettagmethod (tag, event)}}
1794\Deffunc{gettagmethod} 1795\Deffunc{gettagmethod}
1795This function returns the current tag method 1796This function returns the current tag method
1796for a given pair \M{<tag, event>}. 1797for a given pair \M{<tag, event>}.
@@ -1802,9 +1803,9 @@ such as finding and extracting substrings and pattern matching.
1802When indexing a string, the first character is at position~1, 1803When indexing a string, the first character is at position~1,
1803not~0, as in C. 1804not~0, as in C.
1804 1805
1805\subsubsection*{\ff {\tt strfind (str, pattern [, init [, plain]])}} 1806\subsubsection*{\ff \T{strfind (str, pattern [, init [, plain]])}}
1806\Deffunc{strfind} 1807\Deffunc{strfind}
1807This function looks for the first {\em match\/} of 1808This function looks for the first \emph{match} of
1808\verb|pattern| in \verb|str|. 1809\verb|pattern| in \verb|str|.
1809If it finds one, then it returns the indices on \verb|str| 1810If it finds one, then it returns the indices on \verb|str|
1810where this occurrence starts and ends; 1811where this occurrence starts and ends;
@@ -1818,10 +1819,10 @@ turns off the pattern matching facilities,
1818so the function does a plain ``find substring'' operation, 1819so the function does a plain ``find substring'' operation,
1819with no characters in \verb|pattern| being considered ``magic''. 1820with no characters in \verb|pattern| being considered ``magic''.
1820 1821
1821\subsubsection*{\ff {\tt strlen (s)}}\Deffunc{strlen} 1822\subsubsection*{\ff \T{strlen (s)}}\Deffunc{strlen}
1822Receives a string and returns its length. 1823Receives a string and returns its length.
1823 1824
1824\subsubsection*{\ff {\tt strsub (s, i [, j])}}\Deffunc{strsub} 1825\subsubsection*{\ff \T{strsub (s, i [, j])}}\Deffunc{strsub}
1825Returns another string, which is a substring of \verb|s|, 1826Returns another string, which is a substring of \verb|s|,
1826starting at \verb|i| and running until \verb|j|. 1827starting at \verb|i| and running until \verb|j|.
1827If \verb|i| or \verb|j| are negative, 1828If \verb|i| or \verb|j| are negative,
@@ -1837,25 +1838,25 @@ with length \verb|j|,
1837and the call \verb|strsub(s, -i)| returns a suffix of \verb|s| 1838and the call \verb|strsub(s, -i)| returns a suffix of \verb|s|
1838with length \verb|i|. 1839with length \verb|i|.
1839 1840
1840\subsubsection*{\ff {\tt strlower (s)}}\Deffunc{strlower} 1841\subsubsection*{\ff \T{strlower (s)}}\Deffunc{strlower}
1841Receives a string and returns a copy of that string with all 1842Receives a string and returns a copy of that string with all
1842upper case letters changed to lower case. 1843upper case letters changed to lower case.
1843All other characters are left unchanged. 1844All other characters are left unchanged.
1844 1845
1845\subsubsection*{\ff {\tt strupper (s)}}\Deffunc{strupper} 1846\subsubsection*{\ff \T{strupper (s)}}\Deffunc{strupper}
1846Receives a string and returns a copy of that string with all 1847Receives a string and returns a copy of that string with all
1847lower case letters changed to upper case. 1848lower case letters changed to upper case.
1848All other characters are left unchanged. 1849All other characters are left unchanged.
1849 1850
1850\subsubsection*{\ff {\tt strrep (s, n)}}\Deffunc{strrep} 1851\subsubsection*{\ff \T{strrep (s, n)}}\Deffunc{strrep}
1851Returns a string which is the concatenation of \verb|n| copies of 1852Returns a string which is the concatenation of \verb|n| copies of
1852the string \verb|s|. 1853the string \verb|s|.
1853 1854
1854\subsubsection*{\ff {\tt ascii (s [, i])}}\Deffunc{ascii} 1855\subsubsection*{\ff \T{ascii (s [, i])}}\Deffunc{ascii}
1855Returns the ASCII code of the character \verb|s[i]|. 1856Returns the ASCII code of the character \verb|s[i]|.
1856If \verb|i| is absent, then it is assumed to be 1. 1857If \verb|i| is absent, then it is assumed to be 1.
1857 1858
1858\subsubsection*{\ff {\tt format (formatstring, e1, e2, \ldots)}}\Deffunc{format} 1859\subsubsection*{\ff \T{format (formatstring, e1, e2, \ldots)}}\Deffunc{format}
1859\label{format} 1860\label{format}
1860This function returns a formated version of its variable number of arguments 1861This function returns a formated version of its variable number of arguments
1861following the description given in its first argument (which must be a string). 1862following the description given in its first argument (which must be a string).
@@ -1890,7 +1891,7 @@ the appropriate format string.
1890For example, \verb|"%*g"| can be simulated with 1891For example, \verb|"%*g"| can be simulated with
1891\verb|"%"..width.."g"|. 1892\verb|"%"..width.."g"|.
1892 1893
1893\subsubsection*{\ff {\tt gsub (s, pat, repl [, table] [, n])}} 1894\subsubsection*{\ff \T{gsub (s, pat, repl [, table] [, n])}}
1894\Deffunc{gsub} 1895\Deffunc{gsub}
1895Returns a copy of \verb|s|, 1896Returns a copy of \verb|s|,
1896where all occurrences of the pattern \verb|pat| have been 1897where all occurrences of the pattern \verb|pat| have been
@@ -1951,25 +1952,25 @@ See some examples below:
1951a \Def{character class} is used to represent a set of characters. 1952a \Def{character class} is used to represent a set of characters.
1952The following combinations are allowed in describing a character class: 1953The following combinations are allowed in describing a character class:
1953\begin{description} 1954\begin{description}
1954\item[{\em x}] (where {\em x} is any character not in the list \verb|()%.[*-?|) 1955\item[\emph{x}] (where \emph{x} is any character not in the list \verb|()%.[*-?|)
1955--- represents the character {\em x} itself. 1956--- represents the character \emph{x} itself.
1956\item[{\tt .}] --- represents all characters. 1957\item[\T{.}] --- represents all characters.
1957\item[{\tt \%a}] --- represents all letters. 1958\item[\T{\%a}] --- represents all letters.
1958\item[{\tt \%A}] --- represents all non letter characters. 1959\item[\T{\%A}] --- represents all non letter characters.
1959\item[{\tt \%d}] --- represents all digits. 1960\item[\T{\%d}] --- represents all digits.
1960\item[{\tt \%D}] --- represents all non digits. 1961\item[\T{\%D}] --- represents all non digits.
1961\item[{\tt \%l}] --- represents all lower case letters. 1962\item[\T{\%l}] --- represents all lower case letters.
1962\item[{\tt \%L}] --- represents all non lower case letter characters. 1963\item[\T{\%L}] --- represents all non lower case letter characters.
1963\item[{\tt \%s}] --- represents all space characters. 1964\item[\T{\%s}] --- represents all space characters.
1964\item[{\tt \%S}] --- represents all non space characters. 1965\item[\T{\%S}] --- represents all non space characters.
1965\item[{\tt \%u}] --- represents all upper case letters. 1966\item[\T{\%u}] --- represents all upper case letters.
1966\item[{\tt \%U}] --- represents all non upper case letter characters. 1967\item[\T{\%U}] --- represents all non upper case letter characters.
1967\item[{\tt \%w}] --- represents all alphanumeric characters. 1968\item[\T{\%w}] --- represents all alphanumeric characters.
1968\item[{\tt \%W}] --- represents all non alphanumeric characters. 1969\item[\T{\%W}] --- represents all non alphanumeric characters.
1969\item[{\tt \%\M{x}}] (where \M{x} is any non alphanumeric character) --- 1970\item[{\tt \%\M{x}}] (where \M{x} is any non alphanumeric character) ---
1970represents the character \M{x}. 1971represents the character \M{x}.
1971This is the standard way to escape the magic characters \verb|()%.[*-?|. 1972This is the standard way to escape the magic characters \verb|()%.[*-?|.
1972\item[{\tt [char-set]}] --- 1973\item[\T{[char-set]}] ---
1973Represents the class which is the union of all 1974Represents the class which is the union of all
1974characters in char-set. 1975characters in char-set.
1975To include a \verb|]| in char-set, it must be the first character. 1976To include a \verb|]| in char-set, it must be the first character.
@@ -1978,7 +1979,7 @@ separating the end characters of the range with a \verb|-|;
1978e.g., \verb|A-Z| specifies the upper case characters. 1979e.g., \verb|A-Z| specifies the upper case characters.
1979If \verb|-| appears as the first or last character of char-set, 1980If \verb|-| appears as the first or last character of char-set,
1980then it represents itself. 1981then it represents itself.
1981All classes \verb|%|{\em x} described above can also be used as 1982All classes \verb|%|\emph{x} described above can also be used as
1982components in a char-set. 1983components in a char-set.
1983All other characters in char-set represent themselves. 1984All other characters in char-set represent themselves.
1984\item[{\tt [\^{ }char-set]}] --- 1985\item[{\tt [\^{ }char-set]}] ---
@@ -2011,7 +2012,7 @@ such item matches a sub-string equal to the n-th captured string
2011\item 2012\item
2012{\tt \%b\M{xy}}, where \M{x} and \M{y} are two distinct characters; 2013{\tt \%b\M{xy}}, where \M{x} and \M{y} are two distinct characters;
2013such item matches strings that start with \M{x}, end with \M{y}, 2014such item matches strings that start with \M{x}, end with \M{y},
2014and where the \M{x} and \M{y} are {\em balanced}. 2015and where the \M{x} and \M{y} are \emph{balanced}.
2015That means that, if one reads the string from left to write, 2016That means that, if one reads the string from left to write,
2016counting plus 1 for an \M{x} and minus 1 for a \M{y}, 2017counting plus 1 for an \M{x} and minus 1 for a \M{y},
2017the ending \M{y} is the first where the count reaches 0. 2018the ending \M{y} is the first where the count reaches 0.
@@ -2030,7 +2031,7 @@ end of the subject string.
2030a pattern may contain sub-patterns enclosed in parentheses, 2031a pattern may contain sub-patterns enclosed in parentheses,
2031that describe \Def{captures}. 2032that describe \Def{captures}.
2032When a match succeeds, the sub-strings of the subject string 2033When a match succeeds, the sub-strings of the subject string
2033that match captures are stored ({\em captured\/}) for future use. 2034that match captures are stored (\emph{captured}) for future use.
2034Captures are numbered according to their left parentheses. 2035Captures are numbered according to their left parentheses.
2035For instance, in the pattern \verb|"(a*(.)%w(%s*))"|, 2036For instance, in the pattern \verb|"(a*(.)%w(%s*))"|,
2036the part of the string matching \verb|"a*(.)%w(%s*)"| is 2037the part of the string matching \verb|"a*(.)%w(%s*)"| is
@@ -2057,7 +2058,7 @@ max min mod sin sqrt tan random randomseed
2057Most of them 2058Most of them
2058are only interfaces to the homonymous functions in the C library, 2059are only interfaces to the homonymous functions in the C library,
2059except that, for the trigonometric functions, 2060except that, for the trigonometric functions,
2060all angles are expressed in {\em degrees}, not radians. 2061all angles are expressed in \emph{degrees}, not radians.
2061 2062
2062The function \verb|max| returns the maximum 2063The function \verb|max| returns the maximum
2063value of its numeric arguments. 2064value of its numeric arguments.
@@ -2093,7 +2094,7 @@ Unless otherwise stated,
2093all I/O functions return \nil\ on failure and 2094all I/O functions return \nil\ on failure and
2094some value different from \nil\ on success. 2095some value different from \nil\ on success.
2095 2096
2096\subsubsection*{\ff {\tt readfrom (filename)}}\Deffunc{readfrom} 2097\subsubsection*{\ff \T{readfrom (filename)}}\Deffunc{readfrom}
2097 2098
2098This function may be called in two ways. 2099This function may be called in two ways.
2099When called with a file name, it opens the named file, 2100When called with a file name, it opens the named file,
@@ -2111,7 +2112,7 @@ plus a string describing the error.
2111 2112
2112\begin{quotation} 2113\begin{quotation}
2113\noindent 2114\noindent
2114{\em System dependent\/}: if \verb|filename| starts with a \verb-|-, 2115\emph{System dependent}: if \verb|filename| starts with a \verb-|-,
2115then a \Index{piped input} is open, via function \IndexVerb{popen}. 2116then a \Index{piped input} is open, via function \IndexVerb{popen}.
2116Not all systems implement pipes. 2117Not all systems implement pipes.
2117Moreover, 2118Moreover,
@@ -2119,7 +2120,7 @@ the number of files that can be open at the same time is
2119usually limited and depends on the system. 2120usually limited and depends on the system.
2120\end{quotation} 2121\end{quotation}
2121 2122
2122\subsubsection*{\ff {\tt writeto (filename)}}\Deffunc{writeto} 2123\subsubsection*{\ff \T{writeto (filename)}}\Deffunc{writeto}
2123 2124
2124This function may be called in two ways. 2125This function may be called in two ways.
2125When called with a file name, 2126When called with a file name,
@@ -2128,7 +2129,7 @@ sets its handle as the value of \verb|_OUTPUT|,
2128and returns this value. 2129and returns this value.
2129It does not close the current output file. 2130It does not close the current output file.
2130Notice that, if the file already exists, 2131Notice that, if the file already exists,
2131then it will be {\em completely erased\/} with this operation. 2132then it will be \emph{completely erased} with this operation.
2132%When called with a file handle returned by a previous call, 2133%When called with a file handle returned by a previous call,
2133%it restores the file as the current output. 2134%it restores the file as the current output.
2134When called without parameters, 2135When called without parameters,
@@ -2141,7 +2142,7 @@ plus a string describing the error.
2141 2142
2142\begin{quotation} 2143\begin{quotation}
2143\noindent 2144\noindent
2144{\em System dependent\/}: if \verb|filename| starts with a \verb-|-, 2145\emph{System dependent}: if \verb|filename| starts with a \verb-|-,
2145then a \Index{piped output} is open, via function \IndexVerb{popen}. 2146then a \Index{piped output} is open, via function \IndexVerb{popen}.
2146Not all systems implement pipes. 2147Not all systems implement pipes.
2147Moreover, 2148Moreover,
@@ -2149,7 +2150,7 @@ the number of files that can be open at the same time is
2149usually limited and depends on the system. 2150usually limited and depends on the system.
2150\end{quotation} 2151\end{quotation}
2151 2152
2152\subsubsection*{\ff {\tt appendto (filename)}}\Deffunc{appendto} 2153\subsubsection*{\ff \T{appendto (filename)}}\Deffunc{appendto}
2153 2154
2154This function opens a file named \verb|filename| and sets it as the 2155This function opens a file named \verb|filename| and sets it as the
2155value of \verb|_OUTPUT|. 2156value of \verb|_OUTPUT|.
@@ -2160,25 +2161,25 @@ plus a string describing the error.
2160 2161
2161Notice that function \verb|writeto| is available to close an output file. 2162Notice that function \verb|writeto| is available to close an output file.
2162 2163
2163\subsubsection*{\ff {\tt remove (filename)}}\Deffunc{remove} 2164\subsubsection*{\ff \T{remove (filename)}}\Deffunc{remove}
2164 2165
2165This function deletes the file with the given name. 2166This function deletes the file with the given name.
2166If this function fails, it returns \nil, 2167If this function fails, it returns \nil,
2167plus a string describing the error. 2168plus a string describing the error.
2168 2169
2169\subsubsection*{\ff {\tt rename (name1, name2)}}\Deffunc{rename} 2170\subsubsection*{\ff \T{rename (name1, name2)}}\Deffunc{rename}
2170 2171
2171This function renames file named \verb|name1| to \verb|name2|. 2172This function renames file named \verb|name1| to \verb|name2|.
2172If this function fails, it returns \nil, 2173If this function fails, it returns \nil,
2173plus a string describing the error. 2174plus a string describing the error.
2174 2175
2175\subsubsection*{\ff {\tt tmpname ()}}\Deffunc{tmpname} 2176\subsubsection*{\ff \T{tmpname ()}}\Deffunc{tmpname}
2176 2177
2177This function returns a string with a file name that can safely 2178This function returns a string with a file name that can safely
2178be used for a temporary file. 2179be used for a temporary file.
2179The file must be explicitly removed when no longer needed. 2180The file must be explicitly removed when no longer needed.
2180 2181
2181\subsubsection*{\ff {\tt read ([readpattern])}}\Deffunc{read} 2182\subsubsection*{\ff \T{read ([readpattern])}}\Deffunc{read}
2182 2183
2183This function reads the file \verb|_INPUT| 2184This function reads the file \verb|_INPUT|
2184according to a read pattern, that specifies how much to read; 2185according to a read pattern, that specifies how much to read;
@@ -2186,7 +2187,7 @@ characters are read from the current input file until
2186the read pattern fails or ends. 2187the read pattern fails or ends.
2187The function \verb|read| returns a string with the characters read, 2188The function \verb|read| returns a string with the characters read,
2188even if the pattern succeeds only partially, 2189even if the pattern succeeds only partially,
2189or \nil\ if the read pattern fails {\em and\/} 2190or \nil\ if the read pattern fails \emph{and}
2190the result string would be empty. 2191the result string would be empty.
2191When called without parameters, 2192When called without parameters,
2192it uses a default pattern that reads the next line 2193it uses a default pattern that reads the next line
@@ -2206,7 +2207,7 @@ since it can match a sequence of zero characters, it never fails.%
2206\footnote{ 2207\footnote{
2207Notice that the behavior of read patterns is different from 2208Notice that the behavior of read patterns is different from
2208the regular pattern matching behavior, 2209the regular pattern matching behavior,
2209where a \verb|*| expands to the maximum length {\em such that\/} 2210where a \verb|*| expands to the maximum length \emph{such that}
2210the rest of the pattern does not fail. 2211the rest of the pattern does not fail.
2211With the read pattern behavior 2212With the read pattern behavior
2212there is no need for backtracking the reading. 2213there is no need for backtracking the reading.
@@ -2232,7 +2233,7 @@ or \nil\ on end of file.
2232or \nil\ if the next characters do not conform to an integer format. 2233or \nil\ if the next characters do not conform to an integer format.
2233\end{itemize} 2234\end{itemize}
2234 2235
2235\subsubsection*{\ff {\tt write (value1, ...)}}\Deffunc{write} 2236\subsubsection*{\ff \T{write (value1, ...)}}\Deffunc{write}
2236 2237
2237This function writes the value of each of its arguments to the 2238This function writes the value of each of its arguments to the
2238file \verb|_OUTPUT|. 2239file \verb|_OUTPUT|.
@@ -2242,7 +2243,7 @@ use \verb|tostring| or \verb|format| before \verb|write|.
2242If this function fails, it returns \nil, 2243If this function fails, it returns \nil,
2243plus a string describing the error. 2244plus a string describing the error.
2244 2245
2245\subsubsection*{\ff {\tt date ([format])}}\Deffunc{date} 2246\subsubsection*{\ff \T{date ([format])}}\Deffunc{date}
2246 2247
2247This function returns a string containing date and time 2248This function returns a string containing date and time
2248formatted according to the given string \verb|format|, 2249formatted according to the given string \verb|format|,
@@ -2251,19 +2252,19 @@ When called without arguments,
2251it returns a reasonable date and time representation that depends on 2252it returns a reasonable date and time representation that depends on
2252the host system. 2253the host system.
2253 2254
2254\subsubsection*{\ff {\tt exit ([code])}}\Deffunc{exit} 2255\subsubsection*{\ff \T{exit ([code])}}\Deffunc{exit}
2255 2256
2256This function calls the C function \verb|exit|, 2257This function calls the C function \verb|exit|,
2257with an optional \verb|code|, 2258with an optional \verb|code|,
2258to terminate the program. 2259to terminate the program.
2259The default value for \verb|code| is 1. 2260The default value for \verb|code| is 1.
2260 2261
2261\subsubsection*{\ff {\tt getenv (varname)}}\Deffunc{getenv} 2262\subsubsection*{\ff \T{getenv (varname)}}\Deffunc{getenv}
2262 2263
2263Returns the value of the environment variable \verb|varname|, 2264Returns the value of the environment variable \verb|varname|,
2264or \nil\ if the variable is not defined. 2265or \nil\ if the variable is not defined.
2265 2266
2266\subsubsection*{\ff {\tt execute (command)}}\Deffunc{execute} 2267\subsubsection*{\ff \T{execute (command)}}\Deffunc{execute}
2267 2268
2268This function is equivalent to the C function \verb|system|. 2269This function is equivalent to the C function \verb|system|.
2269It passes \verb|command| to be executed by an operating system shell. 2270It passes \verb|command| to be executed by an operating system shell.
@@ -2274,7 +2275,7 @@ It returns an error code, which is system-dependent.
2274 2275
2275Lua has no built-in debugging facilities. 2276Lua has no built-in debugging facilities.
2276Instead, it offers a special interface, 2277Instead, it offers a special interface,
2277by means of functions and {\em hooks}, 2278by means of functions and \emph{hooks},
2278which allows the construction of different 2279which allows the construction of different
2279kinds of debuggers, profilers, and other tools 2280kinds of debuggers, profilers, and other tools
2280that need ``inside information'' from the interpreter. 2281that need ``inside information'' from the interpreter.
@@ -2287,7 +2288,7 @@ is
2287\begin{verbatim} 2288\begin{verbatim}
2288lua_Function lua_stackedfunction (int level); 2289lua_Function lua_stackedfunction (int level);
2289\end{verbatim} 2290\end{verbatim}
2290It returns a handle (\verb|lua_Function|) to the {\em activation record\/} 2291It returns a handle (\verb|lua_Function|) to the \emph{activation record}
2291of the function executing at a given level. 2292of the function executing at a given level.
2292Level~0 is the current running function, 2293Level~0 is the current running function,
2293while level \Math{n+1} is the function that has called level \Math{n}. 2294while level \Math{n+1} is the function that has called level \Math{n}.
@@ -2409,12 +2410,12 @@ called simply \verb|lua|,
2409is provided with the standard distribution. 2410is provided with the standard distribution.
2410This program can be called with any sequence of the following arguments: 2411This program can be called with any sequence of the following arguments:
2411\begin{description} 2412\begin{description}
2412\item[{\tt -v}] prints version information. 2413\item[\T{-v}] prints version information.
2413\item[{\tt -}] runs interactively, accepting commands from standard input 2414\item[\T{-}] runs interactively, accepting commands from standard input
2414until an \verb|EOF|. 2415until an \verb|EOF|.
2415\item[{\tt -e stat}] executes \verb|stat| as a Lua chunk. 2416\item[\T{-e stat}] executes \verb|stat| as a Lua chunk.
2416\item[{\tt var=exp}] executes \verb|var=exp| as a Lua chunk. 2417\item[\T{var=exp}] executes \verb|var=exp| as a Lua chunk.
2417\item[{\tt filename}] executes file \verb|filename| as a Lua chunk. 2418\item[\T{filename}] executes file \verb|filename| as a Lua chunk.
2418\end{description} 2419\end{description}
2419All arguments are handled in order. 2420All arguments are handled in order.
2420For instance, an invocation like 2421For instance, an invocation like
@@ -2431,7 +2432,7 @@ For instance, a call like
2431\begin{verbatim} 2432\begin{verbatim}
2432$ lua a="name" prog.lua 2433$ lua a="name" prog.lua
2433\end{verbatim} 2434\end{verbatim}
2434will {\em not\/} set \verb|a| to the string \verb|"name"|. 2435will \emph{not} set \verb|a| to the string \verb|"name"|.
2435Instead, the quotes will be handled by the shell, 2436Instead, the quotes will be handled by the shell,
2436lua will get only \verb|a=name| to run, 2437lua will get only \verb|a=name| to run,
2437and \verb|a| will finish with \nil, 2438and \verb|a| will finish with \nil,
@@ -2448,7 +2449,7 @@ jointly with \tecgraf, used extensively early versions of
2448this system and gave valuable comments. 2449this system and gave valuable comments.
2449The authors would also like to thank Carlos Henrique Levy, 2450The authors would also like to thank Carlos Henrique Levy,
2450who found the name of the game. 2451who found the name of the game.
2451Lua means {\em moon\/} in Portuguese. 2452Lua means \emph{moon} in Portuguese.
2452 2453
2453 2454
2454 2455
@@ -2494,7 +2495,7 @@ The incompatibilities between the new and the old libraries are:
2494\item The format facility of function \verb|write| has been supersed by 2495\item The format facility of function \verb|write| has been supersed by
2495function \verb|format|; 2496function \verb|format|;
2496therefore this facility has been dropped. 2497therefore this facility has been dropped.
2497\item Function \verb|read| now uses {\em read patterns\/} to specify 2498\item Function \verb|read| now uses \emph{read patterns} to specify
2498what to read; 2499what to read;
2499this is incompatible with the old format options. 2500this is incompatible with the old format options.
2500\item Function \verb|strfind| now accepts patterns, 2501\item Function \verb|strfind| now accepts patterns,
@@ -2529,7 +2530,7 @@ The function \verb|type| now returns the string \verb|"function"|
2529both for C and Lua functions. 2530both for C and Lua functions.
2530Because Lua functions and C functions are compatible, 2531Because Lua functions and C functions are compatible,
2531this behavior is usually more useful. 2532this behavior is usually more useful.
2532When needed, the second result of function {\tt type} may be used 2533When needed, the second result of function \T{type} may be used
2533to distinguish between Lua and C functions. 2534to distinguish between Lua and C functions.
2534\item 2535\item
2535A function definition only assigns the function value to the 2536A function definition only assigns the function value to the
@@ -2550,7 +2551,7 @@ constructor (formerly \verb|@{...}|) now are both coded like
2550When the construction involves a function call, 2551When the construction involves a function call,
2551like in \verb|@func{...}|, 2552like in \verb|@func{...}|,
2552the new syntax does not use the \verb|@|. 2553the new syntax does not use the \verb|@|.
2553More important, {\em a construction function must now 2554More important, \emph{a construction function must now
2554explicitly return the constructed table}. 2555explicitly return the constructed table}.
2555\item 2556\item
2556The function \verb|lua_call| no longer has the parameter \verb|nparam|. 2557The function \verb|lua_call| no longer has the parameter \verb|nparam|.
@@ -2569,7 +2570,7 @@ int lua_storesubscript (void);
2569with the parameters explicitly pushed on the stack. 2570with the parameters explicitly pushed on the stack.
2570\item 2571\item
2571The functionality of the function \verb|lua_errorfunction| has been 2572The functionality of the function \verb|lua_errorfunction| has been
2572replaced by the {\em fallback\/} mechanism \see{error}. 2573replaced by the \emph{fallback} mechanism \see{error}.
2573\item 2574\item
2574When calling a function from the Lua library, 2575When calling a function from the Lua library,
2575parameters passed through the stack 2576parameters passed through the stack