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