aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-11-06 18:26:56 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-11-06 18:26:56 -0200
commitaa4d86507707361e93aee6a0b52f268ee0ade236 (patch)
tree7d84ecdd5d65bfa95f8c929099741221581b699c
parent3e94febfc10ae07adb4de0556de4d4c5d7f22d27 (diff)
downloadlua-aa4d86507707361e93aee6a0b52f268ee0ade236.tar.gz
lua-aa4d86507707361e93aee6a0b52f268ee0ade236.tar.bz2
lua-aa4d86507707361e93aee6a0b52f268ee0ade236.zip
anna's comments
-rw-r--r--manual.tex56
1 files changed, 33 insertions, 23 deletions
diff --git a/manual.tex b/manual.tex
index f068b714..71564f6d 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.20 1996/11/01 17:02:10 roberto Exp roberto $ 1% $Id: manual.tex,v 1.21 1996/11/01 18:02:53 roberto Exp roberto $
2 2
3\documentstyle[fullpage,11pt,bnf]{article} 3\documentstyle[fullpage,11pt,bnf]{article}
4 4
@@ -28,7 +28,6 @@ Roberto Ierusalimschy\quad
28Luiz Henrique de Figueiredo\quad 28Luiz Henrique de Figueiredo\quad
29Waldemar Celes 29Waldemar Celes
30\vspace{1.0ex}\\ 30\vspace{1.0ex}\\
31%\small \tecgraf \ --- PUC-Rio\\
32\smallskip 31\smallskip
33\small\tt lua@icad.puc-rio.br 32\small\tt lua@icad.puc-rio.br
34\vspace{2.0ex}\\ 33\vspace{2.0ex}\\
@@ -36,7 +35,7 @@ Waldemar Celes
36\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio 35\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio
37} 36}
38 37
39\date{\small \verb$Date: 1996/11/01 17:02:10 $} 38\date{\small \verb$Date: 1996/11/01 18:02:53 $}
40 39
41\maketitle 40\maketitle
42 41
@@ -969,6 +968,10 @@ A correct solution could be:
969 lua_pushobject(index); /* push index */ 968 lua_pushobject(index); /* push index */
970 result = lua_getsubscript(); 969 result = lua_getsubscript();
971\end{verbatim} 970\end{verbatim}
971The functions \verb|lua_getnumber|, \verb|lua_getstring|,
972 \verb|lua_getuserdata|, and \verb|lua_getcfunction|,
973plus the family \verb|lua_is*|,
974are safe to be called without modifying the stack.
972 975
973\subsection{Calling Lua Functions} 976\subsection{Calling Lua Functions}
974Functions defined in Lua by a chunk executed with 977Functions defined in Lua by a chunk executed with
@@ -1309,8 +1312,9 @@ The only differences are that the options/modifiers
1309and \verb'h' are not supported, 1312and \verb'h' are not supported,
1310and there is an extra option, \verb'q'. 1313and there is an extra option, \verb'q'.
1311This option formats a string in a form suitable to be safely read 1314This option formats a string in a form suitable to be safely read
1312back by the Lua interpreter. 1315back by the Lua interpreter;
1313The string is written between double quotes, 1316that is,
1317the string is written between double quotes,
1314and all double quotes, returns and backslashes in the string 1318and all double quotes, returns and backslashes in the string
1315are correctly escaped when written. 1319are correctly escaped when written.
1316For instance, the call 1320For instance, the call
@@ -1328,18 +1332,19 @@ The options \verb'c', \verb'd', \verb'E', \verb'e', \verb'f',
1328expect a number as argument, 1332expect a number as argument,
1329whereas \verb'q' and \verb's' expect a string. 1333whereas \verb'q' and \verb's' expect a string.
1330 1334
1331\subsubsection*{\ff{\tt gsub (s, from, to [, n])}}\Deffunc{gsub} 1335\subsubsection*{\ff{\tt gsub (s, pat, repl [, n])}}\Deffunc{gsub}
1332Returns a copy of \verb-s-, 1336Returns a copy of \verb-s-,
1333where all ocurrences of the pattern \verb-from- have been 1337where all ocurrences of the pattern \verb-pat- have been
1334replaced by a replacement string specified by \verb-to-. 1338replaced by a replacement string specified by \verb-repl-.
1335This function also returns, as a second value, 1339This function also returns, as a second value,
1336the total number of substitutions made. 1340the total number of substitutions made.
1337 1341
1338If \verb-to- is a string, its value is used for replacement. 1342If \verb-repl- is a string, its value is used for replacement.
1339Any sequence in \verb-to- of the form \verb-%n- with \verb-n- between 1 and 9 1343Any sequence in \verb-repl- of the form \verb-%n-
1344with \verb-n- between 1 and 9
1340stands for the value of the n-th captured substring. 1345stands for the value of the n-th captured substring.
1341 1346
1342If \verb-to- is a function, this function is called every time a 1347If \verb-repl- is a function, this function is called every time a
1343match occurs, with all captured substrings as parameters. 1348match occurs, with all captured substrings as parameters.
1344If the value returned by this function is a string, 1349If the value returned by this function is a string,
1345it is used as the replacement string; 1350it is used as the replacement string;
@@ -1348,7 +1353,7 @@ otherwise, the replacement string is the empty string.
1348An optional parameter \verb-n- limits 1353An optional parameter \verb-n- limits
1349the maximum number of substitutions to occur. 1354the maximum number of substitutions to occur.
1350For instance, when \verb-n- is 1 only the first ocurrence of 1355For instance, when \verb-n- is 1 only the first ocurrence of
1351\verb-from- is replaced. 1356\verb-pat- is replaced.
1352 1357
1353As an example, in the following expression each ocurrence of the form 1358As an example, in the following expression each ocurrence of the form
1354\verb-$name$- calls the function \verb|getenv|, 1359\verb-$name$- calls the function \verb|getenv|,
@@ -1357,7 +1362,7 @@ passing \verb|name| as argument
1357The value returned by \verb|getenv| will replace the pattern. 1362The value returned by \verb|getenv| will replace the pattern.
1358Therefore, the whole expression: 1363Therefore, the whole expression:
1359\begin{verbatim} 1364\begin{verbatim}
1360 gsub('home = $HOME$, user = $USER$', "$(%w%w*)$", getenv) 1365 gsub("home = $HOME$, user = $USER$", "$(%w%w*)$", getenv)
1361\end{verbatim} 1366\end{verbatim}
1362may return the string: 1367may return the string:
1363\begin{verbatim} 1368\begin{verbatim}
@@ -1366,7 +1371,8 @@ home = /home/roberto, user = roberto
1366 1371
1367\subsubsection*{Patterns} \label{pm} 1372\subsubsection*{Patterns} \label{pm}
1368 1373
1369A \Def{character class} is used to represent a set of characters. 1374\paragraph{Character Class:}
1375a \Def{character class} is used to represent a set of characters.
1370The following combinations are allowed in describing a character class: 1376The following combinations are allowed in describing a character class:
1371\begin{description} 1377\begin{description}
1372\item[{\em x}] (where {\em x} is any character not in the list \verb'()%.[*?') 1378\item[{\em x}] (where {\em x} is any character not in the list \verb'()%.[*?')
@@ -1403,7 +1409,8 @@ represents the complement of char-set,
1403where char-set is interpreted as above. 1409where char-set is interpreted as above.
1404\end{description} 1410\end{description}
1405 1411
1406A \Def{pattern item} may be a single character class, 1412\paragraph{Pattern Item:}
1413a \Def{pattern item} may be a single character class,
1407or a character class followed by \verb'*' or by \verb'?'. 1414or a character class followed by \verb'*' or by \verb'?'.
1408A single character class matches any single character in the class. 1415A single character class matches any single character in the class.
1409A character class followed by \verb'*' matches 0 or more repetitions 1416A character class followed by \verb'*' matches 0 or more repetitions
@@ -1411,10 +1418,11 @@ of characters in the class.
1411A character class followed by \verb'?' matches 0 or one ocurrence 1418A character class followed by \verb'?' matches 0 or one ocurrence
1412of a character in the class. 1419of a character in the class.
1413A pattern item may also has the form \verb'%n', 1420A pattern item may also has the form \verb'%n',
1414for \verb-n- between 1 and 9. 1421for \verb-n- between 1 and 9;
1415Such item matches a sub-string equal to the n-th captured string. 1422such item matches a sub-string equal to the n-th captured string.
1416 1423
1417A \Def{pattern} is a sequence of pattern items. 1424\paragraph{Pattern:}
1425a \Def{pattern} is a sequence of pattern items.
1418Any repetition item (\verb'*') inside a pattern will always 1426Any repetition item (\verb'*') inside a pattern will always
1419match the longest possible sequence. 1427match the longest possible sequence.
1420A \verb'^' at the beginning of a pattern anchors the match at the 1428A \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,
1426that describe \Def{captures}. 1434that describe \Def{captures}.
1427When a match succeeds, the sub-strings of the subject string 1435When a match succeeds, the sub-strings of the subject string
1428that match captures are {\em captured} for future use. 1436that match captures are {\em captured} for future use.
1429Captures are numbered according to their left delimiter. 1437Captures are numbered according to their left parentheses.
1430 1438
1431\subsection{Mathematical Functions} \label{mathlib} 1439\subsection{Mathematical Functions} \label{mathlib}
1432 1440
@@ -1526,6 +1534,8 @@ this function does not erase any previous content of the file.
1526If this function fails, it returns \nil, 1534If this function fails, it returns \nil,
1527plus a string describing the error. 1535plus a string describing the error.
1528 1536
1537Notice that function \verb|writeto| is available to close a file.
1538
1529\subsubsection*{\ff{\tt remove (filename)}}\Deffunc{remove} 1539\subsubsection*{\ff{\tt remove (filename)}}\Deffunc{remove}
1530 1540
1531This function deletes the file with the given name. 1541This function deletes the file with the given name.
@@ -1550,8 +1560,8 @@ according to a read pattern, that specifies how much to read;
1550characters are read from the current input file until 1560characters are read from the current input file until
1551the read pattern fails or ends. 1561the read pattern fails or ends.
1552The function \verb|read| returns a string with the characters read, 1562The function \verb|read| returns a string with the characters read,
1553or \nil\ if the result string would be empty {\em and\/} 1563or \nil\ if the read pattern fails {\em and\/}
1554the read pattern fails. 1564the result string would be empty.
1555When called without parameters, 1565When called without parameters,
1556it uses a default pattern that reads the next line 1566it uses a default pattern that reads the next line
1557(see below). 1567(see below).
@@ -1566,10 +1576,10 @@ from the input if it belongs to the class;
1566it never fails. 1576it never fails.
1567A character class followed by \verb'*' reads until a character that 1577A character class followed by \verb'*' reads until a character that
1568does not belong to the class, or end of file; 1578does not belong to the class, or end of file;
1569it never fails.% 1579since it can match a sequence of zero characteres, it never fails.%
1570\footnote{ 1580\footnote{
1571Notice that this behaviour is different from regular pattern matching, 1581Notice that this behaviour is different from regular pattern matching,
1572where a \verb'*' expands to the maximum length {\em such that} 1582where a \verb'*' expands to the maximum length {\em such that\/}
1573the rest of the pattern does not fail.} 1583the rest of the pattern does not fail.}
1574 1584
1575A pattern item may contain sub-patterns enclosed in curly brackets, 1585A pattern item may contain sub-patterns enclosed in curly brackets,