aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-06-09 15:16:33 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-06-09 15:16:33 -0300
commita22b54bbb6a9b6a2f77d69af003f837fc553f3b3 (patch)
tree7b75a601716403e7ace4e103d7091dfcbd8d9280
parent414ebe8ce1b0263b23e0d55b62cf23499f23548b (diff)
downloadlua-a22b54bbb6a9b6a2f77d69af003f837fc553f3b3.tar.gz
lua-a22b54bbb6a9b6a2f77d69af003f837fc553f3b3.tar.bz2
lua-a22b54bbb6a9b6a2f77d69af003f837fc553f3b3.zip
format more uniform, to facilitate filters .tex->.html
-rw-r--r--manual.tex505
1 files changed, 256 insertions, 249 deletions
diff --git a/manual.tex b/manual.tex
index 15a9b1b4..532662f8 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,9 +1,10 @@
1% $Id: manual.tex,v 1.29 1997/03/06 21:13:34 roberto Exp $ 1% $Id: manual.tex,v 1.29 1997/03/06 22:19:08 roberto Exp roberto $
2 2
3\documentstyle[fullpage,11pt,bnf]{article} 3\documentstyle[fullpage,11pt,bnf]{article}
4 4
5\newcommand{\rw}[1]{{\bf #1}} 5\newcommand{\rw}[1]{{\bf #1}}
6\newcommand{\see}[1]{(see Section~\ref{#1})} 6\newcommand{\see}[1]{(see Section~\ref{#1})}
7\newcommand{\M}[1]{$#1$}
7\newcommand{\nil}{{\bf nil}} 8\newcommand{\nil}{{\bf nil}}
8\newcommand{\Line}{\rule{\linewidth}{.5mm}} 9\newcommand{\Line}{\rule{\linewidth}{.5mm}}
9\def\tecgraf{{\sf TeC\kern-.21em\lower.7ex\hbox{Graf}}} 10\def\tecgraf{{\sf TeC\kern-.21em\lower.7ex\hbox{Graf}}}
@@ -35,7 +36,7 @@ Waldemar Celes
35\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio 36\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio
36} 37}
37 38
38\date{\small \verb$Date: 1997/03/06 21:13:34 $} 39\date{\small \verb$Date: 1997/03/06 22:19:08 $}
39 40
40\maketitle 41\maketitle
41 42
@@ -163,7 +164,7 @@ The syntax%
163one or more {\em a\/}'s.} 164one or more {\em a\/}'s.}
164for chunks is: 165for chunks is:
165\begin{Produc} 166\begin{Produc}
166\produc{chunk}{\rep{statement \Or function} \opt{ret}} 167\produc{chunk}{\rep{stat \Or function} \opt{ret}}
167\end{Produc}% 168\end{Produc}%
168A chunk may contain statements and function definitions, 169A chunk may contain statements and function definitions,
169and may be in a file or in a string inside the host program. 170and may be in a file or in a string inside the host program.
@@ -208,7 +209,7 @@ functions written in C; the latter have type {\em CFunction}.
208 209
209The type {\em userdata\/} is provided to allow 210The type {\em userdata\/} is provided to allow
210arbitrary \Index{C pointers} to be stored in Lua variables. 211arbitrary \Index{C pointers} to be stored in Lua variables.
211It corresponds to \verb'void*' and has no pre-defined operations in Lua, 212It corresponds to \verb|void*| and has no pre-defined operations in Lua,
212besides assignment and equality test. 213besides assignment and equality test.
213However, by using fallbacks, the programmer may define operations 214However, by using fallbacks, the programmer may define operations
214for {\em userdata\/} values; \see{fallback}. 215for {\em userdata\/} values; \see{fallback}.
@@ -220,12 +221,12 @@ Therefore, this type may be used not only to represent ordinary arrays,
220but also symbol tables, sets, records, etc. 221but also symbol tables, sets, records, etc.
221To represent \Index{records}, Lua uses the field name as an index. 222To represent \Index{records}, Lua uses the field name as an index.
222The language supports this representation by 223The language supports this representation by
223providing \verb'a.name' as syntactic sugar for \verb'a["name"]'. 224providing \verb|a.name| as syntactic sugar for \verb|a["name"]|.
224Tables may also carry methods. 225Tables may also carry methods.
225Because functions are first class values, 226Because functions are first class values,
226table fields may contain functions. 227table fields may contain functions.
227The form \verb't:f(x)' is syntactic sugar for \verb't.f(t,x)', 228The form \verb|t:f(x)| is syntactic sugar for \verb|t.f(t,x)|,
228which calls the method \verb'f' from the table \verb't' passing 229which calls the method \verb|f| from the table \verb|t| passing
229itself as the first parameter. 230itself as the first parameter.
230 231
231It is important to notice that tables are {\em objects}, and not values. 232It is important to notice that tables are {\em objects}, and not values.
@@ -264,17 +265,17 @@ The following strings denote other \Index{tokens}:
264 265
265\Index{Literal strings} can be delimited by matching single or double quotes, 266\Index{Literal strings} can be delimited by matching single or double quotes,
266and can contain the C-like escape sequences 267and can contain the C-like escape sequences
267\verb-'\n'-, \verb-'\t'- and \verb-'\r'-. 268\verb|'\n'|, \verb|'\t'| and \verb|'\r'|.
268Literal strings can also be delimited by matching \verb'[[ ... ]]'. 269Literal strings can also be delimited by matching \verb|[[ ... ]]|.
269Literals in this bracketed form may run for several lines, 270Literals in this bracketed form may run for several lines,
270may contain nested \verb'[[ ... ]]' pairs, 271may contain nested \verb|[[ ... ]]| pairs,
271and do not interpret escape sequences. 272and do not interpret escape sequences.
272This form is specially convenient for 273This form is specially convenient for
273handling text that has quoted strings in it. 274handling text that has quoted strings in it.
274 275
275\Index{Comments} start anywhere outside a string with a 276\Index{Comments} start anywhere outside a string with a
276double hyphen (\verb'--') and run until the end of the line. 277double hyphen (\verb|--|) and run until the end of the line.
277Moreover, if the first line of a chunk file starts with \verb'#', 278Moreover, if the first line of a chunk file starts with \verb|#|,
278this line is skipped% 279this line is skipped%
279\footnote{This facility allows the use of Lua as a script interpreter 280\footnote{This facility allows the use of Lua as a script interpreter
280in Unix systems \see{lua-sa}.}. 281in Unix systems \see{lua-sa}.}.
@@ -295,8 +296,8 @@ that string to a number, following the usual rules.
295Conversely, whenever a number is used when a string is expected, 296Conversely, whenever a number is used when a string is expected,
296that number is converted to a string, according to the following rule: 297that number is converted to a string, according to the following rule:
297if the number is an integer, it is written without exponent or decimal point; 298if the number is an integer, it is written without exponent or decimal point;
298otherwise, it is formatted following the \verb'%g' 299otherwise, it is formatted following the \verb|%g|
299conversion specification of the \verb'printf' function in the 300conversion specification of the \verb|printf| function in the
300standard C library. 301standard C library.
301For complete control on how numbers are converted to strings, 302For complete control on how numbers are converted to strings,
302use the \verb|format| function \see{format}. 303use the \verb|format| function \see{format}.
@@ -365,15 +366,15 @@ Square brackets are used to index a table:
365\begin{Produc} 366\begin{Produc}
366\produc{var}{var \ter{[} exp1 \ter{]}} 367\produc{var}{var \ter{[} exp1 \ter{]}}
367\end{Produc}% 368\end{Produc}%
368If \verb'var' results in a table value, 369If \verb|var| results in a table value,
369the field indexed by the expression value gets the assigned value. 370the field indexed by the expression value gets the assigned value.
370Otherwise, the fallback {\em settable\/} is called, 371Otherwise, the fallback {\em settable\/} is called,
371with three parameters: the value of \verb'var', 372with three parameters: the value of \verb|var|,
372the value of expression, and the value being assigned to it; 373the value of expression, and the value being assigned to it;
373\see{fallback}. 374\see{fallback}.
374 375
375The syntax \verb'var.NAME' is just syntactic sugar for 376The syntax \verb|var.NAME| is just syntactic sugar for
376\verb'var["NAME"]': 377\verb|var["NAME"]|:
377\begin{Produc} 378\begin{Produc}
378\produc{var}{var \ter{.} name} 379\produc{var}{var \ter{.} name}
379\end{Produc}% 380\end{Produc}%
@@ -398,7 +399,7 @@ A {\tt return} is used to return values from a function or a chunk.
398Because they may return more than one value, 399Because they may return more than one value,
399the syntax for a \Index{return statement} is: 400the syntax for a \Index{return statement} is:
400\begin{Produc} 401\begin{Produc}
401\produc{ret}{\rwd{return} explist \opt{sc}} 402\produc{ret}{\rwd{return} \opt{explist1} \opt{sc}}
402\end{Produc} 403\end{Produc}
403 404
404\subsubsection{Function Calls as Statements} \label{funcstat} 405\subsubsection{Function Calls as Statements} \label{funcstat}
@@ -440,14 +441,20 @@ Numbers (numerical constants) and
440string literals are explained in Section~\ref{lexical}. 441string literals are explained in Section~\ref{lexical}.
441Variables are explained in Section~\ref{assignment}. 442Variables are explained in Section~\ref{assignment}.
442 443
444The non-terminal \verb|exp1| is used to indicate that the values
445returned by an expression must be adjusted to one single value:
446\begin{Produc}
447\produc{exp1}{exp}
448\end{Produc}
449
443\subsubsection{Arithmetic Operators} 450\subsubsection{Arithmetic Operators}
444Lua supports the usual \Index{arithmetic operators}. 451Lua supports the usual \Index{arithmetic operators}.
445These operators are the binary 452These operators are the binary
446\verb'+' (addition), 453\verb|+| (addition),
447\verb'-' (subtraction), 454\verb|-| (subtraction),
448\verb'*' (multiplication), 455\verb|*| (multiplication),
449\verb'/' (division) and \verb'^' (exponentiation), 456\verb|/| (division) and \verb|^| (exponentiation),
450and the unary \verb'-' (negation). 457and the unary \verb|-| (negation).
451If the operands are numbers, or strings that can be converted to 458If the operands are numbers, or strings that can be converted to
452numbers, according to the rules given in Section~\ref{coercion}, 459numbers, according to the rules given in Section~\ref{coercion},
453then all operations except exponentiation have the usual meaning. 460then all operations except exponentiation have the usual meaning.
@@ -471,7 +478,7 @@ Otherwise, their values are compared.
471Numbers and strings are compared in the usual way. 478Numbers and strings are compared in the usual way.
472Tables, CFunctions, and functions are compared by reference, 479Tables, CFunctions, and functions are compared by reference,
473that is, two tables are considered equal only if they are the same table. 480that is, two tables are considered equal only if they are the same table.
474The operator \verb'~=' is exactly the negation of equality (\verb'=='). 481The operator \verb|~=| is exactly the negation of equality (\verb|==|).
475Note that the conversion rules of Section~\ref{coercion} 482Note that the conversion rules of Section~\ref{coercion}
476do not apply to equality comparisons. 483do not apply to equality comparisons.
477Thus, \verb|"0"==0| evaluates to false. 484Thus, \verb|"0"==0| evaluates to false.
@@ -493,12 +500,12 @@ The \Index{logical operators} are:
493\begin{verbatim} 500\begin{verbatim}
494 and or not 501 and or not
495\end{verbatim} 502\end{verbatim}
496The operator \verb'and' returns \nil\ if its first argument is \nil; 503The operator \verb|and| returns \nil\ if its first argument is \nil;
497otherwise it returns its second argument. 504otherwise it returns its second argument.
498The operator \verb'or' returns its first argument 505The operator \verb|or| returns its first argument
499if it is different from \nil; 506if it is different from \nil;
500otherwise it returns its second argument. 507otherwise it returns its second argument.
501Both \verb'and' and \verb'or' use \Index{short-cut evaluation}, 508Both \verb|and| and \verb|or| use \Index{short-cut evaluation},
502that is, 509that is,
503the second operand is evaluated only if necessary. 510the second operand is evaluated only if necessary.
504 511
@@ -522,7 +529,7 @@ from the lower to the higher priority:
522 ^ 529 ^
523\end{verbatim} 530\end{verbatim}
524All binary operators are left associative, 531All binary operators are left associative,
525except for \verb'^' (exponentiation), 532except for \verb|^| (exponentiation),
526which is right associative. 533which is right associative.
527 534
528\subsubsection{Table Constructors} \label{tableconstructor} 535\subsubsection{Table Constructors} \label{tableconstructor}
@@ -581,11 +588,11 @@ A \Index{function call} has the following syntax:
581\begin{Produc} 588\begin{Produc}
582\produc{functioncall}{var realParams} 589\produc{functioncall}{var realParams}
583\end{Produc}% 590\end{Produc}%
584Here, \verb'var' can be any variable (global, local, indexed, etc). 591Here, \verb|var| can be any variable (global, local, indexed, etc).
585If its value has type {\em function\/} or {\em CFunction}, 592If its value has type {\em function\/} or {\em CFunction},
586then this function is called. 593then this function is called.
587Otherwise, the ``function'' fallback is called, 594Otherwise, the ``function'' fallback is called,
588having as first parameter the value of \verb'var', 595having as first parameter the value of \verb|var|,
589and then the original call parameters. 596and then the original call parameters.
590 597
591The form: 598The form:
@@ -593,12 +600,12 @@ The form:
593\produc{functioncall}{var \ter{:} name realParams} 600\produc{functioncall}{var \ter{:} name realParams}
594\end{Produc}% 601\end{Produc}%
595can be used to call ``methods''. 602can be used to call ``methods''.
596A call \verb'var:name(...)' 603A call \verb|var:name(...)|
597is syntactic sugar for 604is syntactic sugar for
598\begin{verbatim} 605\begin{verbatim}
599 var.name(var, ...) 606 var.name(var, ...)
600\end{verbatim} 607\end{verbatim}
601except that \verb'var' is evaluated only once. 608except that \verb|var| is evaluated only once.
602 609
603\begin{Produc} 610\begin{Produc}
604\produc{realParams}{\ter{(} \opt{explist1} \ter{)}} 611\produc{realParams}{\ter{(} \opt{explist1} \ter{)}}
@@ -609,8 +616,8 @@ All argument expressions are evaluated before the call;
609then the list of \Index{arguments} is adjusted to 616then the list of \Index{arguments} is adjusted to
610the length of the list of parameters \see{adjust}; 617the length of the list of parameters \see{adjust};
611finally, this list is assigned to the formal parameters. 618finally, this list is assigned to the formal parameters.
612A call of the form \verb'f{...}' is syntactic sugar for 619A call of the form \verb|f{...}| is syntactic sugar for
613\verb'f({...})', that is, 620\verb|f({...})|, that is,
614the parameter list is a single new table. 621the parameter list is a single new table.
615 622
616Because a function can return any number of results 623Because a function can return any number of results
@@ -620,12 +627,12 @@ If the function is called as a statement \see{funcstat},
620its return list is adjusted to 0, 627its return list is adjusted to 0,
621thus discarding all returned values. 628thus discarding all returned values.
622If the function is called in a place that needs a single value 629If the function is called in a place that needs a single value
623(syntactically denoted by the non-terminal \verb'exp1'), 630(syntactically denoted by the non-terminal \verb|exp1|),
624then its return list is adjusted to 1, 631then its return list is adjusted to 1,
625thus discarding all returned values, 632thus discarding all returned values,
626except the first one. 633except the first one.
627If the function is called in a place that can hold many values 634If the function is called in a place that can hold many values
628(syntactically denoted by the non-terminal \verb'exp'), 635(syntactically denoted by the non-terminal \verb|exp|),
629then no adjustment is made. 636then no adjustment is made.
630 637
631 638
@@ -642,7 +649,7 @@ When Lua pre-compiles a chunk,
642all its function bodies are pre-compiled, too. 649all its function bodies are pre-compiled, too.
643Then, when Lua ``executes'' the function definition, 650Then, when Lua ``executes'' the function definition,
644its body is stored, with type {\em function}, 651its body is stored, with type {\em function},
645into the variable \verb'var'. 652into the variable \verb|var|.
646It is in this sense that 653It is in this sense that
647a function definition is an assignment to a global variable. 654a function definition is an assignment to a global variable.
648 655
@@ -652,7 +659,7 @@ initialized with the argument values.
652\produc{parlist1}{name \rep{\ter{,} name}} 659\produc{parlist1}{name \rep{\ter{,} name}}
653\end{Produc} 660\end{Produc}
654 661
655Results are returned using the \verb'return' statement \see{return}. 662Results are returned using the \verb|return| statement \see{return}.
656If control reaches the end of a function without a return instruction, 663If control reaches the end of a function without a return instruction,
657then the function returns with no results. 664then the function returns with no results.
658 665
@@ -674,9 +681,9 @@ function v.f (self, ...)
674 ... 681 ...
675end 682end
676\end{verbatim} 683\end{verbatim}
677that is, the function gets an extra formal parameter called \verb'self'. 684that is, the function gets an extra formal parameter called \verb|self|.
678Notice that 685Notice that
679the variable \verb'v' must have been previously initialized with a table value. 686the variable \verb|v| must have been previously initialized with a table value.
680 687
681 688
682\subsection{Fallbacks} \label{fallback} 689\subsection{Fallbacks} \label{fallback}
@@ -691,7 +698,7 @@ identified by the given strings:
691\begin{description} 698\begin{description}
692\item[``arith'':]\index{arithmetic fallback} 699\item[``arith'':]\index{arithmetic fallback}
693called when an arithmetic operation is applied to non numerical operands, 700called when an arithmetic operation is applied to non numerical operands,
694or when the binary \verb'^' operation (exponentiation) is called. 701or when the binary \verb|^| operation (exponentiation) is called.
695It receives three arguments: 702It receives three arguments:
696the two operands (the second one is \nil\ when the operation is unary minus) 703the two operands (the second one is \nil\ when the operation is unary minus)
697and one of the following strings describing the offended operator: 704and one of the following strings describing the offended operator:
@@ -774,8 +781,8 @@ all Lua actions start from C code calling a function from the Lua library.
774Whenever an error occurs during Lua compilation or execution, 781Whenever an error occurs during Lua compilation or execution,
775the ``error'' fallback function is called, 782the ``error'' fallback function is called,
776and then the corresponding function from the library 783and then the corresponding function from the library
777(\verb'lua_dofile', \verb'lua_dostring', 784(\verb|lua_dofile|, \verb|lua_dostring|,
778\verb'lua_call', or \verb'lua_callfunction') 785\verb|lua_call|, or \verb|lua_callfunction|)
779is terminated returning an error condition. 786is terminated returning an error condition.
780 787
781The only argument to the ``error'' fallback function is a string 788The only argument to the ``error'' fallback function is a string
@@ -785,7 +792,7 @@ using the debug facilities \see{debugI},
785in order to print some extra information, 792in order to print some extra information,
786like the call stack. 793like the call stack.
787To provide more information about errors, 794To provide more information about errors,
788Lua programs can include the compilation pragma \verb'$debug'. 795Lua programs can include the compilation pragma \verb|$debug|.
789\index{debug pragma}\label{pragma} 796\index{debug pragma}\label{pragma}
790This pragma must be written in a line by itself. 797This pragma must be written in a line by itself.
791When an error occurs in a program compiled with this option, 798When an error occurs in a program compiled with this option,
@@ -795,7 +802,7 @@ If needed, it is possible to change the ``error'' fallback handler
795\see{fallback}. 802\see{fallback}.
796 803
797Lua code can explicitly generate an error by calling the built-in 804Lua code can explicitly generate an error by calling the built-in
798function \verb'error' \see{pdf-error}. 805function \verb|error| \see{pdf-error}.
799 806
800 807
801\section{The Application Program Interface} 808\section{The Application Program Interface}
@@ -813,18 +820,18 @@ The API functions can be classified in the following categories:
813\item manipulating references to Lua Objects. 820\item manipulating references to Lua Objects.
814\end{enumerate} 821\end{enumerate}
815All API functions and related types and constants 822All API functions and related types and constants
816are declared in the header file \verb'lua.h'. 823are declared in the header file \verb|lua.h|.
817 824
818\subsection{Exchanging Values between C and Lua} \label{valuesCLua} 825\subsection{Exchanging Values between C and Lua} \label{valuesCLua}
819Because Lua has no static type system, 826Because Lua has no static type system,
820all values passed between Lua and C have type 827all values passed between Lua and C have type
821\verb'lua_Object'\Deffunc{lua_Object}, 828\verb|lua_Object|\Deffunc{lua_Object},
822which works like an abstract type in C that can hold any Lua value. 829which works like an abstract type in C that can hold any Lua value.
823Values of type \verb'lua_Object' have no meaning outside Lua; 830Values of type \verb|lua_Object| have no meaning outside Lua;
824for instance, 831for instance,
825the comparisson of two \verb"lua_Object's" is undefined. 832the comparisson of two \verb|lua_Object's| is undefined.
826 833
827To check the type of a \verb'lua_Object', 834To check the type of a \verb|lua_Object|,
828the following function is available: 835the following function is available:
829\Deffunc{lua_type} 836\Deffunc{lua_type}
830\begin{verbatim} 837\begin{verbatim}
@@ -845,14 +852,14 @@ int lua_isuserdata (lua_Object object);
845\end{verbatim} 852\end{verbatim}
846All macros return 1 if the object is compatible with the given type, 853All macros return 1 if the object is compatible with the given type,
847and 0 otherwise. 854and 0 otherwise.
848The function \verb'lua_isnumber' accepts numbers and numerical strings, 855The function \verb|lua_isnumber| accepts numbers and numerical strings,
849whereas 856whereas
850\verb'lua_isstring' accepts strings and numbers \see{coercion}, 857\verb|lua_isstring| accepts strings and numbers \see{coercion},
851and \verb'lua_isfunction' accepts Lua and C functions. 858and \verb|lua_isfunction| accepts Lua and C functions.
852The function \verb'lua_type' can be used to distinguish between 859The function \verb|lua_type| can be used to distinguish between
853different kinds of user data. 860different kinds of user data.
854 861
855To translate a value from type \verb'lua_Object' to a specific C type, 862To translate a value from type \verb|lua_Object| to a specific C type,
856the programmer can use: 863the programmer can use:
857\Deffunc{lua_getnumber}\Deffunc{lua_getstring} 864\Deffunc{lua_getnumber}\Deffunc{lua_getstring}
858\Deffunc{lua_getcfunction}\Deffunc{lua_getuserdata} 865\Deffunc{lua_getcfunction}\Deffunc{lua_getuserdata}
@@ -862,35 +869,35 @@ char *lua_getstring (lua_Object object);
862lua_CFunction lua_getcfunction (lua_Object object); 869lua_CFunction lua_getcfunction (lua_Object object);
863void *lua_getuserdata (lua_Object object); 870void *lua_getuserdata (lua_Object object);
864\end{verbatim} 871\end{verbatim}
865\verb'lua_getnumber' converts a \verb'lua_Object' to a floating-point number. 872\verb|lua_getnumber| converts a \verb|lua_Object| to a floating-point number.
866This \verb'lua_Object' must be a number or a string convertible to number 873This \verb|lua_Object| must be a number or a string convertible to number
867\see{coercion}; otherwise, the function returns 0. 874\see{coercion}; otherwise, the function returns 0.
868 875
869\verb'lua_getstring' converts a \verb'lua_Object' to a string (\verb'char *'). 876\verb|lua_getstring| converts a \verb|lua_Object| to a string (\verb|char *|).
870This \verb'lua_Object' must be a string or a number; 877This \verb|lua_Object| must be a string or a number;
871otherwise, the function returns 0 (the \verb|NULL| pointer). 878otherwise, the function returns 0 (the \verb|NULL| pointer).
872This function does not create a new string, but returns a pointer to 879This function does not create a new string, but returns a pointer to
873a string inside the Lua environment. 880a string inside the Lua environment.
874Because Lua has garbage collection, there is no guarantee that such 881Because Lua has garbage collection, there is no guarantee that such
875pointer will be valid after the block ends. 882pointer will be valid after the block ends.
876 883
877\verb'lua_getcfunction' converts a \verb'lua_Object' to a C function. 884\verb|lua_getcfunction| converts a \verb|lua_Object| to a C function.
878This \verb'lua_Object' must have type {\em CFunction\/}; 885This \verb|lua_Object| must have type {\em CFunction\/};
879otherwise, the function returns 0 (the \verb|NULL| pointer). 886otherwise, the function returns 0 (the \verb|NULL| pointer).
880The type \verb'lua_CFunction' is explained in Section~\ref{LuacallC}. 887The type \verb|lua_CFunction| is explained in Section~\ref{LuacallC}.
881 888
882\verb'lua_getuserdata' converts a \verb'lua_Object' to \verb'void*'. 889\verb|lua_getuserdata| converts a \verb|lua_Object| to \verb|void*|.
883This \verb'lua_Object' must have type {\em userdata\/}; 890This \verb|lua_Object| must have type {\em userdata\/};
884otherwise, the function returns 0 (the \verb|NULL| pointer). 891otherwise, the function returns 0 (the \verb|NULL| pointer).
885 892
886Because Lua has automatic memory management and garbage collection, 893Because Lua has automatic memory management and garbage collection,
887a \verb'lua_Object' has a limited scope, 894a \verb|lua_Object| has a limited scope,
888and is only valid inside the {\em block\/} where it was created. 895and is only valid inside the {\em block\/} where it was created.
889A C function called from Lua is a block, 896A C function called from Lua is a block,
890and its parameters are valid only until its end. 897and its parameters are valid only until its end.
891It is good programming practice to convert Lua objects to C values 898It is good programming practice to convert Lua objects to C values
892as soon as they are available, 899as soon as they are available,
893and never to store \verb'lua_Object's in C global variables. 900and never to store \verb|lua_Object|s in C global variables.
894 901
895 902
896All comunication between Lua and C is done through two 903All comunication between Lua and C is done through two
@@ -908,10 +915,10 @@ which can be indexed with the function:
908\begin{verbatim} 915\begin{verbatim}
909lua_Object lua_lua2C (int number); 916lua_Object lua_lua2C (int number);
910\end{verbatim} 917\end{verbatim}
911where \verb'number' starts with 1. 918where \verb|number| starts with 1.
912When called with a number larger than the array size, 919When called with a number larger than the array size,
913this function returns 920this function returns
914\verb'LUA_NOOBJECT'\Deffunc{LUA_NOOBJECT}. 921\verb|LUA_NOOBJECT|\Deffunc{LUA_NOOBJECT}.
915In this way, it is possible to write C functions that receive 922In this way, it is possible to write C functions that receive
916a variable number of parameters, 923a variable number of parameters,
917and to call Lua functions that return a variable number of results. 924and to call Lua functions that return a variable number of results.
@@ -936,14 +943,14 @@ plus the macro:
936void lua_pushuserdata (void *u); 943void lua_pushuserdata (void *u);
937\end{verbatim} 944\end{verbatim}
938All of them receive a C value, 945All of them receive a C value,
939convert it to a corresponding \verb'lua_Object', 946convert it to a corresponding \verb|lua_Object|,
940and leave the result on the top of C2lua. 947and leave the result on the top of C2lua.
941 948
942User data can have different tags, 949User data can have different tags,
943whose semantics are only known to the host program. 950whose semantics are only known to the host program.
944Any positive integer can be used to tag a user datum. 951Any positive integer can be used to tag a user datum.
945When a user datum is retrieved, 952When a user datum is retrieved,
946the function \verb'lua_type' can be used to get its tag. 953the function \verb|lua_type| can be used to get its tag.
947 954
948{\em Please note:} most functions in the Lua API 955{\em Please note:} most functions in the Lua API
949use the structures lua2C and C2lua, 956use the structures lua2C and C2lua,
@@ -968,7 +975,7 @@ void lua_beginblock (void);
968void lua_endblock (void); 975void lua_endblock (void);
969\end{verbatim} 976\end{verbatim}
970After the end of the block, 977After the end of the block,
971all \verb'lua_Object''s created inside it are released. 978all \verb|lua_Object|'s created inside it are released.
972The use of explicit nested blocks is strongly encouraged. 979The use of explicit nested blocks is strongly encouraged.
973 980
974\subsection{Executing Lua Code} 981\subsection{Executing Lua Code}
@@ -981,11 +988,11 @@ int lua_dostring (char *string);
981\end{verbatim} 988\end{verbatim}
982Both functions return an error code: 989Both functions return an error code:
9830, in case of success; non zero, in case of errors. 9900, in case of success; non zero, in case of errors.
984More specifically, \verb'lua_dofile' returns 2 if for any reason 991More specifically, \verb|lua_dofile| returns 2 if for any reason
985it could not open the file. 992it could not open the file.
986The function \verb'lua_dofile', if called with argument \verb'NULL', 993The function \verb|lua_dofile|, if called with argument \verb|NULL|,
987executes the \verb|stdin| stream. 994executes the \verb|stdin| stream.
988Function \verb'lua_dofile' is also able to execute pre-compiled chunks. 995Function \verb|lua_dofile| is also able to execute pre-compiled chunks.
989It automatically detects whether the file is text or binary, 996It automatically detects whether the file is text or binary,
990and loads it accordingly (see program \IndexVerb{luac}). 997and loads it accordingly (see program \IndexVerb{luac}).
991These functions also return, in structure lua2C, 998These functions also return, in structure lua2C,
@@ -1044,8 +1051,8 @@ Because other functions also use this stack,
1044it is important that these 1051it is important that these
1045parameters be pushed just before the corresponding call, 1052parameters be pushed just before the corresponding call,
1046without intermediate calls to the Lua library. 1053without intermediate calls to the Lua library.
1047For instance, suppose the user wants the value of \verb'a[i]', 1054For instance, suppose the user wants the value of \verb|a[i]|,
1048where \verb'a' and \verb'i' are global Lua variables. 1055where \verb|a| and \verb|i| are global Lua variables.
1049A simplistic solution would be: 1056A simplistic solution would be:
1050\begin{verbatim} 1057\begin{verbatim}
1051 /* Warning: WRONG CODE */ 1058 /* Warning: WRONG CODE */
@@ -1055,7 +1062,7 @@ A simplistic solution would be:
1055 result = lua_getsubscript(); 1062 result = lua_getsubscript();
1056\end{verbatim} 1063\end{verbatim}
1057This code is incorrect because 1064This code is incorrect because
1058the call \verb'lua_getglobal("i")' modifies the stack, 1065the call \verb|lua_getglobal("i")| modifies the stack,
1059and invalidates the previous pushed value. 1066and invalidates the previous pushed value.
1060A correct solution could be: 1067A correct solution could be:
1061\begin{verbatim} 1068\begin{verbatim}
@@ -1068,7 +1075,7 @@ A correct solution could be:
1068 1075
1069\subsection{Calling Lua Functions} 1076\subsection{Calling Lua Functions}
1070Functions defined in Lua by a chunk executed with 1077Functions defined in Lua by a chunk executed with
1071\verb'dofile' or \verb'dostring' can be called from the host program. 1078\verb|dofile| or \verb|dostring| can be called from the host program.
1072This is done using the following protocol: 1079This is done using the following protocol:
1073first, the arguments to the function are pushed onto C2lua 1080first, the arguments to the function are pushed onto C2lua
1074\see{pushing}, in direct order, i.e., the first argument is pushed first. 1081\see{pushing}, in direct order, i.e., the first argument is pushed first.
@@ -1104,7 +1111,7 @@ The following example shows how a C program may call the
1104\end{verbatim} 1111\end{verbatim}
1105 1112
1106Two special Lua functions have exclusive interfaces: 1113Two special Lua functions have exclusive interfaces:
1107\verb'error' and \verb'setfallback'. 1114\verb|error| and \verb|setfallback|.
1108A C function can generate a Lua error calling the function 1115A C function can generate a Lua error calling the function
1109\Deffunc{lua_error} 1116\Deffunc{lua_error}
1110\begin{verbatim} 1117\begin{verbatim}
@@ -1124,7 +1131,7 @@ lua_Object lua_setfallback (char *name, lua_CFunction fallback);
1124\end{verbatim} 1131\end{verbatim}
1125The first parameter is the fallback name \see{fallback}, 1132The first parameter is the fallback name \see{fallback},
1126and the second is a CFunction to be used as the new fallback. 1133and the second is a CFunction to be used as the new fallback.
1127This function returns a \verb'lua_Object', 1134This function returns a \verb|lua_Object|,
1128which is the old fallback value, 1135which is the old fallback value,
1129or \nil\ on failure (invalid fallback name). 1136or \nil\ on failure (invalid fallback name).
1130This old value can be used for chaining fallbacks. 1137This old value can be used for chaining fallbacks.
@@ -1141,7 +1148,7 @@ there is the following macro:
1141\end{verbatim} 1148\end{verbatim}
1142which receives the name the function will have in Lua, 1149which receives the name the function will have in Lua,
1143and a pointer to the function. 1150and a pointer to the function.
1144This pointer must have type \verb'lua_CFunction', 1151This pointer must have type \verb|lua_CFunction|,
1145which is defined as 1152which is defined as
1146\Deffunc{lua_CFunction} 1153\Deffunc{lua_CFunction}
1147\begin{verbatim} 1154\begin{verbatim}
@@ -1198,8 +1205,8 @@ For more examples, see files \verb|strlib.c|,
1198 1205
1199\subsection{References to Lua Objects} 1206\subsection{References to Lua Objects}
1200 1207
1201As noted in Section~\ref{LuacallC}, \verb'lua_Object's are volatile. 1208As noted in Section~\ref{LuacallC}, \verb|lua_Object|s are volatile.
1202If the C code needs to keep a \verb'lua_Object' 1209If the C code needs to keep a \verb|lua_Object|
1203outside block boundaries, 1210outside block boundaries,
1204it must create a \Def{reference} to the object. 1211it must create a \Def{reference} to the object.
1205The routines to manipulate references are the following: 1212The routines to manipulate references are the following:
@@ -1211,22 +1218,22 @@ lua_Object lua_getref (int ref);
1211void lua_pushref (int ref); 1218void lua_pushref (int ref);
1212void lua_unref (int ref); 1219void lua_unref (int ref);
1213\end{verbatim} 1220\end{verbatim}
1214The function \verb'lua_ref' creates a reference 1221The function \verb|lua_ref| creates a reference
1215to the object that is on the top of the stack, 1222to the object that is on the top of the stack,
1216and returns this reference. 1223and returns this reference.
1217If \verb'lock' is true, the object is {\em locked\/}: 1224If \verb|lock| is true, the object is {\em locked\/}:
1218this means the object will not be garbage collected. 1225this means the object will not be garbage collected.
1219Notice that an unlocked reference may be garbage collected. 1226Notice that an unlocked reference may be garbage collected.
1220Whenever the referenced object is needed, 1227Whenever the referenced object is needed,
1221a call to \verb'lua_getref' 1228a call to \verb|lua_getref|
1222returns a handle to it, 1229returns a handle to it,
1223whereas \verb'lua_pushref' pushes the object on the stack. 1230whereas \verb|lua_pushref| pushes the object on the stack.
1224If the object has been collected, 1231If the object has been collected,
1225then \verb'lua_getref' returns \verb'LUA_NOOBJECT', 1232then \verb|lua_getref| returns \verb|LUA_NOOBJECT|,
1226and \verb'lua_pushobject' issues an error. 1233and \verb|lua_pushobject| issues an error.
1227 1234
1228When a reference is no longer needed, 1235When a reference is no longer needed,
1229it can be freed with a call to \verb'lua_unref'. 1236it can be freed with a call to \verb|lua_unref|.
1230 1237
1231The function \verb|lua_pushref| does not corrupt the 1238The function \verb|lua_pushref| does not corrupt the
1232structures lua2C and C2lua, and therefore is safe to 1239structures lua2C and C2lua, and therefore is safe to
@@ -1255,8 +1262,8 @@ Currently there are three standard libraries:
1255\end{itemize} 1262\end{itemize}
1256In order to have access to these libraries, 1263In order to have access to these libraries,
1257the host program must call the functions 1264the host program must call the functions
1258\verb-strlib_open-, \verb-mathlib_open-, and \verb-iolib_open-, 1265\verb|strlib_open|, \verb|mathlib_open|, and \verb|iolib_open|,
1259declared in \verb-lualib.h-. 1266declared in \verb|lualib.h|.
1260 1267
1261 1268
1262\subsection{Predefined Functions} 1269\subsection{Predefined Functions}
@@ -1266,7 +1273,7 @@ This function receives a file name,
1266opens it, and executes its contents as a Lua chunk, 1273opens it, and executes its contents as a Lua chunk,
1267or as pre-compiled chunks. 1274or as pre-compiled chunks.
1268When called without arguments, 1275When called without arguments,
1269it executes the contents of the standard input (\verb'stdin'). 1276it executes the contents of the standard input (\verb|stdin|).
1270If there is any error executing the file, it returns \nil. 1277If there is any error executing the file, it returns \nil.
1271Otherwise, it returns the values returned by the chunk, 1278Otherwise, it returns the values returned by the chunk,
1272or a non \nil\ value if the chunk returns no values. 1279or a non \nil\ value if the chunk returns no values.
@@ -1304,11 +1311,11 @@ the semantics of \verb|next| is undefined.
1304This function cannot be written with the standard API. 1311This function cannot be written with the standard API.
1305 1312
1306\subsubsection*{\ff{\tt nextvar (name)}}\Deffunc{nextvar} 1313\subsubsection*{\ff{\tt nextvar (name)}}\Deffunc{nextvar}
1307This function is similar to the function \verb'next', 1314This function is similar to the function \verb|next|,
1308but iterates over the global variables. 1315but iterates over the global variables.
1309Its single argument is the name of a global variable, 1316Its single argument is the name of a global variable,
1310or \nil\ to get a first name. 1317or \nil\ to get a first name.
1311Similarly to \verb'next', it returns the name of another variable 1318Similarly to \verb|next|, it returns the name of another variable
1312and its value, 1319and its value,
1313or \nil\ if there are no more variables. 1320or \nil\ if there are no more variables.
1314There can be no assignments to global variables during the traversal; 1321There can be no assignments to global variables during the traversal;
@@ -1340,12 +1347,12 @@ otherwise, it returns \nil.
1340This function allows Lua to test the type of a value. 1347This function allows Lua to test the type of a value.
1341It receives one argument, and returns its type, coded as a string. 1348It receives one argument, and returns its type, coded as a string.
1342The possible results of this function are 1349The possible results of this function are
1343\verb'"nil"' (a string, not the value \nil), 1350\verb|"nil"| (a string, not the value \nil),
1344\verb'"number"', 1351\verb|"number"|,
1345\verb'"string"', 1352\verb|"string"|,
1346\verb'"table"', 1353\verb|"table"|,
1347\verb'"function"' (returned both for C functions and Lua functions), 1354\verb|"function"| (returned both for C functions and Lua functions),
1348and \verb'"userdata"'. 1355and \verb|"userdata"|.
1349 1356
1350Besides this string, the function returns a second result, 1357Besides this string, the function returns a second result,
1351which is the \Def{tag} of the value. 1358which is the \Def{tag} of the value.
@@ -1362,21 +1369,21 @@ when its argument is \nil.
1362\subsubsection*{\ff{\tt error (message)}}\Deffunc{error}\label{pdf-error} 1369\subsubsection*{\ff{\tt error (message)}}\Deffunc{error}\label{pdf-error}
1363This function issues an error message and terminates 1370This function issues an error message and terminates
1364the last called function from the library 1371the last called function from the library
1365(\verb'lua_dofile', \verb'lua_dostring', \ldots). 1372(\verb|lua_dofile|, \verb|lua_dostring|, \ldots).
1366It never returns. 1373It never returns.
1367\verb|error| is simply an interface to \verb|lua_error|. 1374\verb|error| is simply an interface to \verb|lua_error|.
1368 1375
1369\subsubsection*{\ff{\tt setglobal (name, value)}}\Deffunc{setglobal} 1376\subsubsection*{\ff{\tt setglobal (name, value)}}\Deffunc{setglobal}
1370This function assigns the given value to a global variable. 1377This function assigns the given value to a global variable.
1371The string \verb'name' does not need to be a syntactically valid variable name. 1378The string \verb|name| does not need to be a syntactically valid variable name.
1372Therefore, this function can set global variables with strange names like 1379Therefore, this function can set global variables with strange names like
1373\verb|`m v 1'| or \verb'34'. 1380\verb|`m v 1'| or \verb|34|.
1374It returns the value of its second argument. 1381It returns the value of its second argument.
1375\verb|setglobal| is simply an interface to \verb|lua_storeglobal|. 1382\verb|setglobal| is simply an interface to \verb|lua_storeglobal|.
1376 1383
1377\subsubsection*{\ff{\tt getglobal (name)}}\Deffunc{getglobal} 1384\subsubsection*{\ff{\tt getglobal (name)}}\Deffunc{getglobal}
1378This function retrieves the value of a global variable. 1385This function retrieves the value of a global variable.
1379The string \verb'name' does not need to be a syntactically valid variable name. 1386The string \verb|name| does not need to be a syntactically valid variable name.
1380 1387
1381\subsubsection*{\ff{\tt setfallback (fallbackname, newfallback)}} 1388\subsubsection*{\ff{\tt setfallback (fallbackname, newfallback)}}
1382\Deffunc{setfallback} 1389\Deffunc{setfallback}
@@ -1393,8 +1400,8 @@ not 0, as in C.
1393\subsubsection*{\ff{\tt strfind (str, pattern [, init [, plain]])}} 1400\subsubsection*{\ff{\tt strfind (str, pattern [, init [, plain]])}}
1394\Deffunc{strfind} 1401\Deffunc{strfind}
1395This function looks for the first {\em match\/} of 1402This function looks for the first {\em match\/} of
1396\verb-pattern- in \verb-str-. 1403\verb|pattern| in \verb|str|.
1397If it finds one, then it returns the indices on \verb-str- 1404If it finds one, then it returns the indices on \verb|str|
1398where this occurence starts and ends; 1405where this occurence starts and ends;
1399otherwise, it returns \nil. 1406otherwise, it returns \nil.
1400If the pattern specifies captures, 1407If the pattern specifies captures,
@@ -1409,14 +1416,14 @@ so the function does a plain ``find substring'' operation.
1409Receives a string and returns its length. 1416Receives a string and returns its length.
1410 1417
1411\subsubsection*{\ff{\tt strsub (s, i [, j])}}\Deffunc{strsub} 1418\subsubsection*{\ff{\tt strsub (s, i [, j])}}\Deffunc{strsub}
1412Returns another string, which is a substring of \verb's', 1419Returns another string, which is a substring of \verb|s|,
1413starting at \verb'i' and runing until \verb'j'. 1420starting at \verb|i| and runing until \verb|j|.
1414If \verb'j' is absent, 1421If \verb|j| is absent,
1415it is assumed to be equal to the length of \verb's'. 1422it is assumed to be equal to the length of \verb|s|.
1416In particular, the call \verb'strsub(s,1,j)' returns a prefix of \verb's' 1423In particular, the call \verb|strsub(s,1,j)| returns a prefix of \verb|s|
1417with length \verb'j', 1424with length \verb|j|,
1418whereas the call \verb'strsub(s,i)' returns a suffix of \verb's', 1425whereas the call \verb|strsub(s,i)| returns a suffix of \verb|s|,
1419starting at \verb'i'. 1426starting at \verb|i|.
1420 1427
1421\subsubsection*{\ff{\tt strlower (s)}}\Deffunc{strlower} 1428\subsubsection*{\ff{\tt strlower (s)}}\Deffunc{strlower}
1422Receives a string and returns a copy of that string with all 1429Receives a string and returns a copy of that string with all
@@ -1429,23 +1436,23 @@ lower case letters changed to upper case.
1429All other characters are left unchanged. 1436All other characters are left unchanged.
1430 1437
1431\subsubsection*{\ff{\tt strrep (s, n)}}\Deffunc{strrep} 1438\subsubsection*{\ff{\tt strrep (s, n)}}\Deffunc{strrep}
1432Returns a string which is the concatenation of \verb-n- copies of 1439Returns a string which is the concatenation of \verb|n| copies of
1433the string \verb-s-. 1440the string \verb|s|.
1434 1441
1435\subsubsection*{\ff{\tt ascii (s [, i])}}\Deffunc{ascii} 1442\subsubsection*{\ff{\tt ascii (s [, i])}}\Deffunc{ascii}
1436Returns the ASCII code of the character \verb's[i]'. 1443Returns the ASCII code of the character \verb|s[i]|.
1437If \verb'i' is absent, then it is assumed to be 1. 1444If \verb|i| is absent, then it is assumed to be 1.
1438 1445
1439\subsubsection*{\ff{\tt format (formatstring, e1, e2, \ldots)}}\Deffunc{format} 1446\subsubsection*{\ff{\tt format (formatstring, e1, e2, \ldots)}}\Deffunc{format}
1440\label{format} 1447\label{format}
1441This function returns a formated version of its variable number of arguments 1448This function returns a formated version of its variable number of arguments
1442following the description given in its first argument (which must be a string). 1449following the description given in its first argument (which must be a string).
1443The format string follows the same rules as the \verb'printf' family of 1450The format string follows the same rules as the \verb|printf| family of
1444standard C functions. 1451standard C functions.
1445The only differences are that the options/modifiers 1452The only differences are that the options/modifiers
1446\verb'*', \verb'l', \verb'L', \verb'n', \verb'p', 1453\verb|*|, \verb|l|, \verb|L|, \verb|n|, \verb|p|,
1447and \verb'h' are not supported, 1454and \verb|h| are not supported,
1448and there is an extra option, \verb'q'. 1455and there is an extra option, \verb|q|.
1449This option formats a string in a form suitable to be safely read 1456This option formats a string in a form suitable to be safely read
1450back by the Lua interpreter; 1457back by the Lua interpreter;
1451that is, 1458that is,
@@ -1462,41 +1469,41 @@ will produce the string:
1462 new line" 1469 new line"
1463\end{verbatim} 1470\end{verbatim}
1464 1471
1465The options \verb'c', \verb'd', \verb'E', \verb'e', \verb'f', 1472The options \verb|c|, \verb|d|, \verb|E|, \verb|e|, \verb|f|,
1466\verb'g' \verb'i', \verb'o', \verb'u', \verb'X', and \verb'x' all 1473\verb|g| \verb|i|, \verb|o|, \verb|u|, \verb|X|, and \verb|x| all
1467expect a number as argument, 1474expect a number as argument,
1468whereas \verb'q' and \verb's' expect a string. 1475whereas \verb|q| and \verb|s| expect a string.
1469Note that the \verb'*' modifier can be simulated by building 1476Note that the \verb|*| modifier can be simulated by building
1470the appropriate format string. 1477the appropriate format string.
1471For example, \verb|"%*g"| can be simulated with 1478For example, \verb|"%*g"| can be simulated with
1472\verb|"%"..width.."g"|. 1479\verb|"%"..width.."g"|.
1473 1480
1474\subsubsection*{\ff{\tt gsub (s, pat, repl [, n])}}\Deffunc{gsub} 1481\subsubsection*{\ff{\tt gsub (s, pat, repl [, n])}}\Deffunc{gsub}
1475Returns a copy of \verb-s-, 1482Returns a copy of \verb|s|,
1476where all occurrences of the pattern \verb-pat- have been 1483where all occurrences of the pattern \verb|pat| have been
1477replaced by a replacement string specified by \verb-repl-. 1484replaced by a replacement string specified by \verb|repl|.
1478This function also returns, as a second value, 1485This function also returns, as a second value,
1479the total number of substitutions made. 1486the total number of substitutions made.
1480 1487
1481If \verb-repl- is a string, then its value is used for replacement. 1488If \verb|repl| is a string, then its value is used for replacement.
1482Any sequence in \verb-repl- of the form \verb-%n- 1489Any sequence in \verb|repl| of the form \verb|%n|
1483with \verb-n- between 1 and 9 1490with \verb|n| between 1 and 9
1484stands for the value of the n-th captured substring. 1491stands for the value of the n-th captured substring.
1485 1492
1486If \verb-repl- is a function, then this function is called every time a 1493If \verb|repl| is a function, then this function is called every time a
1487match occurs, with all captured substrings as parameters 1494match occurs, with all captured substrings as parameters
1488(see below). 1495(see below).
1489If the value returned by this function is a string, 1496If the value returned by this function is a string,
1490then it is used as the replacement string; 1497then it is used as the replacement string;
1491otherwise, the replacement string is the empty string. 1498otherwise, the replacement string is the empty string.
1492 1499
1493An optional parameter \verb-n- limits 1500An optional parameter \verb|n| limits
1494the maximum number of substitutions to occur. 1501the maximum number of substitutions to occur.
1495For instance, when \verb-n- is 1 only the first occurrence of 1502For instance, when \verb|n| is 1 only the first occurrence of
1496\verb-pat- is replaced. 1503\verb|pat| is replaced.
1497 1504
1498As an example, in the following expression each occurrence of the form 1505As an example, in the following expression each occurrence of the form
1499\verb-$name- calls the function \verb|getenv|, 1506\verb|$name| calls the function \verb|getenv|,
1500passing \verb|name| as argument 1507passing \verb|name| as argument
1501(because only this part of the pattern is captured). 1508(because only this part of the pattern is captured).
1502The value returned by \verb|getenv| will replace the pattern. 1509The value returned by \verb|getenv| will replace the pattern.
@@ -1515,7 +1522,7 @@ home = /home/roberto, user = roberto
1515a \Def{character class} is used to represent a set of characters. 1522a \Def{character class} is used to represent a set of characters.
1516The following combinations are allowed in describing a character class: 1523The following combinations are allowed in describing a character class:
1517\begin{description} 1524\begin{description}
1518\item[{\em x}] (where {\em x} is any character not in the list \verb'()%.[*?') 1525\item[{\em x}] (where {\em x} is any character not in the list \verb|()%.[*?|)
1519--- represents the character {\em x} itself. 1526--- represents the character {\em x} itself.
1520\item[{\tt .}] --- represents all characters. 1527\item[{\tt .}] --- represents all characters.
1521\item[{\tt \%a}] --- represents all letters. 1528\item[{\tt \%a}] --- represents all letters.
@@ -1530,19 +1537,19 @@ The following combinations are allowed in describing a character class:
1530\item[{\tt \%U}] --- represents all non upper case letter characters. 1537\item[{\tt \%U}] --- represents all non upper case letter characters.
1531\item[{\tt \%w}] --- represents all alphanumeric characters. 1538\item[{\tt \%w}] --- represents all alphanumeric characters.
1532\item[{\tt \%W}] --- represents all non alphanumeric characters. 1539\item[{\tt \%W}] --- represents all non alphanumeric characters.
1533\item[{\tt \%\em x}] (where {\em x} is any non alphanumeric character) --- 1540\item[{\tt \%\M{x}}] (where \M{x} is any non alphanumeric character) ---
1534represents the character {\em x}. 1541represents the character \M{x}.
1535This is the standard way to escape the magic characters \verb'()%.[*?'. 1542This is the standard way to escape the magic characters \verb|()%.[*?|.
1536\item[{\tt [char-set]}] --- 1543\item[{\tt [char-set]}] ---
1537Represents the class which is the union of all 1544Represents the class which is the union of all
1538characters in char-set. 1545characters in char-set.
1539To include a \verb']' in char-set, it must be the first character. 1546To include a \verb|]| in char-set, it must be the first character.
1540A range of characters may be specified by 1547A range of characters may be specified by
1541separating the end characters of the range with a \verb'-'; 1548separating the end characters of the range with a \verb|-|;
1542e.g., \verb'A-Z' specifies the upper case characters. 1549e.g., \verb|A-Z| specifies the upper case characters.
1543If \verb'-' appears as the first or last character of char-set, 1550If \verb|-| appears as the first or last character of char-set,
1544then it represents itself. 1551then it represents itself.
1545All classes \verb'%'{\em x} described above can also be used as 1552All classes \verb|%|{\em x} described above can also be used as
1546components in a char-set. 1553components in a char-set.
1547All other characters in char-set represent themselves. 1554All other characters in char-set represent themselves.
1548\item[{\tt [\^{ }char-set]}] --- 1555\item[{\tt [\^{ }char-set]}] ---
@@ -1557,37 +1564,37 @@ a \Def{pattern item} may be:
1557a single character class, 1564a single character class,
1558which matches any single character in the class; 1565which matches any single character in the class;
1559\item 1566\item
1560a single character class followed by \verb'*', 1567a single character class followed by \verb|*|,
1561which matches 0 or more repetitions of characters in the class. 1568which matches 0 or more repetitions of characters in the class.
1562These repetition itens will always match the longest possible sequence. 1569These repetition itens will always match the longest possible sequence.
1563\item 1570\item
1564a single character class followed by \verb'-', 1571a single character class followed by \verb|-|,
1565which also matches 0 or more repetitions of characters in the class. 1572which also matches 0 or more repetitions of characters in the class.
1566Unlike \verb'*', 1573Unlike \verb|*|,
1567these repetition itens will always match the shortest possible sequence. 1574these repetition itens will always match the shortest possible sequence.
1568\item 1575\item
1569a single character class followed by \verb'?', 1576a single character class followed by \verb|?|,
1570which matches 0 or 1 occurrence of a character in the class; 1577which matches 0 or 1 occurrence of a character in the class;
1571\item 1578\item
1572{\tt \%$n$}, for $n$ between 1 and 9; 1579{\tt \%\M{n}}, for \M{n} between 1 and 9;
1573such item matches a sub-string equal to the n-th captured string 1580such item matches a sub-string equal to the n-th captured string
1574(see below); 1581(see below);
1575\item 1582\item
1576{\tt \%b$xy$}, where $x$ and $y$ are two distinct characters; 1583{\tt \%b\M{xy}}, where \M{x} and \M{y} are two distinct characters;
1577such item mathes strings that start with $x$, end with $y$, 1584such item mathes strings that start with \M{x}, end with \M{y},
1578and where the $x$ and $y$ are {\em balanced}. 1585and where the \M{x} and \M{y} are {\em balanced}.
1579That means that, if one reads the string from left to write, 1586That means that, if one reads the string from left to write,
1580counting plus 1 for an $x$ and minus 1 for a $y$, 1587counting plus 1 for an \M{x} and minus 1 for a \M{y},
1581the ending $y$ is the first where the count reaches 0. 1588the ending \M{y} is the first where the count reaches 0.
1582For instance, the item \verb|%()| matches expressions with 1589For instance, the item \verb|%()| matches expressions with
1583balanced parentheses. 1590balanced parentheses.
1584\end{itemize} 1591\end{itemize}
1585 1592
1586\paragraph{Pattern:} 1593\paragraph{Pattern:}
1587a \Def{pattern} is a sequence of pattern items. 1594a \Def{pattern} is a sequence of pattern items.
1588A \verb'^' at the beginning of a pattern anchors the match at the 1595A \verb|^| at the beginning of a pattern anchors the match at the
1589beginning of the subject string. 1596beginning of the subject string.
1590A \verb'$' at the end of a pattern anchors the match at the 1597A \verb|$| at the end of a pattern anchors the match at the
1591end of the subject string. 1598end of the subject string.
1592 1599
1593\paragraph{Captures:} 1600\paragraph{Captures:}
@@ -1605,8 +1612,8 @@ and the part matching \verb|%s*| has number 3.
1605\subsection{Mathematical Functions} \label{mathlib} 1612\subsection{Mathematical Functions} \label{mathlib}
1606 1613
1607This library is an interface to some functions of the standard C math library. 1614This library is an interface to some functions of the standard C math library.
1608In addition, it registers a fallback for the binary operator \verb'^' that, 1615In addition, it registers a fallback for the binary operator \verb|^| that,
1609returns $x^y$ when applied to numbers \verb'x^y'. 1616returns \M{x^y} when applied to numbers \verb|x^y|.
1610 1617
1611The library provides the following functions: 1618The library provides the following functions:
1612\Deffunc{abs}\Deffunc{acos}\Deffunc{asin}\Deffunc{atan} 1619\Deffunc{abs}\Deffunc{acos}\Deffunc{asin}\Deffunc{atan}
@@ -1623,24 +1630,24 @@ are only interfaces to the homonymous functions in the C library,
1623except that, for the trigonometric functions, 1630except that, for the trigonometric functions,
1624all angles are expressed in {\em degrees}, not radians. 1631all angles are expressed in {\em degrees}, not radians.
1625 1632
1626The function \verb'max' returns the maximum 1633The function \verb|max| returns the maximum
1627value of its numeric arguments. 1634value of its numeric arguments.
1628Similarly, \verb'min' computes the minimum. 1635Similarly, \verb|min| computes the minimum.
1629Both can be used with an unlimited number of arguments. 1636Both can be used with an unlimited number of arguments.
1630 1637
1631The functions \verb'random' and \verb'randomseed' are interfaces to 1638The functions \verb|random| and \verb|randomseed| are interfaces to
1632the simple random generator functions \verb'rand' and \verb'srand', 1639the simple random generator functions \verb|rand| and \verb|srand|,
1633provided by ANSI C. 1640provided by ANSI C.
1634The function \verb'random' returns pseudo-random numbers in the range 1641The function \verb|random| returns pseudo-random numbers in the
1635$[0,1)$. 1642range \M{[0,1)}.
1636 1643
1637 1644
1638\subsection{I/O Facilities} \label{libio} 1645\subsection{I/O Facilities} \label{libio}
1639 1646
1640All input and outpu operations in Lua are done over two {\em current\/} files: 1647All input and outpu operations in Lua are done over two {\em current\/} files:
1641one for reading and one for writing. 1648one for reading and one for writing.
1642Initially, the current input file is \verb'stdin', 1649Initially, the current input file is \verb|stdin|,
1643and the current output file is \verb'stdout'. 1650and the current output file is \verb|stdout|.
1644 1651
1645Unless otherwise stated, 1652Unless otherwise stated,
1646all I/O functions return \nil\ on failure and 1653all I/O functions return \nil\ on failure and
@@ -1659,14 +1666,14 @@ When called with a file handle, returned by a previous call,
1659it restores the file as the current input. 1666it restores the file as the current input.
1660When called without parameters, 1667When called without parameters,
1661it closes the current input file, 1668it closes the current input file,
1662and restores \verb'stdin' as the current input file. 1669and restores \verb|stdin| as the current input file.
1663 1670
1664If this function fails, it returns \nil, 1671If this function fails, it returns \nil,
1665plus a string describing the error. 1672plus a string describing the error.
1666 1673
1667\begin{quotation} 1674\begin{quotation}
1668\noindent 1675\noindent
1669{\em System dependent\/}: if \verb'filename' starts with a \verb'|', 1676{\em System dependent\/}: if \verb|filename| starts with a \verb-|-,
1670then a \Index{piped input} is open, via function \IndexVerb{popen}. 1677then a \Index{piped input} is open, via function \IndexVerb{popen}.
1671Not all systems implement pipes. 1678Not all systems implement pipes.
1672Moreover, 1679Moreover,
@@ -1689,7 +1696,7 @@ When called with a file handle, returned by a previous call,
1689it restores the file as the current output. 1696it restores the file as the current output.
1690When called without parameters, 1697When called without parameters,
1691this function closes the current output file, 1698this function closes the current output file,
1692and restores \verb'stdout' as the current output file. 1699and restores \verb|stdout| as the current output file.
1693\index{closing a file} 1700\index{closing a file}
1694%%LHF: nao tem como escrever em stderr, tem? 1701%%LHF: nao tem como escrever em stderr, tem?
1695 1702
@@ -1698,7 +1705,7 @@ plus a string describing the error.
1698 1705
1699\begin{quotation} 1706\begin{quotation}
1700\noindent 1707\noindent
1701{\em System dependent\/}: if \verb'filename' starts with a \verb'|', 1708{\em System dependent\/}: if \verb|filename| starts with a \verb-|-,
1702then a \Index{piped output} is open, via function \IndexVerb{popen}. 1709then a \Index{piped output} is open, via function \IndexVerb{popen}.
1703Not all systems implement pipes. 1710Not all systems implement pipes.
1704Moreover, 1711Moreover,
@@ -1708,11 +1715,11 @@ depends on the system.
1708 1715
1709\subsubsection*{\ff{\tt appendto (filename)}}\Deffunc{appendto} 1716\subsubsection*{\ff{\tt appendto (filename)}}\Deffunc{appendto}
1710 1717
1711This function opens a file named \verb'filename' and sets it as the 1718This function opens a file named \verb|filename| and sets it as the
1712{\em current\/} output file. 1719{\em current\/} output file.
1713It returns the file handle, 1720It returns the file handle,
1714or \nil\ in case of error. 1721or \nil\ in case of error.
1715Unlike the \verb'writeto' operation, 1722Unlike the \verb|writeto| operation,
1716this function does not erase any previous content of the file. 1723this function does not erase any previous content of the file.
1717If this function fails, it returns \nil, 1724If this function fails, it returns \nil,
1718plus a string describing the error. 1725plus a string describing the error.
@@ -1727,7 +1734,7 @@ plus a string describing the error.
1727 1734
1728\subsubsection*{\ff{\tt rename (name1, name2)}}\Deffunc{rename} 1735\subsubsection*{\ff{\tt rename (name1, name2)}}\Deffunc{rename}
1729 1736
1730This function renames file named \verb'name1' to \verb'name2'. 1737This function renames file named \verb|name1| to \verb|name2|.
1731If this function fails, it returns \nil, 1738If this function fails, it returns \nil,
1732plus a string describing the error. 1739plus a string describing the error.
1733 1740
@@ -1752,19 +1759,19 @@ it uses a default pattern that reads the next line
1752 1759
1753A \Def{read pattern} is a sequence of read pattern items. 1760A \Def{read pattern} is a sequence of read pattern items.
1754An item may be a single character class 1761An item may be a single character class
1755or a character class followed by \verb'?' or by \verb'*'. 1762or a character class followed by \verb|?| or by \verb|*|.
1756A single character class reads the next character from the input 1763A single character class reads the next character from the input
1757if it belongs to the class, otherwise it fails. 1764if it belongs to the class, otherwise it fails.
1758A character class followed by \verb'?' reads the next character 1765A character class followed by \verb|?| reads the next character
1759from the input if it belongs to the class; 1766from the input if it belongs to the class;
1760it never fails. 1767it never fails.
1761A character class followed by \verb'*' reads until a character that 1768A character class followed by \verb|*| reads until a character that
1762does not belong to the class, or end of file; 1769does not belong to the class, or end of file;
1763since it can match a sequence of zero characteres, it never fails.% 1770since it can match a sequence of zero characteres, it never fails.%
1764\footnote{ 1771\footnote{
1765Notice that the behavior of read patterns is different from 1772Notice that the behavior of read patterns is different from
1766the regular pattern matching behavior, 1773the regular pattern matching behavior,
1767where a \verb'*' expands to the maximum length {\em such that\/} 1774where a \verb|*| expands to the maximum length {\em such that\/}
1768the rest of the pattern does not fail. 1775the rest of the pattern does not fail.
1769With the read pattern behavior 1776With the read pattern behavior
1770there is no need for backtracking the reading. 1777there is no need for backtracking the reading.
@@ -1802,18 +1809,18 @@ plus a string describing the error.
1802\subsubsection*{\ff{\tt date ([format])}}\Deffunc{date} 1809\subsubsection*{\ff{\tt date ([format])}}\Deffunc{date}
1803 1810
1804This function returns a string containing date and time 1811This function returns a string containing date and time
1805formatted according to the given string \verb'format', 1812formatted according to the given string \verb|format|,
1806following the same rules of the ANSI C function \verb'strftime'. 1813following the same rules of the ANSI C function \verb|strftime|.
1807When called without arguments, 1814When called without arguments,
1808it returns a reasonable date and time representation that depends on 1815it returns a reasonable date and time representation that depends on
1809the host system. 1816the host system.
1810 1817
1811\subsubsection*{\ff{\tt exit ([code])}}\Deffunc{exit} 1818\subsubsection*{\ff{\tt exit ([code])}}\Deffunc{exit}
1812 1819
1813This function calls the C function \verb-exit-, 1820This function calls the C function \verb|exit|,
1814with an optional \verb-code-, 1821with an optional \verb|code|,
1815to terminate the program. 1822to terminate the program.
1816The default value for \verb-code- is 1. 1823The default value for \verb|code| is 1.
1817 1824
1818\subsubsection*{\ff{\tt getenv (varname)}}\Deffunc{getenv} 1825\subsubsection*{\ff{\tt getenv (varname)}}\Deffunc{getenv}
1819 1826
@@ -1835,7 +1842,7 @@ by means of functions and {\em hooks},
1835which allows the construction of different 1842which allows the construction of different
1836kinds of debuggers, profilers, and other tools 1843kinds of debuggers, profilers, and other tools
1837that need ``inside information'' from the interpreter. 1844that need ``inside information'' from the interpreter.
1838This interface is declared in the header file \verb'luadebug.h'. 1845This interface is declared in the header file \verb|luadebug.h|.
1839 1846
1840\subsection{Stack and Function Information} 1847\subsection{Stack and Function Information}
1841 1848
@@ -1844,20 +1851,20 @@ is
1844\begin{verbatim} 1851\begin{verbatim}
1845lua_Function lua_stackedfunction (int level); 1852lua_Function lua_stackedfunction (int level);
1846\end{verbatim} 1853\end{verbatim}
1847It returns a handle (\verb'lua_Function') to the {\em activation record\/} 1854It returns a handle (\verb|lua_Function|) to the {\em activation record\/}
1848of the function executing at a given level. 1855of the function executing at a given level.
1849Level 0 is the current running function, 1856Level 0 is the current running function,
1850while level $n+1$ is the function that has called level $n$. 1857while level \M{n+1} is the function that has called level \M{n}.
1851When called with a level greater than the stack depth, 1858When called with a level greater than the stack depth,
1852\verb'lua_stackedfunction' returns \verb'LUA_NOOBJECT'. 1859\verb|lua_stackedfunction| returns \verb|LUA_NOOBJECT|.
1853 1860
1854The type \verb'lua_Function' is just another name 1861The type \verb|lua_Function| is just another name
1855to \verb'lua_Object'. 1862to \verb|lua_Object|.
1856Although, in this library, 1863Although, in this library,
1857a \verb'lua_Function' can be used wherever a \verb'lua_Object' is required, 1864a \verb|lua_Function| can be used wherever a \verb|lua_Object| is required,
1858when a parameter has type \verb'lua_Function' 1865when a parameter has type \verb|lua_Function|
1859it accepts only a handle returned by 1866it accepts only a handle returned by
1860\verb'lua_stackedfunction'. 1867\verb|lua_stackedfunction|.
1861 1868
1862Three other functions produce extra information about a function: 1869Three other functions produce extra information about a function:
1863\begin{verbatim} 1870\begin{verbatim}
@@ -1865,35 +1872,35 @@ void lua_funcinfo (lua_Object func, char **filename, int *linedefined);
1865int lua_currentline (lua_Function func); 1872int lua_currentline (lua_Function func);
1866char *lua_getobjname (lua_Object o, char **name); 1873char *lua_getobjname (lua_Object o, char **name);
1867\end{verbatim} 1874\end{verbatim}
1868\verb'lua_funcinfo' gives the file name and the line where the 1875\verb|lua_funcinfo| gives the file name and the line where the
1869given function has been defined. 1876given function has been defined.
1870If the ``function'' is in fact the main code of a chunk, 1877If the ``function'' is in fact the main code of a chunk,
1871then \verb'linedefined' is 0. 1878then \verb|linedefined| is 0.
1872If the function is a C function, 1879If the function is a C function,
1873then \verb'linedefined' is -1, and \verb'filename' is \verb'"(C)"'. 1880then \verb|linedefined| is -1, and \verb|filename| is \verb|"(C)"|.
1874 1881
1875The function \verb'lua_currentline' gives the current line where 1882The function \verb|lua_currentline| gives the current line where
1876a given function is executing. 1883a given function is executing.
1877It only works if the function has been compiled with debug 1884It only works if the function has been compiled with debug
1878information \see{pragma}. 1885information \see{pragma}.
1879When no line information is available, it returns -1. 1886When no line information is available, it returns -1.
1880 1887
1881Function \verb'lua_getobjname' tries to find a reasonable name for 1888Function \verb|lua_getobjname| tries to find a reasonable name for
1882a given function. 1889a given function.
1883Because functions in Lua are first class values, 1890Because functions in Lua are first class values,
1884they do not have a fixed name: 1891they do not have a fixed name:
1885Some functions may be the value of many global variables, 1892Some functions may be the value of many global variables,
1886while others may be stored only in a table field. 1893while others may be stored only in a table field.
1887Function \verb'lua_getobjname' first checks whether the given 1894Function \verb|lua_getobjname| first checks whether the given
1888function is a fallback. 1895function is a fallback.
1889If so, it returns the string \verb'"fallback"', 1896If so, it returns the string \verb|"fallback"|,
1890and \verb'name' is set to point to the fallback name. 1897and \verb|name| is set to point to the fallback name.
1891Otherwise, if the given function is the value of a global variable, 1898Otherwise, if the given function is the value of a global variable,
1892then \verb'lua_getobjname' returns the string \verb'"global"', 1899then \verb|lua_getobjname| returns the string \verb|"global"|,
1893and \verb'name' points to the variable name. 1900and \verb|name| points to the variable name.
1894If the given function is neither a fallback nor a global variable, 1901If the given function is neither a fallback nor a global variable,
1895then \verb'lua_getobjname' returns the empty string, 1902then \verb|lua_getobjname| returns the empty string,
1896and \verb'name' is set to \verb'NULL'. 1903and \verb|name| is set to \verb|NULL|.
1897 1904
1898\subsection{Manipulating Local Variables} 1905\subsection{Manipulating Local Variables}
1899 1906
@@ -1906,22 +1913,22 @@ lua_Object lua_getlocal (lua_Function func, int local_number, char **name);
1906int lua_setlocal (lua_Function func, int local_number); 1913int lua_setlocal (lua_Function func, int local_number);
1907\end{verbatim} 1914\end{verbatim}
1908\verb|lua_getlocal| returns the value of a local variable, 1915\verb|lua_getlocal| returns the value of a local variable,
1909and sets \verb'name' to point to the variable name. 1916and sets \verb|name| to point to the variable name.
1910\verb'local_number' is an index for local variables. 1917\verb|local_number| is an index for local variables.
1911The first parameter has index 1, and so on, until the 1918The first parameter has index 1, and so on, until the
1912last active local variable. 1919last active local variable.
1913When called with a \verb'local_number' greater than the 1920When called with a \verb|local_number| greater than the
1914number of active local variables, 1921number of active local variables,
1915or if the activation record has no debug information, 1922or if the activation record has no debug information,
1916\verb'lua_getlocal' returns \verb'LUA_NOOBJECT'. 1923\verb|lua_getlocal| returns \verb|LUA_NOOBJECT|.
1917Formal parameters are the first local variables. 1924Formal parameters are the first local variables.
1918 1925
1919The function \verb'lua_setlocal' sets the local variable 1926The function \verb|lua_setlocal| sets the local variable
1920%%LHF: please, lua_setglobal! 1927%%LHF: please, lua_setglobal!
1921\verb'local_number' to the value previously pushed on the stack 1928\verb|local_number| to the value previously pushed on the stack
1922\see{valuesCLua}. 1929\see{valuesCLua}.
1923If the function succeeds, then it returns 1. 1930If the function succeeds, then it returns 1.
1924If \verb'local_number' is greater than the number 1931If \verb|local_number| is greater than the number
1925of active local variables, 1932of active local variables,
1926or if the activation record has no debug information, 1933or if the activation record has no debug information,
1927then this function fails and returns 0. 1934then this function fails and returns 0.
@@ -1941,15 +1948,15 @@ function.
1941When entering a function, 1948When entering a function,
1942its parameters are a handle to the function activation record, 1949its parameters are a handle to the function activation record,
1943plus the file and the line where the function is defined (the same 1950plus the file and the line where the function is defined (the same
1944information which is provided by \verb'lua_funcinfo'); 1951information which is provided by \verb|lua_funcinfo|);
1945when leaving a function, \verb'func' is \verb'LUA_NOOBJECT', 1952when leaving a function, \verb|func| is \verb|LUA_NOOBJECT|,
1946\verb'file' is \verb'"(return)"', and \verb'line' is 0. 1953\verb|file| is \verb|"(return)"|, and \verb|line| is 0.
1947 1954
1948The other hook is called every time the interpreter changes 1955The other hook is called every time the interpreter changes
1949the line of code it is executing. 1956the line of code it is executing.
1950Its only parameter is the line number 1957Its only parameter is the line number
1951(the same information which is provided by the call 1958(the same information which is provided by the call
1952\verb'lua_currentline(lua_stackedfunction(0))'). 1959\verb|lua_currentline(lua_stackedfunction(0))|).
1953This second hook is only called if the active function 1960This second hook is only called if the active function
1954has been compiled with debug information \see{pragma}. 1961has been compiled with debug information \see{pragma}.
1955 1962
@@ -1980,8 +1987,8 @@ For instance, an invocation like
1980$ lua - a=1 prog.lua 1987$ lua - a=1 prog.lua
1981\end{verbatim} 1988\end{verbatim}
1982will first interact with the user until an \verb|EOF|, 1989will first interact with the user until an \verb|EOF|,
1983then will set \verb'a' to 1, 1990then will set \verb|a| to 1,
1984and finally will run file \verb'prog.lua'. 1991and finally will run file \verb|prog.lua|.
1985 1992
1986Please notice that the interaction with the shell may lead to 1993Please notice that the interaction with the shell may lead to
1987unintended results. 1994unintended results.
@@ -1991,8 +1998,8 @@ $ lua a="name" prog.lua
1991\end{verbatim} 1998\end{verbatim}
1992will {\em not\/} set \verb|a| to the string \verb|"name"|. 1999will {\em not\/} set \verb|a| to the string \verb|"name"|.
1993Instead, the quotes will be handled by the shell, 2000Instead, the quotes will be handled by the shell,
1994lua will get only \verb'a=name' to run, 2001lua will get only \verb|a=name| to run,
1995and \verb'a' will finish with \nil, 2002and \verb|a| will finish with \nil,
1996because the global variable \verb|name| has not been initialized. 2003because the global variable \verb|name| has not been initialized.
1997Instead, one should write 2004Instead, one should write
1998\begin{verbatim} 2005\begin{verbatim}
@@ -2001,7 +2008,7 @@ $ lua 'a="name"' prog.lua
2001 2008
2002\section*{Acknowledgments} 2009\section*{Acknowledgments}
2003 2010
2004The authors would like to thank CENPES/PETROBR\'AS which, 2011The authors would like to thank CENPES/PETROBRAS which,
2005jointly with \tecgraf, used extensively early versions of 2012jointly with \tecgraf, used extensively early versions of
2006this system and gave valuable comments. 2013this system and gave valuable comments.
2007The authors would also like to thank Carlos Henrique Levy, 2014The authors would also like to thank Carlos Henrique Levy,
@@ -2028,13 +2035,13 @@ in the distribution,
2028to allow a smooth transition. 2035to allow a smooth transition.
2029The incompatibilities between the new and the old libraries are: 2036The incompatibilities between the new and the old libraries are:
2030\begin{itemize} 2037\begin{itemize}
2031\item The format facility of function \verb'write' has been supersed by 2038\item The format facility of function \verb|write| has been supersed by
2032function \verb'format'; 2039function \verb|format|;
2033therefore this facility has been dropped. 2040therefore this facility has been dropped.
2034\item Function \verb'read' now uses {\em read patterns\/} to specify 2041\item Function \verb|read| now uses {\em read patterns\/} to specify
2035what to read; 2042what to read;
2036this is incompatible with the old format options. 2043this is incompatible with the old format options.
2037\item Function \verb'strfind' now accepts patterns, 2044\item Function \verb|strfind| now accepts patterns,
2038so it may have a different behavior when the pattern includes 2045so it may have a different behavior when the pattern includes
2039special characters. 2046special characters.
2040\end{itemize} 2047\end{itemize}
@@ -2042,27 +2049,27 @@ special characters.
2042\subsection*{Incompatibilities with \Index{version 2.2}} 2049\subsection*{Incompatibilities with \Index{version 2.2}}
2043\begin{itemize} 2050\begin{itemize}
2044\item 2051\item
2045Functions \verb'date' and \verb'time' (from \verb'iolib') 2052Functions \verb|date| and \verb|time| (from \verb|iolib|)
2046have been superseded by the new, more powerful version of function \verb'date'. 2053have been superseded by the new, more powerful version of function \verb|date|.
2047\item 2054\item
2048Function \verb'append' (from \verb'iolib') now returns 1 whenever it succeeds, 2055Function \verb|append| (from \verb|iolib|) now returns 1 whenever it succeeds,
2049whether the file is new or not. 2056whether the file is new or not.
2050\item 2057\item
2051Function \verb'int2str' (from \verb'strlib') has been superseded by new 2058Function \verb|int2str| (from \verb|strlib|) has been superseded by new
2052function \verb'format', with parameter \verb'"%c"'. 2059function \verb|format|, with parameter \verb|"%c"|.
2053\item 2060\item
2054The API lock mechanism has been superseded by the reference mechanism. 2061The API lock mechanism has been superseded by the reference mechanism.
2055However, \verb-lua.h- provides compatibility macros, 2062However, \verb|lua.h| provides compatibility macros,
2056so there is no need to change programs. 2063so there is no need to change programs.
2057\item 2064\item
2058The API function \verb'lua_pushliteral' now is just a macro to 2065The API function \verb|lua_pushliteral| now is just a macro to
2059\verb'lua_pushstring'. 2066\verb|lua_pushstring|.
2060\end{itemize} 2067\end{itemize}
2061 2068
2062\subsection*{Incompatibilities with \Index{version 2.1}} 2069\subsection*{Incompatibilities with \Index{version 2.1}}
2063\begin{itemize} 2070\begin{itemize}
2064\item 2071\item
2065The function \verb'type' now returns the string \verb'"function"' 2072The function \verb|type| now returns the string \verb|"function"|
2066both for C and Lua functions. 2073both for C and Lua functions.
2067Because Lua functions and C functions are compatible, 2074Because Lua functions and C functions are compatible,
2068this behavior is usually more useful. 2075this behavior is usually more useful.
@@ -2076,36 +2083,36 @@ given variable at execution time.
2076\subsection*{Incompatibilities with \Index{version 1.1}} 2083\subsection*{Incompatibilities with \Index{version 1.1}}
2077\begin{itemize} 2084\begin{itemize}
2078\item 2085\item
2079The equality test operator now is denoted by \verb'==', 2086The equality test operator now is denoted by \verb|==|,
2080instead of \verb'='. 2087instead of \verb|=|.
2081\item 2088\item
2082The syntax for table construction has been greatly simplified. 2089The syntax for table construction has been greatly simplified.
2083The old \verb'@(size)' has been substituted by \verb'{}'. 2090The old \verb|@(size)| has been substituted by \verb|{}|.
2084The list constructor (formerly \verb'@[...]') and the record 2091The list constructor (formerly \verb|@[...]|) and the record
2085constructor (formerly \verb'@{...}') now are both coded like 2092constructor (formerly \verb|@{...}|) now are both coded like
2086\verb'{...}'. 2093\verb|{...}|.
2087When the construction involves a function call, 2094When the construction involves a function call,
2088like in \verb'@func{...}', 2095like in \verb|@func{...}|,
2089the new syntax does not use the \verb'@'. 2096the new syntax does not use the \verb|@|.
2090More important, {\em a construction function must now 2097More important, {\em a construction function must now
2091explicitly return the constructed table}. 2098explicitly return the constructed table}.
2092\item 2099\item
2093The function \verb'lua_call' no longer has the parameter \verb'nparam'. 2100The function \verb|lua_call| no longer has the parameter \verb|nparam|.
2094\item 2101\item
2095The function \verb'lua_pop' is no longer available, 2102The function \verb|lua_pop| is no longer available,
2096since it could lead to strange behavior. 2103since it could lead to strange behavior.
2097In particular, 2104In particular,
2098to access results returned from a Lua function, 2105to access results returned from a Lua function,
2099the new macro \verb|lua_getresult| should be used. 2106the new macro \verb|lua_getresult| should be used.
2100\item 2107\item
2101The old functions \verb'lua_storefield' and \verb'lua_storeindexed' 2108The old functions \verb|lua_storefield| and \verb|lua_storeindexed|
2102have been replaced by 2109have been replaced by
2103\begin{verbatim} 2110\begin{verbatim}
2104int lua_storesubscript (void); 2111int lua_storesubscript (void);
2105\end{verbatim} 2112\end{verbatim}
2106with the parameters explicitly pushed on the stack. 2113with the parameters explicitly pushed on the stack.
2107\item 2114\item
2108The functionality of the function \verb'lua_errorfunction' has been 2115The functionality of the function \verb|lua_errorfunction| has been
2109replaced by the {\em fallback\/} mechanism \see{error}. 2116replaced by the {\em fallback\/} mechanism \see{error}.
2110\item 2117\item
2111When calling a function from the Lua library, 2118When calling a function from the Lua library,
@@ -2113,7 +2120,7 @@ parameters passed through the stack
2113must be pushed just before the corresponding call, 2120must be pushed just before the corresponding call,
2114with no intermediate calls to Lua. 2121with no intermediate calls to Lua.
2115Special care should be taken with macros like 2122Special care should be taken with macros like
2116\verb'lua_getindexed' and \verb'lua_getfield'. 2123\verb|lua_getindexed| and \verb|lua_getfield|.
2117\end{itemize} 2124\end{itemize}
2118 2125
2119\newcommand{\indexentry}[2]{\item {#1} #2} 2126\newcommand{\indexentry}[2]{\item {#1} #2}