diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-01-22 14:29:38 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-01-22 14:29:38 -0200 |
commit | a153cafd8df6c3b6dfd13d3d99d7a39d912dc983 (patch) | |
tree | 1ac8c383952e1bc5539a1b3d2605fb8232f594bd | |
parent | 3b5158f2a1d7e44bc67bab5c443bf034c0e2cb47 (diff) | |
download | lua-a153cafd8df6c3b6dfd13d3d99d7a39d912dc983.tar.gz lua-a153cafd8df6c3b6dfd13d3d99d7a39d912dc983.tar.bz2 lua-a153cafd8df6c3b6dfd13d3d99d7a39d912dc983.zip |
starting translation to new format (@comand{...}).
-rw-r--r-- | manual.tex | 347 |
1 files changed, 178 insertions, 169 deletions
@@ -1,4 +1,4 @@ | |||
1 | % $Id: manual.tex,v 1.65 2003/01/20 11:03:05 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.66 2003/01/21 17:45:11 roberto Exp roberto $ |
2 | %{[( | 2 | %{[( |
3 | 3 | ||
4 | \documentclass[11pt,twoside]{article} | 4 | \documentclass[11pt,twoside]{article} |
@@ -26,7 +26,7 @@ | |||
26 | \newcommand{\Index}[1]{#1\index{#1@{\lowercase{#1}}}} | 26 | \newcommand{\Index}[1]{#1\index{#1@{\lowercase{#1}}}} |
27 | \newcommand{\IndexVerb}[1]{\T{#1}\index{#1@{\tt #1}}} | 27 | \newcommand{\IndexVerb}[1]{\T{#1}\index{#1@{\tt #1}}} |
28 | \newcommand{\IndexEmph}[1]{\emph{#1}\index{#1@{\lowercase{#1}}}} | 28 | \newcommand{\IndexEmph}[1]{\emph{#1}\index{#1@{\lowercase{#1}}}} |
29 | \newcommand{\IndexTM}[1]{\index{#1 event@{``#1'' event}}\index{metamethod!#1}} | 29 | \newcommand{\IndexTM}[1]{\index{#1 event@{\Q{#1} event}}\index{metamethod!#1}} |
30 | \newcommand{\Def}[1]{\emph{#1}\index{#1}} | 30 | \newcommand{\Def}[1]{\emph{#1}\index{#1}} |
31 | \newcommand{\IndexAPI}[1]{\T{#1}\DefAPI{#1}} | 31 | \newcommand{\IndexAPI}[1]{\T{#1}\DefAPI{#1}} |
32 | \newcommand{\IndexLIB}[1]{\T{#1}\DefLIB{#1}} | 32 | \newcommand{\IndexLIB}[1]{\T{#1}\DefLIB{#1}} |
@@ -34,6 +34,11 @@ | |||
34 | \newcommand{\DefAPI}[1]{\index{C API!#1@{\tt #1}}} | 34 | \newcommand{\DefAPI}[1]{\index{C API!#1@{\tt #1}}} |
35 | \newcommand{\IndexKW}[1]{\index{keywords!#1@{\tt #1}}} | 35 | \newcommand{\IndexKW}[1]{\index{keywords!#1@{\tt #1}}} |
36 | 36 | ||
37 | \newcommand{\Q}[1]{``#1''} | ||
38 | \newcommand{\Em}{---} | ||
39 | \newcommand{\En}{--} | ||
40 | \newcommand{\C}[1]{} | ||
41 | |||
37 | \newcommand{\ff}{$\bullet$\ } | 42 | \newcommand{\ff}{$\bullet$\ } |
38 | 43 | ||
39 | \newcommand{\Version}{5.0 (beta)} | 44 | \newcommand{\Version}{5.0 (beta)} |
@@ -134,7 +139,7 @@ Waldemar Celes | |||
134 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 139 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
135 | } | 140 | } |
136 | 141 | ||
137 | %\date{{\small \tt\$Date: 2003/01/20 11:03:05 $ $}} | 142 | %\date{{\small \tt\$Date: 2003/01/21 17:45:11 $ $}} |
138 | 143 | ||
139 | \maketitle | 144 | \maketitle |
140 | 145 | ||
@@ -202,7 +207,8 @@ a intera\c{c}\~ao entre programas Lua e programas C~hospedeiros. | |||
202 | \pagestyle{plain} | 207 | \pagestyle{plain} |
203 | \pagenumbering{arabic} | 208 | \pagenumbering{arabic} |
204 | 209 | ||
205 | %------------------------------------------------------------------------------ | 210 | |
211 | \C{------------------------------------------------------------------------------} | ||
206 | \section{Introduction} | 212 | \section{Introduction} |
207 | 213 | ||
208 | Lua is an extension programming language designed to support | 214 | Lua is an extension programming language designed to support |
@@ -212,7 +218,7 @@ Lua is intended to be used as a powerful, light-weight | |||
212 | configuration language for any program that needs one. | 218 | configuration language for any program that needs one. |
213 | Lua is implemented as a library, written in C. | 219 | Lua is implemented as a library, written in C. |
214 | 220 | ||
215 | Being an extension language, Lua has no notion of a ``main'' program: | 221 | Being an extension language, Lua has no notion of a \Q{main} program: |
216 | it only works \emph{embedded} in a host client, | 222 | it only works \emph{embedded} in a host client, |
217 | called the \emph{embedding program} or simply the \emph{host}. | 223 | called the \emph{embedding program} or simply the \emph{host}. |
218 | This host program can invoke functions to execute a piece of Lua code, | 224 | This host program can invoke functions to execute a piece of Lua code, |
@@ -236,25 +242,25 @@ which are available at Lua's web site. | |||
236 | \begin{itemize} | 242 | \begin{itemize} |
237 | \item | 243 | \item |
238 | R.~Ierusalimschy, L.~H.~de Figueiredo, and W.~Celes. | 244 | R.~Ierusalimschy, L.~H.~de Figueiredo, and W.~Celes. |
239 | Lua---an extensible extension language. | 245 | Lua\Em{}an extensible extension language. |
240 | \emph{Software: Practice \& Experience} {\bf 26} \#6 (1996) 635--652. | 246 | \emph{Software: Practice \& Experience} {\bf 26} \#6 (1996) 635\En{}652. |
241 | \item | 247 | \item |
242 | L.~H.~de Figueiredo, R.~Ierusalimschy, and W.~Celes. | 248 | L.~H.~de Figueiredo, R.~Ierusalimschy, and W.~Celes. |
243 | The design and implementation of a language for extending applications. | 249 | The design and implementation of a language for extending applications. |
244 | \emph{Proceedings of XXI Brazilian Seminar on Software and Hardware} (1994) 273--283. | 250 | \emph{Proceedings of XXI Brazilian Seminar on Software and Hardware} (1994) 273\En{}283. |
245 | \item | 251 | \item |
246 | L.~H.~de Figueiredo, R.~Ierusalimschy, and W.~Celes. | 252 | L.~H.~de Figueiredo, R.~Ierusalimschy, and W.~Celes. |
247 | Lua: an extensible embedded language. | 253 | Lua: an extensible embedded language. |
248 | \emph{Dr. Dobb's Journal} {\bf 21} \#12 (Dec 1996) 26--33. | 254 | \emph{Dr. Dobb's Journal} {\bf 21} \#12 (Dec 1996) 26\En{}33. |
249 | \item | 255 | \item |
250 | R.~Ierusalimschy, L.~H.~de Figueiredo, and W.~Celes. | 256 | R.~Ierusalimschy, L.~H.~de Figueiredo, and W.~Celes. |
251 | The evolution of an extension language: a history of Lua, | 257 | The evolution of an extension language: a history of Lua, |
252 | \emph{Proceedings of V Brazilian Symposium on Programming Languages} (2001) B-14--B-28. | 258 | \emph{Proceedings of V Brazilian Symposium on Programming Languages} (2001) B-14\En{}B-28. |
253 | \end{itemize} | 259 | \end{itemize} |
254 | 260 | ||
255 | Lua means ``moon'' in Portuguese. | 261 | Lua means \Q{moon} in Portuguese. |
256 | 262 | ||
257 | %------------------------------------------------------------------------------ | 263 | \C{------------------------------------------------------------------------------} |
258 | \section{Lua Concepts}\label{concepts} | 264 | \section{Lua Concepts}\label{concepts} |
259 | 265 | ||
260 | This section describes the main concepts of Lua as a language. | 266 | This section describes the main concepts of Lua as a language. |
@@ -513,7 +519,7 @@ If \verb|__mode| contains \verb|v|, | |||
513 | the values in the table are weak. | 519 | the values in the table are weak. |
514 | 520 | ||
515 | 521 | ||
516 | %------------------------------------------------------------------------------ | 522 | \C{------------------------------------------------------------------------------} |
517 | \section{The Language}\label{language} | 523 | \section{The Language}\label{language} |
518 | 524 | ||
519 | This section describes the lexis, the syntax, and the semantics of Lua. | 525 | This section describes the lexis, the syntax, and the semantics of Lua. |
@@ -588,7 +594,7 @@ may contain nested \verb|[[| $\ldots$ \verb|]]| pairs, | |||
588 | and do not interpret escape sequences. | 594 | and do not interpret escape sequences. |
589 | For convenience, | 595 | For convenience, |
590 | when the opening \verb|[[| is immediately followed by a newline, | 596 | when the opening \verb|[[| is immediately followed by a newline, |
591 | the newline is not included in the string. % ]] | 597 | the newline is not included in the string. \C{ ]]} |
592 | That form is specially convenient for | 598 | That form is specially convenient for |
593 | writing strings that contain program pieces or | 599 | writing strings that contain program pieces or |
594 | other quoted strings. | 600 | other quoted strings. |
@@ -631,18 +637,18 @@ in Unix systems \see{lua-sa}. | |||
631 | \subsection{Variables}\label{variables} | 637 | \subsection{Variables}\label{variables} |
632 | 638 | ||
633 | Variables are places that store values. | 639 | Variables are places that store values. |
634 | %In Lua, variables are given by simple identifiers or by table fields. | 640 | \C{In Lua, variables are given by simple identifiers or by table fields.} |
635 | 641 | ||
636 | A single name can denote a global variable, a local variable, | 642 | A single name can denote a global variable, a local variable, |
637 | or a formal parameter in a function | 643 | or a formal parameter in a function |
638 | (formal parameters are just local variables): | 644 | (formal parameters are just local variables): |
639 | \begin{Produc} | 645 | \begin{Produc} |
640 | \produc{var}{\Nter{Name}} | 646 | \produc{var}{\Nter{Name}} |
641 | \end{Produc}% | 647 | \end{Produc} |
642 | Square brackets are used to index a table: | 648 | Square brackets are used to index a table: |
643 | \begin{Produc} | 649 | \begin{Produc} |
644 | \produc{var}{prefixexp \ter{[} exp \ter{]}} | 650 | \produc{var}{prefixexp \ter{[} exp \ter{]}} |
645 | \end{Produc}% | 651 | \end{Produc} |
646 | The first expression should result in a table value, | 652 | The first expression should result in a table value, |
647 | and the second expression identifies a specific entry inside that table. | 653 | and the second expression identifies a specific entry inside that table. |
648 | 654 | ||
@@ -650,7 +656,7 @@ The syntax \verb|var.NAME| is just syntactic sugar for | |||
650 | \verb|var["NAME"]|: | 656 | \verb|var["NAME"]|: |
651 | \begin{Produc} | 657 | \begin{Produc} |
652 | \produc{var}{prefixexp \ter{.} \Nter{Name}} | 658 | \produc{var}{prefixexp \ter{.} \Nter{Name}} |
653 | \end{Produc}% | 659 | \end{Produc} |
654 | 660 | ||
655 | The expression denoting the table to be indexed has a restricted syntax; | 661 | The expression denoting the table to be indexed has a restricted syntax; |
656 | see \See{expressions} for details. | 662 | see \See{expressions} for details. |
@@ -691,19 +697,19 @@ which are executed sequentially. | |||
691 | Each statement can be optionally followed by a semicolon: | 697 | Each statement can be optionally followed by a semicolon: |
692 | \begin{Produc} | 698 | \begin{Produc} |
693 | \produc{chunk}{\rep{stat \opt{\ter{;}}}} | 699 | \produc{chunk}{\rep{stat \opt{\ter{;}}}} |
694 | \end{Produc}% | 700 | \end{Produc} |
695 | 701 | ||
696 | \subsubsection{Blocks} | 702 | \subsubsection{Blocks} |
697 | A \Index{block} is a list of statements; | 703 | A \Index{block} is a list of statements; |
698 | syntactically, a block is equal to a chunk: | 704 | syntactically, a block is equal to a chunk: |
699 | \begin{Produc} | 705 | \begin{Produc} |
700 | \produc{block}{chunk} | 706 | \produc{block}{chunk} |
701 | \end{Produc}% | 707 | \end{Produc} |
702 | 708 | ||
703 | A block may be explicitly delimited to produce a single statement: | 709 | A block may be explicitly delimited to produce a single statement: |
704 | \begin{Produc} | 710 | \begin{Produc} |
705 | \produc{stat}{\rwd{do} block \rwd{end}} | 711 | \produc{stat}{\rwd{do} block \rwd{end}} |
706 | \end{Produc}% | 712 | \end{Produc} |
707 | \IndexKW{do} | 713 | \IndexKW{do} |
708 | Explicit blocks are useful | 714 | Explicit blocks are useful |
709 | to control the scope of variable declarations. | 715 | to control the scope of variable declarations. |
@@ -721,7 +727,7 @@ The elements in both lists are separated by commas: | |||
721 | \produc{stat}{varlist1 \ter{=} explist1} | 727 | \produc{stat}{varlist1 \ter{=} explist1} |
722 | \produc{varlist1}{var \rep{\ter{,} var}} | 728 | \produc{varlist1}{var \rep{\ter{,} var}} |
723 | \produc{explist1}{exp \rep{\ter{,} exp}} | 729 | \produc{explist1}{exp \rep{\ter{,} exp}} |
724 | \end{Produc}% | 730 | \end{Produc} |
725 | Expressions are discussed in \See{expressions}. | 731 | Expressions are discussed in \See{expressions}. |
726 | 732 | ||
727 | Before the assignment, | 733 | Before the assignment, |
@@ -765,7 +771,7 @@ familiar syntax: | |||
765 | \produc{stat}{\rwd{if} exp \rwd{then} block | 771 | \produc{stat}{\rwd{if} exp \rwd{then} block |
766 | \rep{\rwd{elseif} exp \rwd{then} block} | 772 | \rep{\rwd{elseif} exp \rwd{then} block} |
767 | \opt{\rwd{else} block} \rwd{end}} | 773 | \opt{\rwd{else} block} \rwd{end}} |
768 | \end{Produc}% | 774 | \end{Produc} |
769 | Lua also has a \rwd{for} statement, in two flavors \see{for}. | 775 | Lua also has a \rwd{for} statement, in two flavors \see{for}. |
770 | 776 | ||
771 | The \Index{condition expression} \M{exp} of a | 777 | The \Index{condition expression} \M{exp} of a |
@@ -776,13 +782,13 @@ All values different from \nil{} and \False{} are considered true | |||
776 | 782 | ||
777 | The \rwd{return} statement is used to return values | 783 | The \rwd{return} statement is used to return values |
778 | from a function or from a chunk.\IndexKW{return} | 784 | from a function or from a chunk.\IndexKW{return} |
779 | \label{return}% | 785 | \label{return} |
780 | \index{return statement}% | 786 | \index{return statement} |
781 | Functions and chunks may return more than one value, | 787 | Functions and chunks may return more than one value, |
782 | so the syntax for the \rwd{return} statement is | 788 | so the syntax for the \rwd{return} statement is |
783 | \begin{Produc} | 789 | \begin{Produc} |
784 | \produc{stat}{\rwd{return} \opt{explist1}} | 790 | \produc{stat}{\rwd{return} \opt{explist1}} |
785 | \end{Produc}% | 791 | \end{Produc} |
786 | 792 | ||
787 | The \rwd{break} statement can be used to terminate the execution of a | 793 | The \rwd{break} statement can be used to terminate the execution of a |
788 | \rwd{while}, \rwd{repeat}, or \rwd{for} loop, | 794 | \rwd{while}, \rwd{repeat}, or \rwd{for} loop, |
@@ -790,7 +796,7 @@ and to skip to the next statement after the loop:\IndexKW{break} | |||
790 | \index{break statement} | 796 | \index{break statement} |
791 | \begin{Produc} | 797 | \begin{Produc} |
792 | \produc{stat}{\rwd{break}} | 798 | \produc{stat}{\rwd{break}} |
793 | \end{Produc}% | 799 | \end{Produc} |
794 | A \rwd{break} ends the innermost enclosing loop. | 800 | A \rwd{break} ends the innermost enclosing loop. |
795 | 801 | ||
796 | \NOTE | 802 | \NOTE |
@@ -821,7 +827,7 @@ It has the following syntax: | |||
821 | \begin{Produc} | 827 | \begin{Produc} |
822 | \produc{stat}{\rwd{for} \Nter{Name} \ter{=} exp \ter{,} exp \opt{\ter{,} exp} | 828 | \produc{stat}{\rwd{for} \Nter{Name} \ter{=} exp \ter{,} exp \opt{\ter{,} exp} |
823 | \rwd{do} block \rwd{end}} | 829 | \rwd{do} block \rwd{end}} |
824 | \end{Produc}% | 830 | \end{Produc} |
825 | The \emph{block} is repeated for \emph{name} starting at the value of | 831 | The \emph{block} is repeated for \emph{name} starting at the value of |
826 | the first \emph{exp}, until it passes the second \emph{exp} by steps of the | 832 | the first \emph{exp}, until it passes the second \emph{exp} by steps of the |
827 | third \emph{exp}. | 833 | third \emph{exp}. |
@@ -864,7 +870,7 @@ It has the following syntax: | |||
864 | \begin{Produc} | 870 | \begin{Produc} |
865 | \produc{stat}{\rwd{for} \Nter{Name} \rep{\ter{,} \Nter{Name}} \rwd{in} explist1 | 871 | \produc{stat}{\rwd{for} \Nter{Name} \rep{\ter{,} \Nter{Name}} \rwd{in} explist1 |
866 | \rwd{do} block \rwd{end}} | 872 | \rwd{do} block \rwd{end}} |
867 | \end{Produc}% | 873 | \end{Produc} |
868 | A \rwd{for} statement like | 874 | A \rwd{for} statement like |
869 | \begin{verbatim} | 875 | \begin{verbatim} |
870 | for var_1, ..., var_n in explist do block end | 876 | for var_1, ..., var_n in explist do block end |
@@ -883,8 +889,8 @@ is equivalent to the code: | |||
883 | Note the following: | 889 | Note the following: |
884 | \begin{itemize}\itemsep=0pt | 890 | \begin{itemize}\itemsep=0pt |
885 | \item \verb|explist| is evaluated only once. | 891 | \item \verb|explist| is evaluated only once. |
886 | Its results are a ``generator'' function, | 892 | Its results are a \Q{generator} function, |
887 | a ``state'', and an initial value for the first ``iterator variable''. | 893 | a \Q{state}, and an initial value for the first \Q{iterator variable}. |
888 | \item \verb|_f| and \verb|_s| are invisible variables. | 894 | \item \verb|_f| and \verb|_s| are invisible variables. |
889 | The names are here for explanatory purposes only. | 895 | The names are here for explanatory purposes only. |
890 | \item The behavior is \emph{undefined} if you assign to any | 896 | \item The behavior is \emph{undefined} if you assign to any |
@@ -902,7 +908,7 @@ Because of possible side-effects, | |||
902 | function calls can be executed as statements: | 908 | function calls can be executed as statements: |
903 | \begin{Produc} | 909 | \begin{Produc} |
904 | \produc{stat}{functioncall} | 910 | \produc{stat}{functioncall} |
905 | \end{Produc}% | 911 | \end{Produc} |
906 | In this case, all returned values are thrown away. | 912 | In this case, all returned values are thrown away. |
907 | Function calls are explained in \See{functioncall}. | 913 | Function calls are explained in \See{functioncall}. |
908 | 914 | ||
@@ -912,7 +918,7 @@ The declaration may include an initial assignment:\IndexKW{local} | |||
912 | \begin{Produc} | 918 | \begin{Produc} |
913 | \produc{stat}{\rwd{local} namelist \opt{\ter{=} explist1}} | 919 | \produc{stat}{\rwd{local} namelist \opt{\ter{=} explist1}} |
914 | \produc{namelist}{\Nter{Name} \rep{\ter{,} \Nter{Name}}} | 920 | \produc{namelist}{\Nter{Name} \rep{\ter{,} \Nter{Name}}} |
915 | \end{Produc}% | 921 | \end{Produc} |
916 | If present, an initial assignment has the same semantics | 922 | If present, an initial assignment has the same semantics |
917 | of a multiple assignment \see{assignment}. | 923 | of a multiple assignment \see{assignment}. |
918 | Otherwise, all variables are initialized with \nil. | 924 | Otherwise, all variables are initialized with \nil. |
@@ -926,7 +932,7 @@ Visibility rules for local variables are explained in \See{visibility}. | |||
926 | 932 | ||
927 | \subsection{\Index{Expressions}}\label{expressions} | 933 | \subsection{\Index{Expressions}}\label{expressions} |
928 | 934 | ||
929 | %\subsubsection{\Index{Basic Expressions}} | 935 | \C{\subsubsection{\Index{Basic Expressions}}} |
930 | The basic expressions in Lua are the following: | 936 | The basic expressions in Lua are the following: |
931 | \begin{Produc} | 937 | \begin{Produc} |
932 | \produc{exp}{prefixexp} | 938 | \produc{exp}{prefixexp} |
@@ -936,7 +942,7 @@ The basic expressions in Lua are the following: | |||
936 | \produc{exp}{function} | 942 | \produc{exp}{function} |
937 | \produc{exp}{tableconstructor} | 943 | \produc{exp}{tableconstructor} |
938 | \produc{prefixexp}{var \Or functioncall \Or \ter{(} exp \ter{)}} | 944 | \produc{prefixexp}{var \Or functioncall \Or \ter{(} exp \ter{)}} |
939 | \end{Produc}% | 945 | \end{Produc} |
940 | \IndexKW{nil}\IndexKW{false}\IndexKW{true} | 946 | \IndexKW{nil}\IndexKW{false}\IndexKW{true} |
941 | 947 | ||
942 | An expression enclosed in parentheses always results in only one value. | 948 | An expression enclosed in parentheses always results in only one value. |
@@ -985,7 +991,7 @@ Tables, userdata, and functions are compared \emph{by reference}, | |||
985 | that is, | 991 | that is, |
986 | two tables are considered equal only if they are the \emph{same} table. | 992 | two tables are considered equal only if they are the \emph{same} table. |
987 | 993 | ||
988 | %% TODO eq metamethod | 994 | \C{TODO eq metamethod} |
989 | 995 | ||
990 | Every time you create a new table (or userdata, or function), | 996 | Every time you create a new table (or userdata, or function), |
991 | this new value is different from any previously existing value. | 997 | this new value is different from any previously existing value. |
@@ -1004,7 +1010,7 @@ The order operators work as follows. | |||
1004 | If both arguments are numbers, then they are compared as such. | 1010 | If both arguments are numbers, then they are compared as such. |
1005 | Otherwise, if both arguments are strings, | 1011 | Otherwise, if both arguments are strings, |
1006 | then their values are compared according to the current locale. | 1012 | then their values are compared according to the current locale. |
1007 | Otherwise, the ``lt'' or the ``le'' metamethod is called \see{metatable}. | 1013 | Otherwise, the \Q{lt} or the \Q{le} metamethod is called \see{metatable}. |
1008 | 1014 | ||
1009 | 1015 | ||
1010 | \subsubsection{Logical Operators} | 1016 | \subsubsection{Logical Operators} |
@@ -1045,7 +1051,7 @@ The string \Index{concatenation} operator in Lua is | |||
1045 | denoted by two dots (`\verb|..|'). | 1051 | denoted by two dots (`\verb|..|'). |
1046 | If both operands are strings or numbers, then they are converted to | 1052 | If both operands are strings or numbers, then they are converted to |
1047 | strings according to the rules mentioned in \See{coercion}. | 1053 | strings according to the rules mentioned in \See{coercion}. |
1048 | Otherwise, the ``concat'' metamethod is called \see{metatable}. | 1054 | Otherwise, the \Q{concat} metamethod is called \see{metatable}. |
1049 | 1055 | ||
1050 | \subsubsection{Precedence} | 1056 | \subsubsection{Precedence} |
1051 | \Index{Operator precedence} in Lua follows the table below, | 1057 | \Index{Operator precedence} in Lua follows the table below, |
@@ -1076,7 +1082,7 @@ The general syntax for constructors is | |||
1076 | \produc{field}{\ter{[} exp \ter{]} \ter{=} exp \Or | 1082 | \produc{field}{\ter{[} exp \ter{]} \ter{=} exp \Or |
1077 | \Nter{Name} \ter{=} exp \Or exp} | 1083 | \Nter{Name} \ter{=} exp \Or exp} |
1078 | \produc{fieldsep}{\ter{,} \Or \ter{;}} | 1084 | \produc{fieldsep}{\ter{,} \Or \ter{;}} |
1079 | \end{Produc}% | 1085 | \end{Produc} |
1080 | 1086 | ||
1081 | Each field of the form \verb|[exp1] = exp2| adds to the new table an entry | 1087 | Each field of the form \verb|[exp1] = exp2| adds to the new table an entry |
1082 | with key \verb|exp1| and value \verb|exp2|. | 1088 | with key \verb|exp1| and value \verb|exp2|. |
@@ -1119,13 +1125,13 @@ as a convenience for machine-generated code. | |||
1119 | A \Index{function call} in Lua has the following syntax: | 1125 | A \Index{function call} in Lua has the following syntax: |
1120 | \begin{Produc} | 1126 | \begin{Produc} |
1121 | \produc{functioncall}{prefixexp args} | 1127 | \produc{functioncall}{prefixexp args} |
1122 | \end{Produc}% | 1128 | \end{Produc} |
1123 | In a function call, | 1129 | In a function call, |
1124 | first \M{prefixexp} and \M{args} are evaluated. | 1130 | first \M{prefixexp} and \M{args} are evaluated. |
1125 | If the value of \M{prefixexp} has type \emph{function}, | 1131 | If the value of \M{prefixexp} has type \emph{function}, |
1126 | then that function is called, | 1132 | then that function is called, |
1127 | with the given arguments. | 1133 | with the given arguments. |
1128 | Otherwise, its ``call'' metamethod is called, | 1134 | Otherwise, its \Q{call} metamethod is called, |
1129 | having as first parameter the value of \M{prefixexp}, | 1135 | having as first parameter the value of \M{prefixexp}, |
1130 | followed by the original call arguments | 1136 | followed by the original call arguments |
1131 | \see{metatable}. | 1137 | \see{metatable}. |
@@ -1133,8 +1139,8 @@ followed by the original call arguments | |||
1133 | The form | 1139 | The form |
1134 | \begin{Produc} | 1140 | \begin{Produc} |
1135 | \produc{functioncall}{prefixexp \ter{:} \Nter{name} args} | 1141 | \produc{functioncall}{prefixexp \ter{:} \Nter{name} args} |
1136 | \end{Produc}% | 1142 | \end{Produc} |
1137 | can be used to call ``methods''. | 1143 | can be used to call \Q{methods}. |
1138 | A call \verb|v:name(...)| | 1144 | A call \verb|v:name(...)| |
1139 | is syntactic sugar for \verb|v.name(v, ...)|, | 1145 | is syntactic sugar for \verb|v.name(v, ...)|, |
1140 | except that \verb|v| is evaluated only once. | 1146 | except that \verb|v| is evaluated only once. |
@@ -1144,7 +1150,7 @@ Arguments have the following syntax: | |||
1144 | \produc{args}{\ter{(} \opt{explist1} \ter{)}} | 1150 | \produc{args}{\ter{(} \opt{explist1} \ter{)}} |
1145 | \produc{args}{tableconstructor} | 1151 | \produc{args}{tableconstructor} |
1146 | \produc{args}{Literal} | 1152 | \produc{args}{Literal} |
1147 | \end{Produc}% | 1153 | \end{Produc} |
1148 | All argument expressions are evaluated before the call. | 1154 | All argument expressions are evaluated before the call. |
1149 | A call of the form \verb|f{...}| is syntactic sugar for | 1155 | A call of the form \verb|f{...}| is syntactic sugar for |
1150 | \verb|f({...})|, that is, | 1156 | \verb|f({...})|, that is, |
@@ -1209,14 +1215,14 @@ The syntax for function definition is\IndexKW{function} | |||
1209 | \begin{Produc} | 1215 | \begin{Produc} |
1210 | \produc{function}{\rwd{function} funcbody} | 1216 | \produc{function}{\rwd{function} funcbody} |
1211 | \produc{funcbody}{\ter{(} \opt{parlist1} \ter{)} block \rwd{end}} | 1217 | \produc{funcbody}{\ter{(} \opt{parlist1} \ter{)} block \rwd{end}} |
1212 | \end{Produc}% | 1218 | \end{Produc} |
1213 | 1219 | ||
1214 | The following syntactic sugar simplifies function definitions: | 1220 | The following syntactic sugar simplifies function definitions: |
1215 | \begin{Produc} | 1221 | \begin{Produc} |
1216 | \produc{stat}{\rwd{function} funcname funcbody} | 1222 | \produc{stat}{\rwd{function} funcname funcbody} |
1217 | \produc{stat}{\rwd{local} \rwd{function} \Nter{name} funcbody} | 1223 | \produc{stat}{\rwd{local} \rwd{function} \Nter{name} funcbody} |
1218 | \produc{funcname}{\Nter{name} \rep{\ter{.} \Nter{name}} \opt{\ter{:} \Nter{name}}} | 1224 | \produc{funcname}{\Nter{name} \rep{\ter{.} \Nter{name}} \opt{\ter{:} \Nter{name}}} |
1219 | \end{Produc}% | 1225 | \end{Produc} |
1220 | The statement | 1226 | The statement |
1221 | \begin{verbatim} | 1227 | \begin{verbatim} |
1222 | function f () ... end | 1228 | function f () ... end |
@@ -1259,8 +1265,8 @@ initialized with the argument values: | |||
1259 | \begin{Produc} | 1265 | \begin{Produc} |
1260 | \produc{parlist1}{namelist \opt{\ter{,} \ter{\ldots}}} | 1266 | \produc{parlist1}{namelist \opt{\ter{,} \ter{\ldots}}} |
1261 | \produc{parlist1}{\ter{\ldots}} | 1267 | \produc{parlist1}{\ter{\ldots}} |
1262 | \end{Produc}% | 1268 | \end{Produc} |
1263 | \label{vararg}% | 1269 | \label{vararg} |
1264 | When a function is called, | 1270 | When a function is called, |
1265 | the list of \Index{arguments} is adjusted to | 1271 | the list of \Index{arguments} is adjusted to |
1266 | the length of the list of parameters, | 1272 | the length of the list of parameters, |
@@ -1338,7 +1344,7 @@ For instance: | |||
1338 | \end{verbatim} | 1344 | \end{verbatim} |
1339 | Notice that, in a declaration like \verb|local x = x|, | 1345 | Notice that, in a declaration like \verb|local x = x|, |
1340 | the new \verb|x| being declared is not in scope yet, | 1346 | the new \verb|x| being declared is not in scope yet, |
1341 | so the second \verb|x| refers to the ``outside'' variable. | 1347 | so the second \verb|x| refers to the \Q{outside} variable. |
1342 | 1348 | ||
1343 | Because of these \Index{lexical scoping} rules, | 1349 | Because of these \Index{lexical scoping} rules, |
1344 | local variables can be freely accessed by functions | 1350 | local variables can be freely accessed by functions |
@@ -1353,7 +1359,7 @@ For instance: | |||
1353 | \end{verbatim} | 1359 | \end{verbatim} |
1354 | 1360 | ||
1355 | Notice that each execution of a \rwd{local} statement | 1361 | Notice that each execution of a \rwd{local} statement |
1356 | ``creates'' new local variables. | 1362 | \Q{creates} new local variables. |
1357 | Consider the following example: | 1363 | Consider the following example: |
1358 | \begin{verbatim} | 1364 | \begin{verbatim} |
1359 | a = {} | 1365 | a = {} |
@@ -1403,14 +1409,14 @@ Metatables control the operations listed next. | |||
1403 | Each operation is identified by its corresponding name. | 1409 | Each operation is identified by its corresponding name. |
1404 | The key for each operation is a string with its name prefixed by | 1410 | The key for each operation is a string with its name prefixed by |
1405 | two underscores; | 1411 | two underscores; |
1406 | for instance, the key for operation ``add'' is the | 1412 | for instance, the key for operation \Q{add} is the |
1407 | string \verb|"__add"|. | 1413 | string \verb|"__add"|. |
1408 | The semantics of these operations is better explained by a Lua function | 1414 | The semantics of these operations is better explained by a Lua function |
1409 | describing how the interpreter executes that operation. | 1415 | describing how the interpreter executes that operation. |
1410 | %Each function shows how a handler is called, | 1416 | \C{Each function shows how a handler is called,} |
1411 | %its arguments (that is, its signature), | 1417 | \C{its arguments (that is, its signature),} |
1412 | %its results, | 1418 | \C{its results,} |
1413 | %and the default behavior in the absence of a handler. | 1419 | \C{and the default behavior in the absence of a handler.} |
1414 | The code shown here in Lua is only illustrative; | 1420 | The code shown here in Lua is only illustrative; |
1415 | the real behavior is hard coded in the interpreter, | 1421 | the real behavior is hard coded in the interpreter, |
1416 | and it is much more efficient than this simulation. | 1422 | and it is much more efficient than this simulation. |
@@ -1420,7 +1426,7 @@ are described in \See{predefined}. | |||
1420 | 1426 | ||
1421 | \begin{description} | 1427 | \begin{description} |
1422 | 1428 | ||
1423 | \item[``add'':]\IndexTM{add} | 1429 | \item[\Q{add}:]\IndexTM{add} |
1424 | the \verb|+| operation. | 1430 | the \verb|+| operation. |
1425 | 1431 | ||
1426 | The function \verb|getbinhandler| below defines how Lua chooses a handler | 1432 | The function \verb|getbinhandler| below defines how Lua chooses a handler |
@@ -1434,7 +1440,7 @@ then Lua tries the second operand. | |||
1434 | end | 1440 | end |
1435 | \end{verbatim} | 1441 | \end{verbatim} |
1436 | Using that function, | 1442 | Using that function, |
1437 | the behavior of the ``add'' operation is | 1443 | the behavior of the \Q{add} operation is |
1438 | \begin{verbatim} | 1444 | \begin{verbatim} |
1439 | function add_event (op1, op2) | 1445 | function add_event (op1, op2) |
1440 | local o1, o2 = tonumber(op1), tonumber(op2) | 1446 | local o1, o2 = tonumber(op1), tonumber(op2) |
@@ -1452,19 +1458,19 @@ the behavior of the ``add'' operation is | |||
1452 | end | 1458 | end |
1453 | \end{verbatim} | 1459 | \end{verbatim} |
1454 | 1460 | ||
1455 | \item[``sub'':]\IndexTM{sub} | 1461 | \item[\Q{sub}:]\IndexTM{sub} |
1456 | the \verb|-| operation. | 1462 | the \verb|-| operation. |
1457 | Behavior similar to the ``add'' operation. | 1463 | Behavior similar to the \Q{add} operation. |
1458 | 1464 | ||
1459 | \item[``mul'':]\IndexTM{mul} | 1465 | \item[\Q{mul}:]\IndexTM{mul} |
1460 | the \verb|*| operation. | 1466 | the \verb|*| operation. |
1461 | Behavior similar to the ``add'' operation. | 1467 | Behavior similar to the \Q{add} operation. |
1462 | 1468 | ||
1463 | \item[``div'':]\IndexTM{div} | 1469 | \item[\Q{div}:]\IndexTM{div} |
1464 | the \verb|/| operation. | 1470 | the \verb|/| operation. |
1465 | Behavior similar to the ``add'' operation. | 1471 | Behavior similar to the \Q{add} operation. |
1466 | 1472 | ||
1467 | \item[``pow'':]\IndexTM{pow} | 1473 | \item[\Q{pow}:]\IndexTM{pow} |
1468 | the \verb|^| operation (exponentiation) operation. | 1474 | the \verb|^| operation (exponentiation) operation. |
1469 | \begin{verbatim} ?? | 1475 | \begin{verbatim} ?? |
1470 | function pow_event (op1, op2) | 1476 | function pow_event (op1, op2) |
@@ -1478,7 +1484,7 @@ the \verb|^| operation (exponentiation) operation. | |||
1478 | end | 1484 | end |
1479 | \end{verbatim} | 1485 | \end{verbatim} |
1480 | 1486 | ||
1481 | \item[``unm'':]\IndexTM{unm} | 1487 | \item[\Q{unm}:]\IndexTM{unm} |
1482 | the unary \verb|-| operation. | 1488 | the unary \verb|-| operation. |
1483 | \begin{verbatim} | 1489 | \begin{verbatim} |
1484 | function unm_event (op) | 1490 | function unm_event (op) |
@@ -1498,7 +1504,7 @@ the unary \verb|-| operation. | |||
1498 | end | 1504 | end |
1499 | \end{verbatim} | 1505 | \end{verbatim} |
1500 | 1506 | ||
1501 | \item[``lt'':]\IndexTM{lt} | 1507 | \item[\Q{lt}:]\IndexTM{lt} |
1502 | the \verb|<| operation. | 1508 | the \verb|<| operation. |
1503 | \begin{verbatim} | 1509 | \begin{verbatim} |
1504 | function lt_event (op1, op2) | 1510 | function lt_event (op1, op2) |
@@ -1518,7 +1524,7 @@ the \verb|<| operation. | |||
1518 | \end{verbatim} | 1524 | \end{verbatim} |
1519 | \verb|a>b| is equivalent to \verb|b<a|. | 1525 | \verb|a>b| is equivalent to \verb|b<a|. |
1520 | 1526 | ||
1521 | \item[``le'':]\IndexTM{lt} | 1527 | \item[\Q{le}:]\IndexTM{lt} |
1522 | the \verb|<=| operation. | 1528 | the \verb|<=| operation. |
1523 | \begin{verbatim} | 1529 | \begin{verbatim} |
1524 | function le_event (op1, op2) | 1530 | function le_event (op1, op2) |
@@ -1542,12 +1548,12 @@ the \verb|<=| operation. | |||
1542 | end | 1548 | end |
1543 | \end{verbatim} | 1549 | \end{verbatim} |
1544 | \verb|a>=b| is equivalent to \verb|b<=a|. | 1550 | \verb|a>=b| is equivalent to \verb|b<=a|. |
1545 | Notice that, in the absence of a ``le'' metamethod, | 1551 | Notice that, in the absence of a \Q{le} metamethod, |
1546 | Lua tries the ``lt'', assuming that \verb|a<=b| is | 1552 | Lua tries the \Q{lt}, assuming that \verb|a<=b| is |
1547 | equivalent to \verb|not (b<a)|. | 1553 | equivalent to \verb|not (b<a)|. |
1548 | 1554 | ||
1549 | 1555 | ||
1550 | \item[``concat'':]\IndexTM{concatenation} | 1556 | \item[\Q{concat}:]\IndexTM{concatenation} |
1551 | the \verb|..| (concatenation) operation. | 1557 | the \verb|..| (concatenation) operation. |
1552 | \begin{verbatim} | 1558 | \begin{verbatim} |
1553 | function concat_event (op1, op2) | 1559 | function concat_event (op1, op2) |
@@ -1565,8 +1571,8 @@ the \verb|..| (concatenation) operation. | |||
1565 | end | 1571 | end |
1566 | \end{verbatim} | 1572 | \end{verbatim} |
1567 | 1573 | ||
1568 | \item[``index'':]\IndexTM{index} | 1574 | \item[\Q{index}:]\IndexTM{index} |
1569 | The ``gettable'' operation \verb|table[key]|. | 1575 | The \Q{gettable} operation \verb|table[key]|. |
1570 | \begin{verbatim} | 1576 | \begin{verbatim} |
1571 | function gettable_event (table, key) | 1577 | function gettable_event (table, key) |
1572 | local h | 1578 | local h |
@@ -1587,8 +1593,8 @@ The ``gettable'' operation \verb|table[key]|. | |||
1587 | end | 1593 | end |
1588 | \end{verbatim} | 1594 | \end{verbatim} |
1589 | 1595 | ||
1590 | \item[``newindex'':]\IndexTM{index} | 1596 | \item[\Q{newindex}:]\IndexTM{index} |
1591 | The ``settable'' operation \verb|table[key] = value|. | 1597 | The \Q{settable} operation \verb|table[key] = value|. |
1592 | \begin{verbatim} | 1598 | \begin{verbatim} |
1593 | function settable_event (table, key, value) | 1599 | function settable_event (table, key, value) |
1594 | local h | 1600 | local h |
@@ -1610,7 +1616,7 @@ The ``settable'' operation \verb|table[key] = value|. | |||
1610 | \end{verbatim} | 1616 | \end{verbatim} |
1611 | 1617 | ||
1612 | 1618 | ||
1613 | \item[``call'':]\IndexTM{call} | 1619 | \item[\Q{call}:]\IndexTM{call} |
1614 | called when Lua calls a value. | 1620 | called when Lua calls a value. |
1615 | \begin{verbatim} | 1621 | \begin{verbatim} |
1616 | function function_event (func, ...) | 1622 | function function_event (func, ...) |
@@ -1659,7 +1665,7 @@ Lua supports coroutines, | |||
1659 | also called \emph{semi-coroutines} | 1665 | also called \emph{semi-coroutines} |
1660 | or \emph{collaborative multithreading}. | 1666 | or \emph{collaborative multithreading}. |
1661 | A coroutine in Lua represents an independent thread of execution. | 1667 | A coroutine in Lua represents an independent thread of execution. |
1662 | Unlike ``real'' threads, however, | 1668 | Unlike \Q{real} threads, however, |
1663 | a coroutine only suspends its execution by explicitly calling | 1669 | a coroutine only suspends its execution by explicitly calling |
1664 | an yield function. | 1670 | an yield function. |
1665 | 1671 | ||
@@ -1753,7 +1759,7 @@ main false cannot resume dead coroutine | |||
1753 | 1759 | ||
1754 | 1760 | ||
1755 | 1761 | ||
1756 | %------------------------------------------------------------------------------ | 1762 | \C{------------------------------------------------------------------------------} |
1757 | \section{The Application Program Interface}\label{API} | 1763 | \section{The Application Program Interface}\label{API} |
1758 | \index{C API} | 1764 | \index{C API} |
1759 | 1765 | ||
@@ -1764,7 +1770,7 @@ All API functions and related types and constants | |||
1764 | are declared in the header file \verb|lua.h|. | 1770 | are declared in the header file \verb|lua.h|. |
1765 | 1771 | ||
1766 | \NOTE | 1772 | \NOTE |
1767 | Even when we use the term ``function'', | 1773 | Even when we use the term \Q{function}, |
1768 | any facility in the API may be provided as a \emph{macro} instead. | 1774 | any facility in the API may be provided as a \emph{macro} instead. |
1769 | All such macros use each of its arguments exactly once | 1775 | All such macros use each of its arguments exactly once |
1770 | (except for the first argument, which is always a Lua state), | 1776 | (except for the first argument, which is always a Lua state), |
@@ -1801,8 +1807,8 @@ and frees all dynamic memory used by that state. | |||
1801 | On several platforms, you may not need to call this function, | 1807 | On several platforms, you may not need to call this function, |
1802 | because all resources are naturally released when the host program ends. | 1808 | because all resources are naturally released when the host program ends. |
1803 | On the other hand, | 1809 | On the other hand, |
1804 | long-running programs --- | 1810 | long-running programs \Em{} |
1805 | like a daemon or a web server --- | 1811 | like a daemon or a web server \Em{} |
1806 | might need to release states as soon as they are not needed, | 1812 | might need to release states as soon as they are not needed, |
1807 | to avoid growing too large. | 1813 | to avoid growing too large. |
1808 | 1814 | ||
@@ -1813,7 +1819,7 @@ Lua offers partial support for multiple threads of execution. | |||
1813 | If you have a C~library that offers multi-threading, | 1819 | If you have a C~library that offers multi-threading, |
1814 | then Lua can cooperate with it to implement the equivalent facility in Lua. | 1820 | then Lua can cooperate with it to implement the equivalent facility in Lua. |
1815 | Also, Lua implements its own coroutine system on top of threads. | 1821 | Also, Lua implements its own coroutine system on top of threads. |
1816 | The following function creates a new ``thread'' in Lua: | 1822 | The following function creates a new \Q{thread} in Lua: |
1817 | \begin{verbatim} | 1823 | \begin{verbatim} |
1818 | lua_State *lua_newthread (lua_State *L); | 1824 | lua_State *lua_newthread (lua_State *L); |
1819 | \end{verbatim} | 1825 | \end{verbatim} |
@@ -1821,7 +1827,7 @@ The following function creates a new ``thread'' in Lua: | |||
1821 | The new state returned by this function shares with the original state | 1827 | The new state returned by this function shares with the original state |
1822 | all global environment (such as tables), | 1828 | all global environment (such as tables), |
1823 | but has an independent run-time stack. | 1829 | but has an independent run-time stack. |
1824 | (The use of these multiple stacks must be ``synchronized'' with C. | 1830 | (The use of these multiple stacks must be \Q{synchronized} with C. |
1825 | How to explain that? TO BE WRITTEN.) | 1831 | How to explain that? TO BE WRITTEN.) |
1826 | 1832 | ||
1827 | Each thread has an independent table for global variables. | 1833 | Each thread has an independent table for global variables. |
@@ -1997,7 +2003,7 @@ These functions can be called with any acceptable index. | |||
1997 | 2003 | ||
1998 | \verb|lua_type| returns the type of a value in the stack, | 2004 | \verb|lua_type| returns the type of a value in the stack, |
1999 | or \verb|LUA_TNONE| for a non-valid index | 2005 | or \verb|LUA_TNONE| for a non-valid index |
2000 | (that is, if that stack position is ``empty''). | 2006 | (that is, if that stack position is \Q{empty}). |
2001 | The types are coded by the following constants | 2007 | The types are coded by the following constants |
2002 | defined in \verb|lua.h|: | 2008 | defined in \verb|lua.h|: |
2003 | \verb|LUA_TNIL|, | 2009 | \verb|LUA_TNIL|, |
@@ -2061,7 +2067,7 @@ When called with a non-valid index, | |||
2061 | they act as if the given value had an incorrect type. | 2067 | they act as if the given value had an incorrect type. |
2062 | 2068 | ||
2063 | \verb|lua_toboolean| converts the Lua value at the given index | 2069 | \verb|lua_toboolean| converts the Lua value at the given index |
2064 | to a C ``boolean'' value (that is, 0 or 1). | 2070 | to a C \Q{boolean} value (that is, 0 or 1). |
2065 | Like all tests in Lua, it returns 1 for any Lua value different from | 2071 | Like all tests in Lua, it returns 1 for any Lua value different from |
2066 | \False{} and \nil; | 2072 | \False{} and \nil; |
2067 | otherwise it returns 0. | 2073 | otherwise it returns 0. |
@@ -2132,7 +2138,7 @@ make an internal copy of the given string. | |||
2132 | otherwise, you should use the more general \verb|lua_pushlstring|, | 2138 | otherwise, you should use the more general \verb|lua_pushlstring|, |
2133 | which accepts an explicit size. | 2139 | which accepts an explicit size. |
2134 | 2140 | ||
2135 | You can also push ``formatted'' strings: | 2141 | You can also push \Q{formatted} strings: |
2136 | \begin{verbatim} | 2142 | \begin{verbatim} |
2137 | const char *lua_pushfstring (lua_State *L, const char *fmt, ...); | 2143 | const char *lua_pushfstring (lua_State *L, const char *fmt, ...); |
2138 | const char *lua_pushvfstring (lua_State *L, const char *fmt, | 2144 | const char *lua_pushvfstring (lua_State *L, const char *fmt, |
@@ -2191,11 +2197,11 @@ In particular | |||
2191 | After the collection, | 2197 | After the collection, |
2192 | a new threshold is set according to the previous rule. | 2198 | a new threshold is set according to the previous rule. |
2193 | 2199 | ||
2194 | %% TODO do we need a new way to do that?? | 2200 | \C{TODO do we need a new way to do that??} |
2195 | % If you want to change the adaptive behavior of the garbage collector, | 2201 | \C{ If you want to change the adaptive behavior of the garbage collector,} |
2196 | % you can use the garbage-collection tag method for \nil{} % | 2202 | \C{ you can use the garbage-collection tag method for \nil{} } |
2197 | % to set your own threshold | 2203 | \C{ to set your own threshold} |
2198 | % (the tag method is called after Lua resets the threshold). | 2204 | \C{ (the tag method is called after Lua resets the threshold).} |
2199 | 2205 | ||
2200 | 2206 | ||
2201 | \subsection{Userdata}\label{userdata} | 2207 | \subsection{Userdata}\label{userdata} |
@@ -2214,7 +2220,7 @@ A light userdata represents a pointer. | |||
2214 | It is a value (like a number): | 2220 | It is a value (like a number): |
2215 | You do not create it, it has no metatables, | 2221 | You do not create it, it has no metatables, |
2216 | it is not collected (as it was never created). | 2222 | it is not collected (as it was never created). |
2217 | A light userdata is equal to ``any'' | 2223 | A light userdata is equal to \Q{any} |
2218 | light userdata with the same address. | 2224 | light userdata with the same address. |
2219 | 2225 | ||
2220 | In Lua code, there is no way to test whether a userdata is full or light; | 2226 | In Lua code, there is no way to test whether a userdata is full or light; |
@@ -2278,10 +2284,10 @@ You can load a Lua chunk with | |||
2278 | \DefAPI{Chunkreader}\DefAPI{lua_load} | 2284 | \DefAPI{Chunkreader}\DefAPI{lua_load} |
2279 | The return values of \verb|lua_load| are: | 2285 | The return values of \verb|lua_load| are: |
2280 | \begin{itemize} | 2286 | \begin{itemize} |
2281 | \item 0 --- no errors; | 2287 | \item 0 \Em{} no errors; |
2282 | \item \IndexAPI{LUA_ERRSYNTAX} --- | 2288 | \item \IndexAPI{LUA_ERRSYNTAX} \Em{} |
2283 | syntax error during pre-compilation. | 2289 | syntax error during pre-compilation. |
2284 | \item \IndexAPI{LUA_ERRMEM} --- | 2290 | \item \IndexAPI{LUA_ERRMEM} \Em{} |
2285 | memory allocation error. | 2291 | memory allocation error. |
2286 | \end{itemize} | 2292 | \end{itemize} |
2287 | If there are no errors, | 2293 | If there are no errors, |
@@ -2337,7 +2343,7 @@ The table is left where it was in the stack; | |||
2337 | this is convenient for getting multiple values from a table. | 2343 | this is convenient for getting multiple values from a table. |
2338 | 2344 | ||
2339 | As in Lua, this function may trigger a metamethod | 2345 | As in Lua, this function may trigger a metamethod |
2340 | for the ``index'' event \see{metatable}. | 2346 | for the \Q{index} event \see{metatable}. |
2341 | To get the real value of any table key, | 2347 | To get the real value of any table key, |
2342 | without invoking any metamethod, | 2348 | without invoking any metamethod, |
2343 | use the \emph{raw} version: | 2349 | use the \emph{raw} version: |
@@ -2360,7 +2366,7 @@ The table is left where it was in the stack; | |||
2360 | this is convenient for setting multiple values in a table. | 2366 | this is convenient for setting multiple values in a table. |
2361 | 2367 | ||
2362 | As in Lua, this operation may trigger a metamethod | 2368 | As in Lua, this operation may trigger a metamethod |
2363 | for the ``settable'' or ``newindex'' events. | 2369 | for the \Q{settable} or \Q{newindex} events. |
2364 | To set the real value of any table index, | 2370 | To set the real value of any table index, |
2365 | without invoking any metamethod, | 2371 | without invoking any metamethod, |
2366 | use the \emph{raw} version: | 2372 | use the \emph{raw} version: |
@@ -2377,7 +2383,7 @@ You can traverse a table with the function | |||
2377 | where \verb|index| points to the table to be traversed. | 2383 | where \verb|index| points to the table to be traversed. |
2378 | The function pops a key from the stack, | 2384 | The function pops a key from the stack, |
2379 | and pushes a key-value pair from the table | 2385 | and pushes a key-value pair from the table |
2380 | (the ``next'' pair after the given key). | 2386 | (the \Q{next} pair after the given key). |
2381 | If there are no more elements, then \verb|lua_next| returns 0 | 2387 | If there are no more elements, then \verb|lua_next| returns 0 |
2382 | (and pushes nothing). | 2388 | (and pushes nothing). |
2383 | Use a \nil{} key to signal the start of a traversal. | 2389 | Use a \nil{} key to signal the start of a traversal. |
@@ -2480,7 +2486,7 @@ Here it is in~C: | |||
2480 | lua_settable(L, LUA_GLOBALSINDEX); /* set global variable `a' */ | 2486 | lua_settable(L, LUA_GLOBALSINDEX); /* set global variable `a' */ |
2481 | lua_pop(L, 1); /* remove `t' from the stack */ | 2487 | lua_pop(L, 1); /* remove `t' from the stack */ |
2482 | \end{verbatim} | 2488 | \end{verbatim} |
2483 | Notice that the code above is ``balanced'': | 2489 | Notice that the code above is \Q{balanced}: |
2484 | at its end, the stack is back to its original configuration. | 2490 | at its end, the stack is back to its original configuration. |
2485 | This is considered good programming practice. | 2491 | This is considered good programming practice. |
2486 | 2492 | ||
@@ -2530,10 +2536,10 @@ The \verb|lua_pcall| function returns 0 in case of success, | |||
2530 | or one of the following error codes | 2536 | or one of the following error codes |
2531 | (defined in \verb|lua.h|): | 2537 | (defined in \verb|lua.h|): |
2532 | \begin{itemize} | 2538 | \begin{itemize} |
2533 | \item \IndexAPI{LUA_ERRRUN} --- a runtime error. | 2539 | \item \IndexAPI{LUA_ERRRUN} \Em{} a runtime error. |
2534 | \item \IndexAPI{LUA_ERRMEM} --- memory allocation error. | 2540 | \item \IndexAPI{LUA_ERRMEM} \Em{} memory allocation error. |
2535 | For such errors, Lua does not call the error handler function. | 2541 | For such errors, Lua does not call the error handler function. |
2536 | \item \IndexAPI{LUA_ERRERR} --- | 2542 | \item \IndexAPI{LUA_ERRERR} \Em{} |
2537 | error while running the error handler function. | 2543 | error while running the error handler function. |
2538 | \end{itemize} | 2544 | \end{itemize} |
2539 | 2545 | ||
@@ -2541,7 +2547,7 @@ error while running the error handler function. | |||
2541 | \medskip | 2547 | \medskip |
2542 | 2548 | ||
2543 | >>>> | 2549 | >>>> |
2544 | %% TODO: mover essas 2 para algum lugar melhor. | 2550 | \C{ TODO: mover essas 2 para algum lugar melhor.} |
2545 | Some special Lua functions have their own C~interfaces. | 2551 | Some special Lua functions have their own C~interfaces. |
2546 | The host program can generate a Lua error calling the function | 2552 | The host program can generate a Lua error calling the function |
2547 | \begin{verbatim} | 2553 | \begin{verbatim} |
@@ -2557,7 +2563,7 @@ then the corresponding Lua execution terminates, | |||
2557 | as if an error had occurred inside Lua code. | 2563 | as if an error had occurred inside Lua code. |
2558 | Otherwise, the whole host program terminates with a call to | 2564 | Otherwise, the whole host program terminates with a call to |
2559 | \verb|exit(EXIT_FAILURE)|. | 2565 | \verb|exit(EXIT_FAILURE)|. |
2560 | %% TODO: at_panic | 2566 | \C{ TODO: at_panic} |
2561 | 2567 | ||
2562 | The function | 2568 | The function |
2563 | \begin{verbatim} | 2569 | \begin{verbatim} |
@@ -2690,7 +2696,7 @@ implemented by the auxiliary library, | |||
2690 | and therefore should not be used by other purposes. | 2696 | and therefore should not be used by other purposes. |
2691 | 2697 | ||
2692 | 2698 | ||
2693 | %------------------------------------------------------------------------------ | 2699 | \C{------------------------------------------------------------------------------} |
2694 | \section{The Debug Interface} \label{debugI} | 2700 | \section{The Debug Interface} \label{debugI} |
2695 | 2701 | ||
2696 | Lua has no built-in debugging facilities. | 2702 | Lua has no built-in debugging facilities. |
@@ -2698,7 +2704,7 @@ Instead, it offers a special interface | |||
2698 | by means of functions and \emph{hooks}. | 2704 | by means of functions and \emph{hooks}. |
2699 | This interface allows the construction of different | 2705 | This interface allows the construction of different |
2700 | kinds of debuggers, profilers, and other tools | 2706 | kinds of debuggers, profilers, and other tools |
2701 | that need ``inside information'' from the interpreter. | 2707 | that need \Q{inside information} from the interpreter. |
2702 | 2708 | ||
2703 | \subsection{Stack and Function Information} | 2709 | \subsection{Stack and Function Information} |
2704 | 2710 | ||
@@ -2778,7 +2784,7 @@ if the function was defined in a file, | |||
2778 | then \verb|source| starts with a \verb|@| followed by the file name. | 2784 | then \verb|source| starts with a \verb|@| followed by the file name. |
2779 | 2785 | ||
2780 | \item[short\_src] | 2786 | \item[short\_src] |
2781 | A ``printable'' version of \verb|source|, to be used in error messages. | 2787 | A \Q{printable} version of \verb|source|, to be used in error messages. |
2782 | 2788 | ||
2783 | \item[linedefined] | 2789 | \item[linedefined] |
2784 | the line number where the definition of the function starts. | 2790 | the line number where the definition of the function starts. |
@@ -2869,7 +2875,7 @@ A hook may be called in four different events: | |||
2869 | a \emph{call} event, when Lua calls a function; | 2875 | a \emph{call} event, when Lua calls a function; |
2870 | a \emph{return} event, when Lua returns from a function; | 2876 | a \emph{return} event, when Lua returns from a function; |
2871 | a \emph{line} event, when Lua starts executing a new line of code; | 2877 | a \emph{line} event, when Lua starts executing a new line of code; |
2872 | and a \emph{count} event, which happens every ``count'' instructions. | 2878 | and a \emph{count} event, which happens every \Q{count} instructions. |
2873 | Lua identifies them with the following constants: | 2879 | Lua identifies them with the following constants: |
2874 | \verb|LUA_HOOKCALL|\DefAPI{LUA_HOOKCALL}, | 2880 | \verb|LUA_HOOKCALL|\DefAPI{LUA_HOOKCALL}, |
2875 | \verb|LUA_HOOKRET|\DefAPI{LUA_HOOKRET}, | 2881 | \verb|LUA_HOOKRET|\DefAPI{LUA_HOOKRET}, |
@@ -2896,9 +2902,9 @@ plus the macro \verb|LUA_MASKCOUNT(count)|. | |||
2896 | For each event, the hook is called as explained below: | 2902 | For each event, the hook is called as explained below: |
2897 | \begin{description} | 2903 | \begin{description} |
2898 | \item{The call hook} is called when the interpreter calls a function. | 2904 | \item{The call hook} is called when the interpreter calls a function. |
2899 | The hook is called just after Lua ``enters'' the new function. | 2905 | The hook is called just after Lua \Q{enters} the new function. |
2900 | \item{The return hook} is called when the interpreter returns from a function. | 2906 | \item{The return hook} is called when the interpreter returns from a function. |
2901 | The hook is called just before Lua ``leaves'' the function. | 2907 | The hook is called just before Lua \Q{leaves} the function. |
2902 | \item{The line hook} is called when the interpreter is about to | 2908 | \item{The line hook} is called when the interpreter is about to |
2903 | start the execution of a new line of code, | 2909 | start the execution of a new line of code, |
2904 | or when it jumps back (even for the same line). | 2910 | or when it jumps back (even for the same line). |
@@ -2930,14 +2936,14 @@ Therefore, if a hook calls Lua to execute a function or a chunk, | |||
2930 | that execution occurs without any calls to hooks. | 2936 | that execution occurs without any calls to hooks. |
2931 | 2937 | ||
2932 | 2938 | ||
2933 | %------------------------------------------------------------------------------ | 2939 | \C{------------------------------------------------------------------------------} |
2934 | \section{Standard Libraries}\label{libraries} | 2940 | \section{Standard Libraries}\label{libraries} |
2935 | 2941 | ||
2936 | The standard libraries provide useful functions | 2942 | The standard libraries provide useful functions |
2937 | that are implemented directly through the standard C~API. | 2943 | that are implemented directly through the standard C~API. |
2938 | Some of these functions provide essential services to the language | 2944 | Some of these functions provide essential services to the language |
2939 | (e.g. \verb|type| and \verb|getmetatable|); | 2945 | (e.g. \verb|type| and \verb|getmetatable|); |
2940 | others provide access to ``outside'' services (e.g. I/O); | 2946 | others provide access to \Q{outside} services (e.g. I/O); |
2941 | and others could be implemented in Lua itself, | 2947 | and others could be implemented in Lua itself, |
2942 | but are quite useful or have critical performance to | 2948 | but are quite useful or have critical performance to |
2943 | deserve an implementation in C (e.g. \verb|sort|). | 2949 | deserve an implementation in C (e.g. \verb|sort|). |
@@ -2987,8 +2993,8 @@ with a string containing the current interpreter version. | |||
2987 | The current content of this string is {\tt "Lua \Version"}. | 2993 | The current content of this string is {\tt "Lua \Version"}. |
2988 | 2994 | ||
2989 | \subsubsection*{\ff \T{assert (v [, message])}}\DefLIB{assert} | 2995 | \subsubsection*{\ff \T{assert (v [, message])}}\DefLIB{assert} |
2990 | Issues an \emph{``assertion failed!''} error | 2996 | Issues an \emph{\Q{assertion failed!}} error |
2991 | when its argument \verb|v| is \nil{} or \false; | 2997 | when its argument \verb|v| is \nil{} or \False; |
2992 | otherwise, returns this argument. | 2998 | otherwise, returns this argument. |
2993 | This function is equivalent to the following Lua function: | 2999 | This function is equivalent to the following Lua function: |
2994 | \begin{verbatim} | 3000 | \begin{verbatim} |
@@ -3035,7 +3041,7 @@ Returns the current table of globals in use by the function. | |||
3035 | which specifies the function at that stack level: | 3041 | which specifies the function at that stack level: |
3036 | Level 1 is the function calling \verb|getglobals|. | 3042 | Level 1 is the function calling \verb|getglobals|. |
3037 | If the given function is not a Lua function, | 3043 | If the given function is not a Lua function, |
3038 | returns the ``global'' table of globals. | 3044 | returns the \Q{global} table of globals. |
3039 | The default for \verb|function| is 1. | 3045 | The default for \verb|function| is 1. |
3040 | 3046 | ||
3041 | \subsubsection*{\ff \T{getmetatable (object)}} | 3047 | \subsubsection*{\ff \T{getmetatable (object)}} |
@@ -3072,7 +3078,7 @@ returns the compiled chunk as a function; | |||
3072 | otherwise, returns \nil{} plus an error message. | 3078 | otherwise, returns \nil{} plus an error message. |
3073 | 3079 | ||
3074 | The optional parameter \verb|chunkname| | 3080 | The optional parameter \verb|chunkname| |
3075 | is the ``name of the chunk'', | 3081 | is the \Q{name of the chunk}, |
3076 | which is used in error messages and debug information. | 3082 | which is used in error messages and debug information. |
3077 | 3083 | ||
3078 | To load and run a given string, use the idiom | 3084 | To load and run a given string, use the idiom |
@@ -3113,7 +3119,7 @@ so that the construction | |||
3113 | \begin{verbatim} | 3119 | \begin{verbatim} |
3114 | for k,v in pairs(t) do ... end | 3120 | for k,v in pairs(t) do ... end |
3115 | \end{verbatim} | 3121 | \end{verbatim} |
3116 | will iterate over all pairs of key--value of table \verb|t|. | 3122 | will iterate over all pairs of key\En{}value of table \verb|t|. |
3117 | 3123 | ||
3118 | \subsubsection*{\ff \T{pcall (func, arg1, arg2, ...)}}\DefLIB{pcall} | 3124 | \subsubsection*{\ff \T{pcall (func, arg1, arg2, ...)}}\DefLIB{pcall} |
3119 | \label{pdf-pcall} | 3125 | \label{pdf-pcall} |
@@ -3285,8 +3291,8 @@ where to start the search; | |||
3285 | its default value is~1, and may be negative. | 3291 | its default value is~1, and may be negative. |
3286 | A value of \True{} as a fourth, optional argument \verb|plain| | 3292 | A value of \True{} as a fourth, optional argument \verb|plain| |
3287 | turns off the pattern matching facilities, | 3293 | turns off the pattern matching facilities, |
3288 | so the function does a plain ``find substring'' operation, | 3294 | so the function does a plain \Q{find substring} operation, |
3289 | with no characters in \verb|pattern| being considered ``magic''. | 3295 | with no characters in \verb|pattern| being considered \Q{magic}. |
3290 | Note that if \verb|plain| is given, then \verb|init| must be given too. | 3296 | Note that if \verb|plain| is given, then \verb|init| must be given too. |
3291 | 3297 | ||
3292 | \subsubsection*{\ff \T{string.len (s)}}\DefLIB{string.len} | 3298 | \subsubsection*{\ff \T{string.len (s)}}\DefLIB{string.len} |
@@ -3451,26 +3457,26 @@ The following combinations are allowed in describing a character class: | |||
3451 | \begin{description}\leftskip=20pt | 3457 | \begin{description}\leftskip=20pt |
3452 | \item[\emph{x}] (where \emph{x} is not one of the magic characters | 3458 | \item[\emph{x}] (where \emph{x} is not one of the magic characters |
3453 | \verb|^$()%.[]*+-?|) | 3459 | \verb|^$()%.[]*+-?|) |
3454 | --- represents the character \emph{x} itself. | 3460 | \Em{} represents the character \emph{x} itself. |
3455 | \item[\T{.}] --- (a dot) represents all characters. | 3461 | \item[\T{.}] \Em{} (a dot) represents all characters. |
3456 | \item[\T{\%a}] --- represents all letters. | 3462 | \item[\T{\%a}] \Em{} represents all letters. |
3457 | \item[\T{\%c}] --- represents all control characters. | 3463 | \item[\T{\%c}] \Em{} represents all control characters. |
3458 | \item[\T{\%d}] --- represents all digits. | 3464 | \item[\T{\%d}] \Em{} represents all digits. |
3459 | \item[\T{\%l}] --- represents all lowercase letters. | 3465 | \item[\T{\%l}] \Em{} represents all lowercase letters. |
3460 | \item[\T{\%p}] --- represents all punctuation characters. | 3466 | \item[\T{\%p}] \Em{} represents all punctuation characters. |
3461 | \item[\T{\%s}] --- represents all space characters. | 3467 | \item[\T{\%s}] \Em{} represents all space characters. |
3462 | \item[\T{\%u}] --- represents all uppercase letters. | 3468 | \item[\T{\%u}] \Em{} represents all uppercase letters. |
3463 | \item[\T{\%w}] --- represents all alphanumeric characters. | 3469 | \item[\T{\%w}] \Em{} represents all alphanumeric characters. |
3464 | \item[\T{\%x}] --- represents all hexadecimal digits. | 3470 | \item[\T{\%x}] \Em{} represents all hexadecimal digits. |
3465 | \item[\T{\%z}] --- represents the character with representation 0. | 3471 | \item[\T{\%z}] \Em{} represents the character with representation 0. |
3466 | \item[\T{\%\M{x}}] (where \M{x} is any non-alphanumeric character) --- | 3472 | \item[\T{\%\M{x}}] (where \M{x} is any non-alphanumeric character) \Em{} |
3467 | represents the character \M{x}. | 3473 | represents the character \M{x}. |
3468 | This is the standard way to escape the magic characters. | 3474 | This is the standard way to escape the magic characters. |
3469 | We recommend that any punctuation character (even the non magic) | 3475 | We recommend that any punctuation character (even the non magic) |
3470 | should be preceded by a \verb|%| | 3476 | should be preceded by a \verb|%| |
3471 | when used to represent itself in a pattern. | 3477 | when used to represent itself in a pattern. |
3472 | 3478 | ||
3473 | \item[\T{[\M{set}]}] --- | 3479 | \item[\T{[\M{set}]}] \Em{} |
3474 | represents the class which is the union of all | 3480 | represents the class which is the union of all |
3475 | characters in \M{set}. | 3481 | characters in \M{set}. |
3476 | A range of characters may be specified by | 3482 | A range of characters may be specified by |
@@ -3488,7 +3494,7 @@ The interaction between ranges and classes is not defined. | |||
3488 | Therefore, patterns like \verb|[%a-z]| or \verb|[a-%%]| | 3494 | Therefore, patterns like \verb|[%a-z]| or \verb|[a-%%]| |
3489 | have no meaning. | 3495 | have no meaning. |
3490 | 3496 | ||
3491 | \item[\T{[\^\null\M{set}]}] --- | 3497 | \item[\T{[\^\null\M{set}]}] \Em{} |
3492 | represents the complement of \M{set}, | 3498 | represents the complement of \M{set}, |
3493 | where \M{set} is interpreted as above. | 3499 | where \M{set} is interpreted as above. |
3494 | \end{description} | 3500 | \end{description} |
@@ -3576,13 +3582,13 @@ represents an array or a list. | |||
3576 | For those functions, an important concept is the \emph{size} of the array. | 3582 | For those functions, an important concept is the \emph{size} of the array. |
3577 | There are three ways to specify that size: | 3583 | There are three ways to specify that size: |
3578 | \begin{itemize} | 3584 | \begin{itemize} |
3579 | \item the field \verb|"n"| --- | 3585 | \item the field \verb|"n"| \Em{} |
3580 | When the table has a field \verb|"n"| with a numerical value, | 3586 | When the table has a field \verb|"n"| with a numerical value, |
3581 | that value is assumed as its size. | 3587 | that value is assumed as its size. |
3582 | \item \verb|setn| --- | 3588 | \item \verb|setn| \Em{} |
3583 | You can call the \verb|table.setn| function to explicitly set | 3589 | You can call the \verb|table.setn| function to explicitly set |
3584 | the size of a table. | 3590 | the size of a table. |
3585 | \item implicit size --- | 3591 | \item implicit size \Em{} |
3586 | Otherwise, the size of the object is one less the first integer index | 3592 | Otherwise, the size of the object is one less the first integer index |
3587 | with a \nil{} value. | 3593 | with a \nil{} value. |
3588 | \end{itemize} | 3594 | \end{itemize} |
@@ -3622,13 +3628,13 @@ then the loop is broken, and this value is returned | |||
3622 | as the final value of \verb|foreachi|. | 3628 | as the final value of \verb|foreachi|. |
3623 | 3629 | ||
3624 | \subsubsection*{\ff \T{table.getn (table)}}\DefLIB{table.getn}\label{getn} | 3630 | \subsubsection*{\ff \T{table.getn (table)}}\DefLIB{table.getn}\label{getn} |
3625 | Returns the ``size'' of a table, when seen as a list. | 3631 | Returns the \Q{size} of a table, when seen as a list. |
3626 | If the table has an \verb|n| field with a numeric value, | 3632 | If the table has an \verb|n| field with a numeric value, |
3627 | this value is the ``size'' of the table. | 3633 | this value is the \Q{size} of the table. |
3628 | Otherwise, if there was a previous call to | 3634 | Otherwise, if there was a previous call to |
3629 | \verb|table.getn| or to \verb|table.setn| over this table, | 3635 | \verb|table.getn| or to \verb|table.setn| over this table, |
3630 | the respective value is returned. | 3636 | the respective value is returned. |
3631 | Otherwise, the ``size'' is one less the first integer index with | 3637 | Otherwise, the \Q{size} is one less the first integer index with |
3632 | a \nil{} value. | 3638 | a \nil{} value. |
3633 | 3639 | ||
3634 | Notice that the last option happens only once for a table. | 3640 | Notice that the last option happens only once for a table. |
@@ -3679,7 +3685,7 @@ calling \verb|table.setn(table, n-1)|. | |||
3679 | 3685 | ||
3680 | \subsubsection*{\ff \T{table.setn (table, n)}}\DefLIB{table.setn} | 3686 | \subsubsection*{\ff \T{table.setn (table, n)}}\DefLIB{table.setn} |
3681 | 3687 | ||
3682 | Updates the ``size'' of a table. | 3688 | Updates the \Q{size} of a table. |
3683 | If the table has a field \verb|"n"| with a numerical value, | 3689 | If the table has a field \verb|"n"| with a numerical value, |
3684 | that value is changed to the given \verb|n|. | 3690 | that value is changed to the given \verb|n|. |
3685 | Otherwise, it updates an internal state of the \verb|table| library | 3691 | Otherwise, it updates an internal state of the \verb|table| library |
@@ -3731,12 +3737,12 @@ are interfaces to the simple random generator functions | |||
3731 | (No guarantees can be given for their statistical properties.) | 3737 | (No guarantees can be given for their statistical properties.) |
3732 | When called without arguments, | 3738 | When called without arguments, |
3733 | \verb|math.random| returns a pseudo-random real number | 3739 | \verb|math.random| returns a pseudo-random real number |
3734 | in the range \Math{[0,1)}. %] | 3740 | in the range \Math{[0,1)}. \C{]} |
3735 | When called with a number \Math{n}, | 3741 | When called with a number \Math{n}, |
3736 | \verb|math.random| returns a pseudo-random integer in the range \Math{[1,n]}. | 3742 | \verb|math.random| returns a pseudo-random integer in the range \Math{[1,n]}. |
3737 | When called with two arguments, \Math{l} and \Math{u}, | 3743 | When called with two arguments, \Math{l} and \Math{u}, |
3738 | \verb|math.random| returns a pseudo-random integer in the range \Math{[l,u]}. | 3744 | \verb|math.random| returns a pseudo-random integer in the range \Math{[l,u]}. |
3739 | The \verb|math.randomseed| function sets a ``seed'' | 3745 | The \verb|math.randomseed| function sets a \Q{seed} |
3740 | for the pseudo-random generator: | 3746 | for the pseudo-random generator: |
3741 | Equal seeds produce equal sequences of numbers. | 3747 | Equal seeds produce equal sequences of numbers. |
3742 | 3748 | ||
@@ -3817,12 +3823,12 @@ or, in case of errors, \nil{} plus an error message. | |||
3817 | 3823 | ||
3818 | The \verb|mode| string can be any of the following: | 3824 | The \verb|mode| string can be any of the following: |
3819 | \begin{description}\leftskip=20pt | 3825 | \begin{description}\leftskip=20pt |
3820 | \item[``r''] read mode (the default); | 3826 | \item[\Q{r}] read mode (the default); |
3821 | \item[``w''] write mode; | 3827 | \item[\Q{w}] write mode; |
3822 | \item[``a''] append mode; | 3828 | \item[\Q{a}] append mode; |
3823 | \item[``r+''] update mode, all previous data is preserved; | 3829 | \item[\Q{r+}] update mode, all previous data is preserved; |
3824 | \item[``w+''] update mode, all previous data is erased; | 3830 | \item[\Q{w+}] update mode, all previous data is erased; |
3825 | \item[``a+''] append update mode, previous data is preserved, | 3831 | \item[\Q{a+}] append update mode, previous data is preserved, |
3826 | writing is only allowed at the end of file. | 3832 | writing is only allowed at the end of file. |
3827 | \end{description} | 3833 | \end{description} |
3828 | The \verb|mode| string may also have a \verb|b| at the end, | 3834 | The \verb|mode| string may also have a \verb|b| at the end, |
@@ -3883,11 +3889,11 @@ it uses a default format that reads the entire next line | |||
3883 | 3889 | ||
3884 | The available formats are | 3890 | The available formats are |
3885 | \begin{description}\leftskip=20pt | 3891 | \begin{description}\leftskip=20pt |
3886 | \item[``*n''] reads a number; | 3892 | \item[\Q{*n}] reads a number; |
3887 | this is the only format that returns a number instead of a string. | 3893 | this is the only format that returns a number instead of a string. |
3888 | \item[``*a''] reads the whole file, starting at the current position. | 3894 | \item[\Q{*a}] reads the whole file, starting at the current position. |
3889 | On end of file, it returns the empty string. | 3895 | On end of file, it returns the empty string. |
3890 | \item[``*l''] reads the next line (skipping the end of line), | 3896 | \item[\Q{*l}] reads the next line (skipping the end of line), |
3891 | returning \nil{} on end of file. | 3897 | returning \nil{} on end of file. |
3892 | This is the default format. | 3898 | This is the default format. |
3893 | \item[\emph{number}] reads a string with up to that number of characters, | 3899 | \item[\emph{number}] reads a string with up to that number of characters, |
@@ -3904,9 +3910,9 @@ measured in bytes from the beginning of the file, | |||
3904 | to the position given by \verb|offset| plus a base | 3910 | to the position given by \verb|offset| plus a base |
3905 | specified by the string \verb|whence|, as follows: | 3911 | specified by the string \verb|whence|, as follows: |
3906 | \begin{description}\leftskip=20pt | 3912 | \begin{description}\leftskip=20pt |
3907 | \item[``set''] base is position 0 (beginning of the file); | 3913 | \item[\Q{set}] base is position 0 (beginning of the file); |
3908 | \item[``cur''] base is current position; | 3914 | \item[\Q{cur}] base is current position; |
3909 | \item[``end''] base is end of file; | 3915 | \item[\Q{end}] base is end of file; |
3910 | \end{description} | 3916 | \end{description} |
3911 | In case of success, function \verb|seek| returns the final file position, | 3917 | In case of success, function \verb|seek| returns the final file position, |
3912 | measured in bytes from the beginning of the file. | 3918 | measured in bytes from the beginning of the file. |
@@ -4029,7 +4035,7 @@ and may have fields \verb|hour|, \verb|min|, \verb|sec|, and \verb|isdst| | |||
4029 | 4035 | ||
4030 | The returned value is a number, whose meaning depends on your system. | 4036 | The returned value is a number, whose meaning depends on your system. |
4031 | In Posix, Windows, and some other systems, this number counts the number | 4037 | In Posix, Windows, and some other systems, this number counts the number |
4032 | of seconds since some given start time (the ``epoch''). | 4038 | of seconds since some given start time (the \Q{epoch}). |
4033 | In other systems, the meaning is not specified, | 4039 | In other systems, the meaning is not specified, |
4034 | and the number returned by \verb|time| can be used only as an argument to | 4040 | and the number returned by \verb|time| can be used only as an argument to |
4035 | \verb|date| and \verb|difftime|. | 4041 | \verb|date| and \verb|difftime|. |
@@ -4150,7 +4156,7 @@ the current hook function, the current hook mask, | |||
4150 | and the current hook count (as set by the \verb|debug.sethook| function). | 4156 | and the current hook count (as set by the \verb|debug.sethook| function). |
4151 | 4157 | ||
4152 | 4158 | ||
4153 | %------------------------------------------------------------------------------ | 4159 | \C{------------------------------------------------------------------------------} |
4154 | \section{\Index{Lua Stand-alone}} \label{lua-sa} | 4160 | \section{\Index{Lua Stand-alone}} \label{lua-sa} |
4155 | 4161 | ||
4156 | Although Lua has been designed as an extension language, | 4162 | Although Lua has been designed as an extension language, |
@@ -4169,7 +4175,7 @@ The options are: | |||
4169 | \begin{description}\leftskip=20pt | 4175 | \begin{description}\leftskip=20pt |
4170 | \item[\T{-} ] executes \verb|stdin| as a file; | 4176 | \item[\T{-} ] executes \verb|stdin| as a file; |
4171 | \item[\T{-e} \rm\emph{stat}] executes string \emph{stat}; | 4177 | \item[\T{-e} \rm\emph{stat}] executes string \emph{stat}; |
4172 | \item[\T{-l} \rm\emph{file}] ``requires'' \emph{file}; | 4178 | \item[\T{-l} \rm\emph{file}] \Q{requires} \emph{file}; |
4173 | \item[\T{-i}] enters interactive mode after running \emph{script}; | 4179 | \item[\T{-i}] enters interactive mode after running \emph{script}; |
4174 | \item[\T{-v}] prints version information; | 4180 | \item[\T{-v}] prints version information; |
4175 | \item[\T{--}] stop handling options. | 4181 | \item[\T{--}] stop handling options. |
@@ -4248,7 +4254,7 @@ then | |||
4248 | \end{verbatim} | 4254 | \end{verbatim} |
4249 | is a more portable solution.) | 4255 | is a more portable solution.) |
4250 | 4256 | ||
4251 | %------------------------------------------------------------------------------ | 4257 | \C{------------------------------------------------------------------------------} |
4252 | \section*{Acknowledgments} | 4258 | \section*{Acknowledgments} |
4253 | 4259 | ||
4254 | The Lua team is grateful to \tecgraf{} for its continued support to Lua. | 4260 | The Lua team is grateful to \tecgraf{} for its continued support to Lua. |
@@ -4368,7 +4374,9 @@ Userdata!! | |||
4368 | 4374 | ||
4369 | \end{itemize} | 4375 | \end{itemize} |
4370 | 4376 | ||
4371 | %{=============================================================== | 4377 | |
4378 | |||
4379 | \C{[===============================================================} | ||
4372 | \newpage | 4380 | \newpage |
4373 | \section*{The Complete Syntax of Lua} \label{BNF} | 4381 | \section*{The Complete Syntax of Lua} \label{BNF} |
4374 | \addcontentsline{toc}{section}{The Complete Syntax of Lua} | 4382 | \addcontentsline{toc}{section}{The Complete Syntax of Lua} |
@@ -4386,8 +4394,8 @@ enclosed in single quotes. | |||
4386 | \renewenvironment{Produc}{\vspace{0.8ex}\par\noindent\hspace{3ex}\it\begin{tabular}{rrl}}{\end{tabular}\vspace{0.8ex}\par\noindent} | 4394 | \renewenvironment{Produc}{\vspace{0.8ex}\par\noindent\hspace{3ex}\it\begin{tabular}{rrl}}{\end{tabular}\vspace{0.8ex}\par\noindent} |
4387 | 4395 | ||
4388 | \renewcommand{\OrNL}{\\ & \Or & } | 4396 | \renewcommand{\OrNL}{\\ & \Or & } |
4389 | %\newcommand{\Nter}[1]{{\rm{\tt#1}}} | 4397 | \C{\newcommand{\Nter}[1]{{\rm{\tt#1}}}} |
4390 | %\newcommand{\Nter}[1]{\ter{#1}} | 4398 | \C{\newcommand{\Nter}[1]{\ter{#1}}} |
4391 | 4399 | ||
4392 | \index{grammar} | 4400 | \index{grammar} |
4393 | 4401 | ||
@@ -4397,7 +4405,7 @@ enclosed in single quotes. | |||
4397 | 4405 | ||
4398 | \produc{block}{chunk} | 4406 | \produc{block}{chunk} |
4399 | 4407 | ||
4400 | \produc{stat}{% | 4408 | \produc{stat}{ |
4401 | varlist1 \ter{=} explist1 | 4409 | varlist1 \ter{=} explist1 |
4402 | \OrNL functioncall | 4410 | \OrNL functioncall |
4403 | \OrNL \rwd{do} block \rwd{end} | 4411 | \OrNL \rwd{do} block \rwd{end} |
@@ -4422,7 +4430,7 @@ enclosed in single quotes. | |||
4422 | 4430 | ||
4423 | \produc{varlist1}{var \rep{\ter{,} var}} | 4431 | \produc{varlist1}{var \rep{\ter{,} var}} |
4424 | 4432 | ||
4425 | \produc{var}{% | 4433 | \produc{var}{ |
4426 | \Nter{Name} | 4434 | \Nter{Name} |
4427 | \Or prefixexp \ter{[} exp \ter{]} | 4435 | \Or prefixexp \ter{[} exp \ter{]} |
4428 | \Or prefixexp \ter{.} \Nter{Name} | 4436 | \Or prefixexp \ter{.} \Nter{Name} |
@@ -4434,7 +4442,7 @@ enclosed in single quotes. | |||
4434 | 4442 | ||
4435 | \produc{explist1}{\rep{exp \ter{,}} exp} | 4443 | \produc{explist1}{\rep{exp \ter{,}} exp} |
4436 | 4444 | ||
4437 | \produc{exp}{% | 4445 | \produc{exp}{ |
4438 | \rwd{nil} | 4446 | \rwd{nil} |
4439 | \rwd{false} | 4447 | \rwd{false} |
4440 | \rwd{true} | 4448 | \rwd{true} |
@@ -4449,12 +4457,12 @@ enclosed in single quotes. | |||
4449 | 4457 | ||
4450 | \produc{prefixexp}{var \Or functioncall \Or \ter{(} exp \ter{)}} | 4458 | \produc{prefixexp}{var \Or functioncall \Or \ter{(} exp \ter{)}} |
4451 | 4459 | ||
4452 | \produc{functioncall}{% | 4460 | \produc{functioncall}{ |
4453 | prefixexp args | 4461 | prefixexp args |
4454 | \Or prefixexp \ter{:} \Nter{Name} args | 4462 | \Or prefixexp \ter{:} \Nter{Name} args |
4455 | } | 4463 | } |
4456 | 4464 | ||
4457 | \produc{args}{% | 4465 | \produc{args}{ |
4458 | \ter{(} \opt{explist1} \ter{)} | 4466 | \ter{(} \opt{explist1} \ter{)} |
4459 | \Or tableconstructor | 4467 | \Or tableconstructor |
4460 | \Or \Nter{Literal} | 4468 | \Or \Nter{Literal} |
@@ -4464,7 +4472,7 @@ enclosed in single quotes. | |||
4464 | 4472 | ||
4465 | \produc{funcbody}{\ter{(} \opt{parlist1} \ter{)} block \rwd{end}} | 4473 | \produc{funcbody}{\ter{(} \opt{parlist1} \ter{)} block \rwd{end}} |
4466 | 4474 | ||
4467 | \produc{parlist1}{% | 4475 | \produc{parlist1}{ |
4468 | \Nter{Name} \rep{\ter{,} \Nter{Name}} \opt{\ter{,} \ter{\ldots}} | 4476 | \Nter{Name} \rep{\ter{,} \Nter{Name}} \opt{\ter{,} \ter{\ldots}} |
4469 | \Or \ter{\ldots} | 4477 | \Or \ter{\ldots} |
4470 | } | 4478 | } |
@@ -4482,9 +4490,9 @@ enclosed in single quotes. | |||
4482 | 4490 | ||
4483 | \end{Produc} | 4491 | \end{Produc} |
4484 | 4492 | ||
4485 | %}=============================================================== | 4493 | \C{]===============================================================} |
4486 | 4494 | ||
4487 | % Index | 4495 | \C{ Index} |
4488 | 4496 | ||
4489 | \newpage | 4497 | \newpage |
4490 | \addcontentsline{toc}{section}{Index} | 4498 | \addcontentsline{toc}{section}{Index} |
@@ -4492,3 +4500,4 @@ enclosed in single quotes. | |||
4492 | 4500 | ||
4493 | \end{document} | 4501 | \end{document} |
4494 | %)]} | 4502 | %)]} |
4503 | |||