summaryrefslogtreecommitdiff
path: root/manual.tex
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-02 14:09:48 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-02 14:09:48 -0300
commitd56e3a64817fec16b8bcb779515d87ebaed1fcdf (patch)
treea199c93fdd1b01c27e81b32c99146a445c5e09e7 /manual.tex
parent7820a47184c0079677c5c430125f0541af05c8b6 (diff)
downloadlua-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.tex97
1 files changed, 55 insertions, 42 deletions
diff --git a/manual.tex b/manual.tex
index 6573c472..37b51ba0 100644
--- a/manual.tex
+++ b/manual.tex
@@ -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;
167this default can be changed \see{tag-method}. 166this default can be changed \see{tag-method}.
168 167
169The unit of execution of Lua is called a \Def{chunk}. 168The unit of execution of Lua is called a \Def{chunk}.
170The syntax% 169The 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
173one or more \emph{a}'s.}
174for 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
175one or more \emph{a}'s.)
176
178A chunk may contain statements and function definitions, 177A chunk may contain statements and function definitions,
179and may be in a file or in a string inside the host program. 178and may be in a file or in a string inside the host program.
180A chunk may optionally end with a \verb|return| statement \see{return}. 179A 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,
182then the statements are executed in sequential order. 181then the statements are executed in sequential order.
183All modifications a chunk effects on the global environment persist 182All modifications a chunk effects on the global environment persist
184after its end. 183after its end.
185Those include modifications to global variables and definitions 184Those include modifications to global variables
186of new functions% 185and definitions of new functions
187\footnote{Actually, a function definition is an 186(actually, a function definition is an
188assignment to a global variable \see{TypesSec}.}. 187assignment to a global variable \see{TypesSec}).
189 188
190Chunks may be pre-compiled into binary form; 189Chunks may be pre-compiled into binary form;
191see program \IndexVerb{luac} for details. 190see 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,
208whose main property is to be different from any other value. 207whose 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,
210while \emph{string} has the usual meaning. 209while \emph{string} has the usual meaning;
210notice that Lua is \Index{eight-bit clean},
211so strings can have ISO characters.
211The function \verb|type| returns a string describing the type 212The function \verb|type| returns a string describing the type
212of a given value \see{pdf-type}. 213of 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
278Lua 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,
280not beginning with a digit. 280not beginning with a digit.
281The definition of letter depends on the current locale:
282Any character considered alphabetic by the current locale
283can be used in an identifier.
281The following words are reserved, and cannot be used as identifiers: 284The 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}
292Lua 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
290The following strings denote other \Index{tokens}: 296The 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
308double hyphen (\verb|--|) and run until the end of the line. 314double hyphen (\verb|--|) and run until the end of the line.
309Moreover, 315Moreover,
310the first line of a chunk file is skipped if it starts with \verb|#|% 316the 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 317This facility allows the use of Lua as a script interpreter
312in Unix systems \see{lua-sa}.}. 318in 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,
315and an optional decimal exponent. 321and 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.
329If \M{cond} is false, then this part is skipped by the lexical analyzer. 335If \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.
331If \M{cond} is true, then this part is skipped by the lexical analyzer. 337If \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,
439is equivalent to a call \verb|setglobal('x', val)|; 445is equivalent to a call \verb|setglobal('x', val)|;
440an assignment \verb|t[i] = val| is equivalent to 446an assignment \verb|t[i] = val| is equivalent to
441\verb|settable_event(t, i, val)|. 447\verb|settable_event(t, i, val)|.
442See \See{tag-method} for a description of these functions% 448See \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.
444Function \T{settable\_event} is used only for explanatory purposes.}. 450Function \T{settable\_event} is used only for explanatory purposes.)
445 451
446The syntax \verb|var.NAME| is just syntactic sugar for 452The 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
515call \verb|getglobal('x')|; 521call \verb|getglobal('x')|;
516an access to an indexed variable \verb|t[i]| is equivalent to 522an access to an indexed variable \verb|t[i]| is equivalent to
517a call \verb|gettable_event(t, i)|. 523a call \verb|gettable_event(t, i)|.
518See \See{tag-method} for a description of these functions% 524See \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.
520Function \T{gettable\_event} is used only for explanatory purposes.}. 526Function \T{gettable\_event} is used only for explanatory purposes.)
521 527
522The non-terminal \M{exp1} is used to indicate that the values 528The non-terminal \M{exp1} is used to indicate that the values
523returned by an expression must be adjusted to one single value: 529returned 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.
563Otherwise, if both arguments are strings, 569Otherwise, if both arguments are strings,
564their values are compared using lexicographical order. 570their values are compared using lexicographical order.
565Otherwise, the ``order'' tag method is called \see{tag-method}. 571Otherwise, 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}
571Like control structures, all logical operators 574Like control structures, all logical operators
@@ -643,7 +646,7 @@ is essentially equivalent to:
643The form \emph{ffieldlist1} initializes other fields in a table: 646The 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}%
648For example: 651For 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}
1324A host program can execute Lua chunks written in a file or in a string 1327A host program can execute Lua chunks written in a file or in a string
1325using the following functions:% 1328using the following functions:
1326\Deffunc{lua_dofile}\Deffunc{lua_dostring} 1329\Deffunc{lua_dofile}\Deffunc{lua_dostring}
1327\begin{verbatim} 1330\begin{verbatim}
1328int lua_dofile (char *filename); 1331int 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) ---
1971represents the character \M{x}. 1974represents the character \M{x}.
1972This is the standard way to escape the magic characters \verb|()%.[*-?|. 1975This 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.
1976To include a \verb|]| in char-set, it must be the first character. 1979To include a \verb|]| in char-set, it must be the first character.
1977A range of characters may be specified by 1980A range of characters may be specified by
1978separating the end characters of the range with a \verb|-|; 1981separating the end characters of the range with a \verb|-|;
1979e.g., \verb|A-Z| specifies the upper case characters. 1982e.g., \verb|A-Z| specifies the English upper case characters.
1980If \verb|-| appears as the first or last character of char-set, 1983If \verb|-| appears as the first or last character of char-set,
1981then it represents itself. 1984then it represents itself.
1982All classes \verb|%|\emph{x} described above can also be used as 1985All classes \verb|%|\emph{x} described above can also be used as
1983components in a char-set. 1986components in a char-set.
1984All other characters in char-set represent themselves. 1987All other characters in char-set represent themselves.
1985\item[{\tt [\^{ }char-set]}] --- 1988\item[\T{[\^{ }char-set]}] ---
1986represents the complement of char-set, 1989represents the complement of char-set,
1987where char-set is interpreted as above. 1990where char-set is interpreted as above.
1988\end{description} 1991\end{description}
1989 1992
1993The definitions of letter, space, etc depend on the current locale.
1994In particular, the class \verb|[a-z]| may not be equivalent to \verb|%l|.
1995The second form should be preferred for more portable programs.
1996
1990\paragraph{Pattern Item:} 1997\paragraph{Pattern Item:}
1991a \Def{pattern item} may be: 1998a \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.
2006a single character class followed by \verb|?|, 2013a single character class followed by \verb|?|,
2007which matches 0 or 1 occurrence of a character in the class; 2014which 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;
2010such item matches a sub-string equal to the n-th captured string 2017such 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;
2014such item matches strings that start with \M{x}, end with \M{y}, 2021such item matches strings that start with \M{x}, end with \M{y},
2015and where the \M{x} and \M{y} are \emph{balanced}. 2022and where the \M{x} and \M{y} are \emph{balanced}.
2016That means that, if one reads the string from left to write, 2023That 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);
2039the character matching \verb|.| is captured with number 2, 2046the character matching \verb|.| is captured with number 2,
2040and the part matching \verb|%s*| has number 3. 2047and 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
2044This library is an interface to some functions of the standard C math library. 2052This 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,
2101sets its handle as the value of \verb|_INPUT|, 2109sets its handle as the value of \verb|_INPUT|,
2102and returns this value. 2110and returns this value.
2103It does not close the current input file. 2111It 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|.
2106When called without parameters, 2112When called without parameters,
2107it closes the \verb|_INPUT| file, 2113it closes the \verb|_INPUT| file,
2108and restores \verb|stdin| as the value of \verb|_INPUT|. 2114and restores \verb|stdin| as the value of \verb|_INPUT|.
@@ -2130,8 +2136,6 @@ and returns this value.
2130It does not close the current output file. 2136It does not close the current output file.
2131Notice that, if the file already exists, 2137Notice that, if the file already exists,
2132then it will be \emph{completely erased} with this operation. 2138then 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.
2135When called without parameters, 2139When called without parameters,
2136this function closes the \verb|_OUTPUT| file, 2140this function closes the \verb|_OUTPUT| file,
2137and restores \verb|stdout| as the value of \verb|_OUTPUT|. 2141and restores \verb|stdout| as the value of \verb|_OUTPUT|.
@@ -2203,15 +2207,13 @@ from the input if it belongs to the class;
2203it never fails. 2207it never fails.
2204A character class followed by \verb|*| reads until a character that 2208A character class followed by \verb|*| reads until a character that
2205does not belong to the class, or end of file; 2209does not belong to the class, or end of file;
2206since it can match a sequence of zero characters, it never fails.% 2210since it can match a sequence of zero characters, it never fails.
2207\footnote{
2208Notice that the behavior of read patterns is different from 2211Notice that the behavior of read patterns is different from
2209the regular pattern matching behavior, 2212the regular pattern matching behavior,
2210where a \verb|*| expands to the maximum length \emph{such that} 2213where a \verb|*| expands to the maximum length \emph{such that}
2211the rest of the pattern does not fail. 2214the rest of the pattern does not fail.
2212With the read pattern behavior 2215With the read pattern behavior
2213there is no need for backtracking the reading. 2216there is no need for backtracking the reading.
2214}
2215 2217
2216A pattern item may contain sub-patterns enclosed in curly brackets, 2218A pattern item may contain sub-patterns enclosed in curly brackets,
2217that describe \Def{skips}. 2219that describe \Def{skips}.
@@ -2270,6 +2272,17 @@ This function is equivalent to the C function \verb|system|.
2270It passes \verb|command| to be executed by an operating system shell. 2272It passes \verb|command| to be executed by an operating system shell.
2271It returns an error code, which is system-dependent. 2273It returns an error code, which is system-dependent.
2272 2274
2275\subsubsection*{\ff \T{setlocale (locale [, category])}}\Deffunc{setlocale}
2276
2277This 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:
22800 is \verb|LC_ALL|, 1 is \verb|LC_COLLATE|, 2 is \verb|LC_CTYPE|,
22813 is \verb|LC_MONETARY|, 4 is \verb|LC_NUMERIC|, and 5 is \verb|LC_TIME|;
2282the default category is \verb|LC_ALL|.
2283The function returns the name of the new locale,
2284or \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