diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-02 14:09:48 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-02 14:09:48 -0300 |
commit | d56e3a64817fec16b8bcb779515d87ebaed1fcdf (patch) | |
tree | a199c93fdd1b01c27e81b32c99146a445c5e09e7 /manual.tex | |
parent | 7820a47184c0079677c5c430125f0541af05c8b6 (diff) | |
download | lua-d56e3a64817fec16b8bcb779515d87ebaed1fcdf.tar.gz lua-d56e3a64817fec16b8bcb779515d87ebaed1fcdf.tar.bz2 lua-d56e3a64817fec16b8bcb779515d87ebaed1fcdf.zip |
"locale" support + better uniformity in formating
Diffstat (limited to 'manual.tex')
-rw-r--r-- | manual.tex | 97 |
1 files changed, 55 insertions, 42 deletions
@@ -1,8 +1,7 @@ | |||
1 | % $Id: manual.tex,v 2.8 1997/06/27 22:38:49 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 2.9 1997/07/01 17:41:34 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}} | ||
6 | \newcommand{\See}[1]{Section~\ref{#1}} | 5 | \newcommand{\See}[1]{Section~\ref{#1}} |
7 | \newcommand{\see}[1]{(see \See{#1})} | 6 | \newcommand{\see}[1]{(see \See{#1})} |
8 | \newcommand{\M}[1]{\emph{#1}} | 7 | \newcommand{\M}[1]{\emph{#1}} |
@@ -39,7 +38,7 @@ Waldemar Celes | |||
39 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 38 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
40 | } | 39 | } |
41 | 40 | ||
42 | \date{\small \verb$Date: 1997/06/27 22:38:49 $} | 41 | \date{\small \verb$Date: 1997/07/01 17:41:34 $} |
43 | 42 | ||
44 | \maketitle | 43 | \maketitle |
45 | 44 | ||
@@ -167,14 +166,14 @@ Before the first assignment, the value of a global variable is \nil; | |||
167 | this default can be changed \see{tag-method}. | 166 | this default can be changed \see{tag-method}. |
168 | 167 | ||
169 | The unit of execution of Lua is called a \Def{chunk}. | 168 | The unit of execution of Lua is called a \Def{chunk}. |
170 | The syntax% | 169 | The syntax for chunks is: |
171 | \footnote{As usual, \rep{\emph{a}} means 0 or more \emph{a}'s, | ||
172 | \opt{\emph{a}} means an optional \emph{a} and \oneormore{\emph{a}} means | ||
173 | one or more \emph{a}'s.} | ||
174 | for chunks is: | ||
175 | \begin{Produc} | 170 | \begin{Produc} |
176 | \produc{chunk}{\rep{stat \Or function} \opt{ret}} | 171 | \produc{chunk}{\rep{stat \Or function} \opt{ret}} |
177 | \end{Produc}% | 172 | \end{Produc}% |
173 | (As usual, \rep{\emph{a}} means 0 or more \emph{a}'s, | ||
174 | \opt{\emph{a}} means an optional \emph{a} and \oneormore{\emph{a}} means | ||
175 | one or more \emph{a}'s.) | ||
176 | |||
178 | A chunk may contain statements and function definitions, | 177 | A chunk may contain statements and function definitions, |
179 | and may be in a file or in a string inside the host program. | 178 | and may be in a file or in a string inside the host program. |
180 | A chunk may optionally end with a \verb|return| statement \see{return}. | 179 | A chunk may optionally end with a \verb|return| statement \see{return}. |
@@ -182,10 +181,10 @@ When a chunk is executed, first all its functions and statements are compiled, | |||
182 | then the statements are executed in sequential order. | 181 | then the statements are executed in sequential order. |
183 | All modifications a chunk effects on the global environment persist | 182 | All modifications a chunk effects on the global environment persist |
184 | after its end. | 183 | after its end. |
185 | Those include modifications to global variables and definitions | 184 | Those include modifications to global variables |
186 | of new functions% | 185 | and definitions of new functions |
187 | \footnote{Actually, a function definition is an | 186 | (actually, a function definition is an |
188 | assignment to a global variable \see{TypesSec}.}. | 187 | assignment to a global variable \see{TypesSec}). |
189 | 188 | ||
190 | Chunks may be pre-compiled into binary form; | 189 | Chunks may be pre-compiled into binary form; |
191 | see program \IndexVerb{luac} for details. | 190 | see program \IndexVerb{luac} for details. |
@@ -207,7 +206,9 @@ There are six \Index{basic types} in Lua: \Def{nil}, \Def{number}, | |||
207 | \emph{Nil} is the type of the value \nil, | 206 | \emph{Nil} is the type of the value \nil, |
208 | whose main property is to be different from any other value. | 207 | whose main property is to be different from any other value. |
209 | \emph{Number} represents real (floating-point) numbers, | 208 | \emph{Number} represents real (floating-point) numbers, |
210 | while \emph{string} has the usual meaning. | 209 | while \emph{string} has the usual meaning; |
210 | notice that Lua is \Index{eight-bit clean}, | ||
211 | so strings can have ISO characters. | ||
211 | The function \verb|type| returns a string describing the type | 212 | The function \verb|type| returns a string describing the type |
212 | of a given value \see{pdf-type}. | 213 | of a given value \see{pdf-type}. |
213 | 214 | ||
@@ -275,9 +276,11 @@ This section describes the lexis, the syntax and the semantics of Lua. | |||
275 | 276 | ||
276 | \subsection{Lexical Conventions} \label{lexical} | 277 | \subsection{Lexical Conventions} \label{lexical} |
277 | 278 | ||
278 | Lua is a case-sensitive language. | ||
279 | \Index{Identifiers} can be any string of letters, digits, and underscores, | 279 | \Index{Identifiers} can be any string of letters, digits, and underscores, |
280 | not beginning with a digit. | 280 | not beginning with a digit. |
281 | The definition of letter depends on the current locale: | ||
282 | Any character considered alphabetic by the current locale | ||
283 | can be used in an identifier. | ||
281 | The following words are reserved, and cannot be used as identifiers: | 284 | The following words are reserved, and cannot be used as identifiers: |
282 | \index{reserved words} | 285 | \index{reserved words} |
283 | \begin{verbatim} | 286 | \begin{verbatim} |
@@ -286,6 +289,9 @@ The following words are reserved, and cannot be used as identifiers: | |||
286 | nil not or repeat | 289 | nil not or repeat |
287 | return then until while | 290 | return then until while |
288 | \end{verbatim} | 291 | \end{verbatim} |
292 | Lua is a case-sensitive language: | ||
293 | \T{and} is a reserved word, but \T{And} and \T{\'and} | ||
294 | (if the locale permits) are two other different identifiers. | ||
289 | 295 | ||
290 | The following strings denote other \Index{tokens}: | 296 | The following strings denote other \Index{tokens}: |
291 | \begin{verbatim} | 297 | \begin{verbatim} |
@@ -307,9 +313,9 @@ other quoted strings. | |||
307 | \Index{Comments} start anywhere outside a string with a | 313 | \Index{Comments} start anywhere outside a string with a |
308 | double hyphen (\verb|--|) and run until the end of the line. | 314 | double hyphen (\verb|--|) and run until the end of the line. |
309 | Moreover, | 315 | Moreover, |
310 | the first line of a chunk file is skipped if it starts with \verb|#|% | 316 | the first line of a chunk file is skipped if it starts with \verb|#|. |
311 | \footnote{This facility allows the use of Lua as a script interpreter | 317 | This facility allows the use of Lua as a script interpreter |
312 | in Unix systems \see{lua-sa}.}. | 318 | in Unix systems \see{lua-sa}. |
313 | 319 | ||
314 | \Index{Numerical constants} may be written with an optional decimal part, | 320 | \Index{Numerical constants} may be written with an optional decimal part, |
315 | and an optional decimal exponent. | 321 | and an optional decimal exponent. |
@@ -325,9 +331,9 @@ The \verb|$| can be followed by any of the following directives: | |||
325 | \begin{description} | 331 | \begin{description} |
326 | \item[\T{debug}] --- turn on some debugging facilities \see{pragma}. | 332 | \item[\T{debug}] --- turn on some debugging facilities \see{pragma}. |
327 | \item[\T{nodebug}] --- turn off some debugging facilities \see{pragma}. | 333 | \item[\T{nodebug}] --- turn off some debugging facilities \see{pragma}. |
328 | \item[{\tt if \M{cond}}] --- starts a conditional part. | 334 | \item[\T{if \M{cond}}] --- starts a conditional part. |
329 | If \M{cond} is false, then this part is skipped by the lexical analyzer. | 335 | If \M{cond} is false, then this part is skipped by the lexical analyzer. |
330 | \item[{\tt ifnot \M{cond}}] --- starts a conditional part. | 336 | \item[\T{ifnot \M{cond}}] --- starts a conditional part. |
331 | If \M{cond} is true, then this part is skipped by the lexical analyzer. | 337 | If \M{cond} is true, then this part is skipped by the lexical analyzer. |
332 | \item[\T{end}] --- ends a conditional part. | 338 | \item[\T{end}] --- ends a conditional part. |
333 | \item[\T{else}] --- starts an ``else'' conditional part, | 339 | \item[\T{else}] --- starts an ``else'' conditional part, |
@@ -439,9 +445,9 @@ an assignment \verb|x = val|, where \verb|x| is a global variable, | |||
439 | is equivalent to a call \verb|setglobal('x', val)|; | 445 | is equivalent to a call \verb|setglobal('x', val)|; |
440 | an assignment \verb|t[i] = val| is equivalent to | 446 | an assignment \verb|t[i] = val| is equivalent to |
441 | \verb|settable_event(t, i, val)|. | 447 | \verb|settable_event(t, i, val)|. |
442 | See \See{tag-method} for a description of these functions% | 448 | See \See{tag-method} for a description of these functions. |
443 | \footnote{Function \verb|setglobal| is pre-defined in Lua. | 449 | (Function \verb|setglobal| is pre-defined in Lua. |
444 | Function \T{settable\_event} is used only for explanatory purposes.}. | 450 | Function \T{settable\_event} is used only for explanatory purposes.) |
445 | 451 | ||
446 | The syntax \verb|var.NAME| is just syntactic sugar for | 452 | The syntax \verb|var.NAME| is just syntactic sugar for |
447 | \verb|var["NAME"]|: | 453 | \verb|var["NAME"]|: |
@@ -515,9 +521,9 @@ An access to a global variable \verb|x| is equivalent to a | |||
515 | call \verb|getglobal('x')|; | 521 | call \verb|getglobal('x')|; |
516 | an access to an indexed variable \verb|t[i]| is equivalent to | 522 | an access to an indexed variable \verb|t[i]| is equivalent to |
517 | a call \verb|gettable_event(t, i)|. | 523 | a call \verb|gettable_event(t, i)|. |
518 | See \See{tag-method} for a description of these functions% | 524 | See \See{tag-method} for a description of these functions. |
519 | \footnote{Function \verb|getglobal| is pre-defined in Lua. | 525 | (Function \verb|getglobal| is pre-defined in Lua. |
520 | Function \T{gettable\_event} is used only for explanatory purposes.}. | 526 | Function \T{gettable\_event} is used only for explanatory purposes.) |
521 | 527 | ||
522 | The non-terminal \M{exp1} is used to indicate that the values | 528 | The non-terminal \M{exp1} is used to indicate that the values |
523 | returned by an expression must be adjusted to one single value: | 529 | returned by an expression must be adjusted to one single value: |
@@ -563,9 +569,6 @@ If both arguments are numbers, then they are compared as such. | |||
563 | Otherwise, if both arguments are strings, | 569 | Otherwise, if both arguments are strings, |
564 | their values are compared using lexicographical order. | 570 | their values are compared using lexicographical order. |
565 | Otherwise, the ``order'' tag method is called \see{tag-method}. | 571 | Otherwise, the ``order'' tag method is called \see{tag-method}. |
566 | %Note that the conversion rules of Section~\ref{coercion} | ||
567 | %do apply to order operators. | ||
568 | %Thus, \verb|"2">"12"| evaluates to true. | ||
569 | 572 | ||
570 | \subsubsection{Logical Operators} | 573 | \subsubsection{Logical Operators} |
571 | Like control structures, all logical operators | 574 | Like control structures, all logical operators |
@@ -643,7 +646,7 @@ is essentially equivalent to: | |||
643 | The form \emph{ffieldlist1} initializes other fields in a table: | 646 | The form \emph{ffieldlist1} initializes other fields in a table: |
644 | \begin{Produc} | 647 | \begin{Produc} |
645 | \produc{ffieldlist1}{ffield \rep{\ter{,} ffield} \opt{\ter{,}}} | 648 | \produc{ffieldlist1}{ffield \rep{\ter{,} ffield} \opt{\ter{,}}} |
646 | \produc{ffield}{\ter{[} exp \ter{]} \ter {=} exp \Or name \ter{=} exp} | 649 | \produc{ffield}{\ter{[} exp \ter{]} \ter{=} exp \Or name \ter{=} exp} |
647 | \end{Produc}% | 650 | \end{Produc}% |
648 | For example: | 651 | For example: |
649 | \begin{verbatim} | 652 | \begin{verbatim} |
@@ -1322,7 +1325,7 @@ The use of explicit nested blocks is strongly encouraged. | |||
1322 | 1325 | ||
1323 | \subsection{Executing Lua Code} | 1326 | \subsection{Executing Lua Code} |
1324 | A host program can execute Lua chunks written in a file or in a string | 1327 | A host program can execute Lua chunks written in a file or in a string |
1325 | using the following functions:% | 1328 | using the following functions: |
1326 | \Deffunc{lua_dofile}\Deffunc{lua_dostring} | 1329 | \Deffunc{lua_dofile}\Deffunc{lua_dostring} |
1327 | \begin{verbatim} | 1330 | \begin{verbatim} |
1328 | int lua_dofile (char *filename); | 1331 | int lua_dofile (char *filename); |
@@ -1967,7 +1970,7 @@ The following combinations are allowed in describing a character class: | |||
1967 | \item[\T{\%U}] --- represents all non upper case letter characters. | 1970 | \item[\T{\%U}] --- represents all non upper case letter characters. |
1968 | \item[\T{\%w}] --- represents all alphanumeric characters. | 1971 | \item[\T{\%w}] --- represents all alphanumeric characters. |
1969 | \item[\T{\%W}] --- represents all non alphanumeric characters. | 1972 | \item[\T{\%W}] --- represents all non alphanumeric characters. |
1970 | \item[{\tt \%\M{x}}] (where \M{x} is any non alphanumeric character) --- | 1973 | \item[\T{\%\M{x}}] (where \M{x} is any non alphanumeric character) --- |
1971 | represents the character \M{x}. | 1974 | represents the character \M{x}. |
1972 | This is the standard way to escape the magic characters \verb|()%.[*-?|. | 1975 | This is the standard way to escape the magic characters \verb|()%.[*-?|. |
1973 | \item[\T{[char-set]}] --- | 1976 | \item[\T{[char-set]}] --- |
@@ -1976,17 +1979,21 @@ characters in char-set. | |||
1976 | To include a \verb|]| in char-set, it must be the first character. | 1979 | To include a \verb|]| in char-set, it must be the first character. |
1977 | A range of characters may be specified by | 1980 | A range of characters may be specified by |
1978 | separating the end characters of the range with a \verb|-|; | 1981 | separating the end characters of the range with a \verb|-|; |
1979 | e.g., \verb|A-Z| specifies the upper case characters. | 1982 | e.g., \verb|A-Z| specifies the English upper case characters. |
1980 | If \verb|-| appears as the first or last character of char-set, | 1983 | If \verb|-| appears as the first or last character of char-set, |
1981 | then it represents itself. | 1984 | then it represents itself. |
1982 | All classes \verb|%|\emph{x} described above can also be used as | 1985 | All classes \verb|%|\emph{x} described above can also be used as |
1983 | components in a char-set. | 1986 | components in a char-set. |
1984 | All other characters in char-set represent themselves. | 1987 | All other characters in char-set represent themselves. |
1985 | \item[{\tt [\^{ }char-set]}] --- | 1988 | \item[\T{[\^{ }char-set]}] --- |
1986 | represents the complement of char-set, | 1989 | represents the complement of char-set, |
1987 | where char-set is interpreted as above. | 1990 | where char-set is interpreted as above. |
1988 | \end{description} | 1991 | \end{description} |
1989 | 1992 | ||
1993 | The definitions of letter, space, etc depend on the current locale. | ||
1994 | In particular, the class \verb|[a-z]| may not be equivalent to \verb|%l|. | ||
1995 | The second form should be preferred for more portable programs. | ||
1996 | |||
1990 | \paragraph{Pattern Item:} | 1997 | \paragraph{Pattern Item:} |
1991 | a \Def{pattern item} may be: | 1998 | a \Def{pattern item} may be: |
1992 | \begin{itemize} | 1999 | \begin{itemize} |
@@ -2006,11 +2013,11 @@ these repetition items will always match the shortest possible sequence. | |||
2006 | a single character class followed by \verb|?|, | 2013 | a single character class followed by \verb|?|, |
2007 | which matches 0 or 1 occurrence of a character in the class; | 2014 | which matches 0 or 1 occurrence of a character in the class; |
2008 | \item | 2015 | \item |
2009 | {\tt \%\M{n}}, for \M{n} between 1 and 9; | 2016 | \T{\%\M{n}}, for \M{n} between 1 and 9; |
2010 | such item matches a sub-string equal to the n-th captured string | 2017 | such item matches a sub-string equal to the n-th captured string |
2011 | (see below); | 2018 | (see below); |
2012 | \item | 2019 | \item |
2013 | {\tt \%b\M{xy}}, where \M{x} and \M{y} are two distinct characters; | 2020 | \T{\%b\M{xy}}, where \M{x} and \M{y} are two distinct characters; |
2014 | such item matches strings that start with \M{x}, end with \M{y}, | 2021 | such item matches strings that start with \M{x}, end with \M{y}, |
2015 | and where the \M{x} and \M{y} are \emph{balanced}. | 2022 | and where the \M{x} and \M{y} are \emph{balanced}. |
2016 | That means that, if one reads the string from left to write, | 2023 | That means that, if one reads the string from left to write, |
@@ -2039,6 +2046,7 @@ stored as the first capture (and therefore has number 1); | |||
2039 | the character matching \verb|.| is captured with number 2, | 2046 | the character matching \verb|.| is captured with number 2, |
2040 | and the part matching \verb|%s*| has number 3. | 2047 | and the part matching \verb|%s*| has number 3. |
2041 | 2048 | ||
2049 | |||
2042 | \subsection{Mathematical Functions} \label{mathlib} | 2050 | \subsection{Mathematical Functions} \label{mathlib} |
2043 | 2051 | ||
2044 | This library is an interface to some functions of the standard C math library. | 2052 | This library is an interface to some functions of the standard C math library. |
@@ -2101,8 +2109,6 @@ When called with a file name, it opens the named file, | |||
2101 | sets its handle as the value of \verb|_INPUT|, | 2109 | sets its handle as the value of \verb|_INPUT|, |
2102 | and returns this value. | 2110 | and returns this value. |
2103 | It does not close the current input file. | 2111 | It does not close the current input file. |
2104 | %When called with a file handle returned by a previous call, | ||
2105 | %it simply assigns it to \verb|_INPUT|. | ||
2106 | When called without parameters, | 2112 | When called without parameters, |
2107 | it closes the \verb|_INPUT| file, | 2113 | it closes the \verb|_INPUT| file, |
2108 | and restores \verb|stdin| as the value of \verb|_INPUT|. | 2114 | and restores \verb|stdin| as the value of \verb|_INPUT|. |
@@ -2130,8 +2136,6 @@ and returns this value. | |||
2130 | It does not close the current output file. | 2136 | It does not close the current output file. |
2131 | Notice that, if the file already exists, | 2137 | Notice that, if the file already exists, |
2132 | then it will be \emph{completely erased} with this operation. | 2138 | then it will be \emph{completely erased} with this operation. |
2133 | %When called with a file handle returned by a previous call, | ||
2134 | %it restores the file as the current output. | ||
2135 | When called without parameters, | 2139 | When called without parameters, |
2136 | this function closes the \verb|_OUTPUT| file, | 2140 | this function closes the \verb|_OUTPUT| file, |
2137 | and restores \verb|stdout| as the value of \verb|_OUTPUT|. | 2141 | and restores \verb|stdout| as the value of \verb|_OUTPUT|. |
@@ -2203,15 +2207,13 @@ from the input if it belongs to the class; | |||
2203 | it never fails. | 2207 | it never fails. |
2204 | A character class followed by \verb|*| reads until a character that | 2208 | A character class followed by \verb|*| reads until a character that |
2205 | does not belong to the class, or end of file; | 2209 | does not belong to the class, or end of file; |
2206 | since it can match a sequence of zero characters, it never fails.% | 2210 | since it can match a sequence of zero characters, it never fails. |
2207 | \footnote{ | ||
2208 | Notice that the behavior of read patterns is different from | 2211 | Notice that the behavior of read patterns is different from |
2209 | the regular pattern matching behavior, | 2212 | the regular pattern matching behavior, |
2210 | where a \verb|*| expands to the maximum length \emph{such that} | 2213 | where a \verb|*| expands to the maximum length \emph{such that} |
2211 | the rest of the pattern does not fail. | 2214 | the rest of the pattern does not fail. |
2212 | With the read pattern behavior | 2215 | With the read pattern behavior |
2213 | there is no need for backtracking the reading. | 2216 | there is no need for backtracking the reading. |
2214 | } | ||
2215 | 2217 | ||
2216 | A pattern item may contain sub-patterns enclosed in curly brackets, | 2218 | A pattern item may contain sub-patterns enclosed in curly brackets, |
2217 | that describe \Def{skips}. | 2219 | that describe \Def{skips}. |
@@ -2270,6 +2272,17 @@ This function is equivalent to the C function \verb|system|. | |||
2270 | It passes \verb|command| to be executed by an operating system shell. | 2272 | It passes \verb|command| to be executed by an operating system shell. |
2271 | It returns an error code, which is system-dependent. | 2273 | It returns an error code, which is system-dependent. |
2272 | 2274 | ||
2275 | \subsubsection*{\ff \T{setlocale (locale [, category])}}\Deffunc{setlocale} | ||
2276 | |||
2277 | This function is an interface to the ANSI C function \verb|setlocale|. | ||
2278 | \verb|locale| is a string specifing a locale; | ||
2279 | \verb|category| is a number describing which category to change: | ||
2280 | 0 is \verb|LC_ALL|, 1 is \verb|LC_COLLATE|, 2 is \verb|LC_CTYPE|, | ||
2281 | 3 is \verb|LC_MONETARY|, 4 is \verb|LC_NUMERIC|, and 5 is \verb|LC_TIME|; | ||
2282 | the default category is \verb|LC_ALL|. | ||
2283 | The function returns the name of the new locale, | ||
2284 | or \nil\ if the request cannot be honored. | ||
2285 | |||
2273 | 2286 | ||
2274 | \section{The Debugger Interface} \label{debugI} | 2287 | \section{The Debugger Interface} \label{debugI} |
2275 | 2288 | ||