anna's comments

This commit is contained in:
Roberto Ierusalimschy 1996-11-06 18:26:56 -02:00
parent 3e94febfc1
commit aa4d865077
1 changed files with 33 additions and 23 deletions

View File

@ -1,4 +1,4 @@
% $Id: manual.tex,v 1.20 1996/11/01 17:02:10 roberto Exp roberto $ % $Id: manual.tex,v 1.21 1996/11/01 18:02:53 roberto Exp roberto $
\documentstyle[fullpage,11pt,bnf]{article} \documentstyle[fullpage,11pt,bnf]{article}
@ -28,7 +28,6 @@ Roberto Ierusalimschy\quad
Luiz Henrique de Figueiredo\quad Luiz Henrique de Figueiredo\quad
Waldemar Celes Waldemar Celes
\vspace{1.0ex}\\ \vspace{1.0ex}\\
%\small \tecgraf \ --- PUC-Rio\\
\smallskip \smallskip
\small\tt lua@icad.puc-rio.br \small\tt lua@icad.puc-rio.br
\vspace{2.0ex}\\ \vspace{2.0ex}\\
@ -36,7 +35,7 @@ Waldemar Celes
\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio \tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio
} }
\date{\small \verb$Date: 1996/11/01 17:02:10 $} \date{\small \verb$Date: 1996/11/01 18:02:53 $}
\maketitle \maketitle
@ -969,6 +968,10 @@ A correct solution could be:
lua_pushobject(index); /* push index */ lua_pushobject(index); /* push index */
result = lua_getsubscript(); result = lua_getsubscript();
\end{verbatim} \end{verbatim}
The functions \verb|lua_getnumber|, \verb|lua_getstring|,
\verb|lua_getuserdata|, and \verb|lua_getcfunction|,
plus the family \verb|lua_is*|,
are safe to be called without modifying the stack.
\subsection{Calling Lua Functions} \subsection{Calling Lua Functions}
Functions defined in Lua by a chunk executed with Functions defined in Lua by a chunk executed with
@ -1309,8 +1312,9 @@ The only differences are that the options/modifiers
and \verb'h' are not supported, and \verb'h' are not supported,
and there is an extra option, \verb'q'. and there is an extra option, \verb'q'.
This option formats a string in a form suitable to be safely read This option formats a string in a form suitable to be safely read
back by the Lua interpreter. back by the Lua interpreter;
The string is written between double quotes, that is,
the string is written between double quotes,
and all double quotes, returns and backslashes in the string and all double quotes, returns and backslashes in the string
are correctly escaped when written. are correctly escaped when written.
For instance, the call For instance, the call
@ -1328,18 +1332,19 @@ The options \verb'c', \verb'd', \verb'E', \verb'e', \verb'f',
expect a number as argument, expect a number as argument,
whereas \verb'q' and \verb's' expect a string. whereas \verb'q' and \verb's' expect a string.
\subsubsection*{\ff{\tt gsub (s, from, to [, n])}}\Deffunc{gsub} \subsubsection*{\ff{\tt gsub (s, pat, repl [, n])}}\Deffunc{gsub}
Returns a copy of \verb-s-, Returns a copy of \verb-s-,
where all ocurrences of the pattern \verb-from- have been where all ocurrences of the pattern \verb-pat- have been
replaced by a replacement string specified by \verb-to-. replaced by a replacement string specified by \verb-repl-.
This function also returns, as a second value, This function also returns, as a second value,
the total number of substitutions made. the total number of substitutions made.
If \verb-to- is a string, its value is used for replacement. If \verb-repl- is a string, its value is used for replacement.
Any sequence in \verb-to- of the form \verb-%n- with \verb-n- between 1 and 9 Any sequence in \verb-repl- of the form \verb-%n-
with \verb-n- between 1 and 9
stands for the value of the n-th captured substring. stands for the value of the n-th captured substring.
If \verb-to- is a function, this function is called every time a If \verb-repl- is a function, this function is called every time a
match occurs, with all captured substrings as parameters. match occurs, with all captured substrings as parameters.
If the value returned by this function is a string, If the value returned by this function is a string,
it is used as the replacement string; it is used as the replacement string;
@ -1348,7 +1353,7 @@ otherwise, the replacement string is the empty string.
An optional parameter \verb-n- limits An optional parameter \verb-n- limits
the maximum number of substitutions to occur. the maximum number of substitutions to occur.
For instance, when \verb-n- is 1 only the first ocurrence of For instance, when \verb-n- is 1 only the first ocurrence of
\verb-from- is replaced. \verb-pat- is replaced.
As an example, in the following expression each ocurrence of the form As an example, in the following expression each ocurrence of the form
\verb-$name$- calls the function \verb|getenv|, \verb-$name$- calls the function \verb|getenv|,
@ -1357,7 +1362,7 @@ passing \verb|name| as argument
The value returned by \verb|getenv| will replace the pattern. The value returned by \verb|getenv| will replace the pattern.
Therefore, the whole expression: Therefore, the whole expression:
\begin{verbatim} \begin{verbatim}
gsub('home = $HOME$, user = $USER$', "$(%w%w*)$", getenv) gsub("home = $HOME$, user = $USER$", "$(%w%w*)$", getenv)
\end{verbatim} \end{verbatim}
may return the string: may return the string:
\begin{verbatim} \begin{verbatim}
@ -1366,7 +1371,8 @@ home = /home/roberto, user = roberto
\subsubsection*{Patterns} \label{pm} \subsubsection*{Patterns} \label{pm}
A \Def{character class} is used to represent a set of characters. \paragraph{Character Class:}
a \Def{character class} is used to represent a set of characters.
The following combinations are allowed in describing a character class: The following combinations are allowed in describing a character class:
\begin{description} \begin{description}
\item[{\em x}] (where {\em x} is any character not in the list \verb'()%.[*?') \item[{\em x}] (where {\em x} is any character not in the list \verb'()%.[*?')
@ -1403,7 +1409,8 @@ represents the complement of char-set,
where char-set is interpreted as above. where char-set is interpreted as above.
\end{description} \end{description}
A \Def{pattern item} may be a single character class, \paragraph{Pattern Item:}
a \Def{pattern item} may be a single character class,
or a character class followed by \verb'*' or by \verb'?'. or a character class followed by \verb'*' or by \verb'?'.
A single character class matches any single character in the class. A single character class matches any single character in the class.
A character class followed by \verb'*' matches 0 or more repetitions A character class followed by \verb'*' matches 0 or more repetitions
@ -1411,10 +1418,11 @@ of characters in the class.
A character class followed by \verb'?' matches 0 or one ocurrence A character class followed by \verb'?' matches 0 or one ocurrence
of a character in the class. of a character in the class.
A pattern item may also has the form \verb'%n', A pattern item may also has the form \verb'%n',
for \verb-n- between 1 and 9. for \verb-n- between 1 and 9;
Such item matches a sub-string equal to the n-th captured string. such item matches a sub-string equal to the n-th captured string.
A \Def{pattern} is a sequence of pattern items. \paragraph{Pattern:}
a \Def{pattern} is a sequence of pattern items.
Any repetition item (\verb'*') inside a pattern will always Any repetition item (\verb'*') inside a pattern will always
match the longest possible sequence. match the longest possible sequence.
A \verb'^' at the beginning of a pattern anchors the match at the A \verb'^' at the beginning of a pattern anchors the match at the
@ -1426,7 +1434,7 @@ A pattern may contain sub-patterns enclosed in parentheses,
that describe \Def{captures}. that describe \Def{captures}.
When a match succeeds, the sub-strings of the subject string When a match succeeds, the sub-strings of the subject string
that match captures are {\em captured} for future use. that match captures are {\em captured} for future use.
Captures are numbered according to their left delimiter. Captures are numbered according to their left parentheses.
\subsection{Mathematical Functions} \label{mathlib} \subsection{Mathematical Functions} \label{mathlib}
@ -1526,6 +1534,8 @@ this function does not erase any previous content of the file.
If this function fails, it returns \nil, If this function fails, it returns \nil,
plus a string describing the error. plus a string describing the error.
Notice that function \verb|writeto| is available to close a file.
\subsubsection*{\ff{\tt remove (filename)}}\Deffunc{remove} \subsubsection*{\ff{\tt remove (filename)}}\Deffunc{remove}
This function deletes the file with the given name. This function deletes the file with the given name.
@ -1550,8 +1560,8 @@ according to a read pattern, that specifies how much to read;
characters are read from the current input file until characters are read from the current input file until
the read pattern fails or ends. the read pattern fails or ends.
The function \verb|read| returns a string with the characters read, The function \verb|read| returns a string with the characters read,
or \nil\ if the result string would be empty {\em and\/} or \nil\ if the read pattern fails {\em and\/}
the read pattern fails. the result string would be empty.
When called without parameters, When called without parameters,
it uses a default pattern that reads the next line it uses a default pattern that reads the next line
(see below). (see below).
@ -1566,10 +1576,10 @@ from the input if it belongs to the class;
it never fails. it never fails.
A character class followed by \verb'*' reads until a character that A character class followed by \verb'*' reads until a character that
does not belong to the class, or end of file; does not belong to the class, or end of file;
it never fails.% since it can match a sequence of zero characteres, it never fails.%
\footnote{ \footnote{
Notice that this behaviour is different from regular pattern matching, Notice that this behaviour is different from regular pattern matching,
where a \verb'*' expands to the maximum length {\em such that} where a \verb'*' expands to the maximum length {\em such that\/}
the rest of the pattern does not fail.} the rest of the pattern does not fail.}
A pattern item may contain sub-patterns enclosed in curly brackets, A pattern item may contain sub-patterns enclosed in curly brackets,