diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-11-06 18:26:56 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-11-06 18:26:56 -0200 |
commit | aa4d86507707361e93aee6a0b52f268ee0ade236 (patch) | |
tree | 7d84ecdd5d65bfa95f8c929099741221581b699c | |
parent | 3e94febfc10ae07adb4de0556de4d4c5d7f22d27 (diff) | |
download | lua-aa4d86507707361e93aee6a0b52f268ee0ade236.tar.gz lua-aa4d86507707361e93aee6a0b52f268ee0ade236.tar.bz2 lua-aa4d86507707361e93aee6a0b52f268ee0ade236.zip |
anna's comments
-rw-r--r-- | manual.tex | 56 |
1 files changed, 33 insertions, 23 deletions
@@ -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 | |||
28 | Luiz Henrique de Figueiredo\quad | 28 | Luiz Henrique de Figueiredo\quad |
29 | Waldemar Celes | 29 | Waldemar 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} |
971 | The functions \verb|lua_getnumber|, \verb|lua_getstring|, | ||
972 | \verb|lua_getuserdata|, and \verb|lua_getcfunction|, | ||
973 | plus the family \verb|lua_is*|, | ||
974 | are safe to be called without modifying the stack. | ||
972 | 975 | ||
973 | \subsection{Calling Lua Functions} | 976 | \subsection{Calling Lua Functions} |
974 | Functions defined in Lua by a chunk executed with | 977 | Functions defined in Lua by a chunk executed with |
@@ -1309,8 +1312,9 @@ The only differences are that the options/modifiers | |||
1309 | and \verb'h' are not supported, | 1312 | and \verb'h' are not supported, |
1310 | and there is an extra option, \verb'q'. | 1313 | and there is an extra option, \verb'q'. |
1311 | This option formats a string in a form suitable to be safely read | 1314 | This option formats a string in a form suitable to be safely read |
1312 | back by the Lua interpreter. | 1315 | back by the Lua interpreter; |
1313 | The string is written between double quotes, | 1316 | that is, |
1317 | the string is written between double quotes, | ||
1314 | and all double quotes, returns and backslashes in the string | 1318 | and all double quotes, returns and backslashes in the string |
1315 | are correctly escaped when written. | 1319 | are correctly escaped when written. |
1316 | For instance, the call | 1320 | For instance, the call |
@@ -1328,18 +1332,19 @@ The options \verb'c', \verb'd', \verb'E', \verb'e', \verb'f', | |||
1328 | expect a number as argument, | 1332 | expect a number as argument, |
1329 | whereas \verb'q' and \verb's' expect a string. | 1333 | whereas \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} |
1332 | Returns a copy of \verb-s-, | 1336 | Returns a copy of \verb-s-, |
1333 | where all ocurrences of the pattern \verb-from- have been | 1337 | where all ocurrences of the pattern \verb-pat- have been |
1334 | replaced by a replacement string specified by \verb-to-. | 1338 | replaced by a replacement string specified by \verb-repl-. |
1335 | This function also returns, as a second value, | 1339 | This function also returns, as a second value, |
1336 | the total number of substitutions made. | 1340 | the total number of substitutions made. |
1337 | 1341 | ||
1338 | If \verb-to- is a string, its value is used for replacement. | 1342 | If \verb-repl- is a string, its value is used for replacement. |
1339 | Any sequence in \verb-to- of the form \verb-%n- with \verb-n- between 1 and 9 | 1343 | Any sequence in \verb-repl- of the form \verb-%n- |
1344 | with \verb-n- between 1 and 9 | ||
1340 | stands for the value of the n-th captured substring. | 1345 | stands for the value of the n-th captured substring. |
1341 | 1346 | ||
1342 | If \verb-to- is a function, this function is called every time a | 1347 | If \verb-repl- is a function, this function is called every time a |
1343 | match occurs, with all captured substrings as parameters. | 1348 | match occurs, with all captured substrings as parameters. |
1344 | If the value returned by this function is a string, | 1349 | If the value returned by this function is a string, |
1345 | it is used as the replacement string; | 1350 | it is used as the replacement string; |
@@ -1348,7 +1353,7 @@ otherwise, the replacement string is the empty string. | |||
1348 | An optional parameter \verb-n- limits | 1353 | An optional parameter \verb-n- limits |
1349 | the maximum number of substitutions to occur. | 1354 | the maximum number of substitutions to occur. |
1350 | For instance, when \verb-n- is 1 only the first ocurrence of | 1355 | For instance, when \verb-n- is 1 only the first ocurrence of |
1351 | \verb-from- is replaced. | 1356 | \verb-pat- is replaced. |
1352 | 1357 | ||
1353 | As an example, in the following expression each ocurrence of the form | 1358 | As 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 | |||
1357 | The value returned by \verb|getenv| will replace the pattern. | 1362 | The value returned by \verb|getenv| will replace the pattern. |
1358 | Therefore, the whole expression: | 1363 | Therefore, 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} |
1362 | may return the string: | 1367 | may 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 | ||
1369 | A \Def{character class} is used to represent a set of characters. | 1374 | \paragraph{Character Class:} |
1375 | a \Def{character class} is used to represent a set of characters. | ||
1370 | The following combinations are allowed in describing a character class: | 1376 | The 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, | |||
1403 | where char-set is interpreted as above. | 1409 | where char-set is interpreted as above. |
1404 | \end{description} | 1410 | \end{description} |
1405 | 1411 | ||
1406 | A \Def{pattern item} may be a single character class, | 1412 | \paragraph{Pattern Item:} |
1413 | a \Def{pattern item} may be a single character class, | ||
1407 | or a character class followed by \verb'*' or by \verb'?'. | 1414 | or a character class followed by \verb'*' or by \verb'?'. |
1408 | A single character class matches any single character in the class. | 1415 | A single character class matches any single character in the class. |
1409 | A character class followed by \verb'*' matches 0 or more repetitions | 1416 | A character class followed by \verb'*' matches 0 or more repetitions |
@@ -1411,10 +1418,11 @@ of characters in the class. | |||
1411 | A character class followed by \verb'?' matches 0 or one ocurrence | 1418 | A character class followed by \verb'?' matches 0 or one ocurrence |
1412 | of a character in the class. | 1419 | of a character in the class. |
1413 | A pattern item may also has the form \verb'%n', | 1420 | A pattern item may also has the form \verb'%n', |
1414 | for \verb-n- between 1 and 9. | 1421 | for \verb-n- between 1 and 9; |
1415 | Such item matches a sub-string equal to the n-th captured string. | 1422 | such item matches a sub-string equal to the n-th captured string. |
1416 | 1423 | ||
1417 | A \Def{pattern} is a sequence of pattern items. | 1424 | \paragraph{Pattern:} |
1425 | a \Def{pattern} is a sequence of pattern items. | ||
1418 | Any repetition item (\verb'*') inside a pattern will always | 1426 | Any repetition item (\verb'*') inside a pattern will always |
1419 | match the longest possible sequence. | 1427 | match the longest possible sequence. |
1420 | A \verb'^' at the beginning of a pattern anchors the match at the | 1428 | 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, | |||
1426 | that describe \Def{captures}. | 1434 | that describe \Def{captures}. |
1427 | When a match succeeds, the sub-strings of the subject string | 1435 | When a match succeeds, the sub-strings of the subject string |
1428 | that match captures are {\em captured} for future use. | 1436 | that match captures are {\em captured} for future use. |
1429 | Captures are numbered according to their left delimiter. | 1437 | Captures 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. | |||
1526 | If this function fails, it returns \nil, | 1534 | If this function fails, it returns \nil, |
1527 | plus a string describing the error. | 1535 | plus a string describing the error. |
1528 | 1536 | ||
1537 | Notice 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 | ||
1531 | This function deletes the file with the given name. | 1541 | This function deletes the file with the given name. |
@@ -1550,8 +1560,8 @@ according to a read pattern, that specifies how much to read; | |||
1550 | characters are read from the current input file until | 1560 | characters are read from the current input file until |
1551 | the read pattern fails or ends. | 1561 | the read pattern fails or ends. |
1552 | The function \verb|read| returns a string with the characters read, | 1562 | The function \verb|read| returns a string with the characters read, |
1553 | or \nil\ if the result string would be empty {\em and\/} | 1563 | or \nil\ if the read pattern fails {\em and\/} |
1554 | the read pattern fails. | 1564 | the result string would be empty. |
1555 | When called without parameters, | 1565 | When called without parameters, |
1556 | it uses a default pattern that reads the next line | 1566 | it 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; | |||
1566 | it never fails. | 1576 | it never fails. |
1567 | A character class followed by \verb'*' reads until a character that | 1577 | A character class followed by \verb'*' reads until a character that |
1568 | does not belong to the class, or end of file; | 1578 | does not belong to the class, or end of file; |
1569 | it never fails.% | 1579 | since it can match a sequence of zero characteres, it never fails.% |
1570 | \footnote{ | 1580 | \footnote{ |
1571 | Notice that this behaviour is different from regular pattern matching, | 1581 | Notice that this behaviour is different from regular pattern matching, |
1572 | where a \verb'*' expands to the maximum length {\em such that} | 1582 | where a \verb'*' expands to the maximum length {\em such that\/} |
1573 | the rest of the pattern does not fail.} | 1583 | the rest of the pattern does not fail.} |
1574 | 1584 | ||
1575 | A pattern item may contain sub-patterns enclosed in curly brackets, | 1585 | A pattern item may contain sub-patterns enclosed in curly brackets, |