diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-19 15:49:40 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-19 15:49:40 -0300 |
commit | f84c2ebc4aba7e62618a8177296d95a83167ec06 (patch) | |
tree | 3fc89c20bfa245829b743386ae4097dbc0c423d6 | |
parent | c8897f2b082616bd5eb5328d3f260273adb53fbd (diff) | |
download | lua-f84c2ebc4aba7e62618a8177296d95a83167ec06.tar.gz lua-f84c2ebc4aba7e62618a8177296d95a83167ec06.tar.bz2 lua-f84c2ebc4aba7e62618a8177296d95a83167ec06.zip |
dostring has an optional error method argument;
counter for gsub only when there is a table (to keep full compatibility)
-rw-r--r-- | manual.tex | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -1,4 +1,4 @@ | |||
1 | % $Id: manual.tex,v 2.2 1997/06/18 21:11:53 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 2.3 1997/06/19 18:03:04 roberto Exp roberto $ |
2 | 2 | ||
3 | \documentstyle[fullpage,11pt,bnf]{article} | 3 | \documentstyle[fullpage,11pt,bnf]{article} |
4 | 4 | ||
@@ -38,7 +38,7 @@ Waldemar Celes | |||
38 | \tecgraf\ --- Computer Science Department --- PUC-Rio | 38 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
39 | } | 39 | } |
40 | 40 | ||
41 | \date{\small \verb$Date: 1997/06/18 21:11:53 $} | 41 | \date{\small \verb$Date: 1997/06/19 18:03:04 $} |
42 | 42 | ||
43 | \maketitle | 43 | \maketitle |
44 | 44 | ||
@@ -1624,12 +1624,15 @@ or a non \nil\ value if the chunk returns no values. | |||
1624 | It issues an error when called with a non string argument. | 1624 | It issues an error when called with a non string argument. |
1625 | \verb|dofile| is equivalent to the API function \verb|lua_dofile|. | 1625 | \verb|dofile| is equivalent to the API function \verb|lua_dofile|. |
1626 | 1626 | ||
1627 | \subsubsection*{\ff {\tt dostring (string)}}\Deffunc{dostring} | 1627 | \subsubsection*{\ff {\tt dostring (string [, errmethod])}}\Deffunc{dostring} |
1628 | This function executes a given string as a Lua chunk. | 1628 | This function executes a given string as a Lua chunk. |
1629 | If there is any error executing the string, it returns \nil. | 1629 | If there is any error executing the string, it returns \nil. |
1630 | Otherwise, it returns the values returned by the chunk, | 1630 | Otherwise, it returns the values returned by the chunk, |
1631 | or a non \nil\ value if the chunk returns no values. | 1631 | or a non \nil\ value if the chunk returns no values. |
1632 | \verb|dostring| is equivalent to the API function \verb|lua_dostring|. | 1632 | If provided, \verb|errmethod| is temporarily set as the error method, |
1633 | while \verb|string| runs. | ||
1634 | As a particular case, if \verb|errmethod| is \nil, | ||
1635 | no error messages will be issued during the execution of the string. | ||
1633 | 1636 | ||
1634 | \subsubsection*{\ff {\tt newtag ()}}\Deffunc{newtag}\label{pdf-newtag} | 1637 | \subsubsection*{\ff {\tt newtag ()}}\Deffunc{newtag}\label{pdf-newtag} |
1635 | Returns a new tag. | 1638 | Returns a new tag. |
@@ -1890,10 +1893,11 @@ stands for the value of the n-th captured substring. | |||
1890 | 1893 | ||
1891 | If \verb|repl| is a function, then this function is called every time a | 1894 | If \verb|repl| is a function, then this function is called every time a |
1892 | match occurs, with the following arguments: | 1895 | match occurs, with the following arguments: |
1893 | If \verb|table| is present, it is the first argument; | 1896 | If \verb|table| is present, the the first argument is this table |
1894 | then all captured substrings, in order (see below); | 1897 | and the second one is a match counter (1 for the first call). |
1895 | finally, the last argument is a match counter | 1898 | Independently of these two optional arguments, |
1896 | (1 for the first call). | 1899 | all captured substrings are passed as arguments, |
1900 | in order (see below); | ||
1897 | If the value returned by this function is a string, | 1901 | If the value returned by this function is a string, |
1898 | then it is used as the replacement string; | 1902 | then it is used as the replacement string; |
1899 | otherwise, the replacement string is the empty string. | 1903 | otherwise, the replacement string is the empty string. |
@@ -1914,17 +1918,17 @@ See some examples below: | |||
1914 | x = gsub("4+5 = $return 4+5$", "$(.-)%$", dostring) | 1918 | x = gsub("4+5 = $return 4+5$", "$(.-)%$", dostring) |
1915 | --> x="4+5 = 9" | 1919 | --> x="4+5 = 9" |
1916 | 1920 | ||
1921 | function f(t, i, v) return t[v] end | ||
1917 | t = {name="lua", version="3.0"} | 1922 | t = {name="lua", version="3.0"} |
1918 | x = gsub("$name - $version", "$(%w%w*)", rawgettable, t) | 1923 | x = gsub("$name - $version", "$(%w%w*)", f, t) |
1919 | --> x="lua - 3.0" | 1924 | --> x="lua - 3.0" |
1920 | 1925 | ||
1921 | t = {"apple", "orange", "lime"} | 1926 | t = {"apple", "orange", "lime"} |
1922 | x = gsub("x and x and x", "x", rawgettable, t) | 1927 | x = gsub("x and x and x", "x", rawgettable, t) |
1923 | --> x="apple and orange and lime" | 1928 | --> x="apple and orange and lime" |
1924 | 1929 | ||
1925 | function f(t,v,i) t[i]=v end | ||
1926 | t = {} | 1930 | t = {} |
1927 | gsub("first second word", "(%w%w*)", f, t) | 1931 | gsub("first second word", "(%w%w*)", rawsettable, t) |
1928 | --> t={"first", "second", "word"} | 1932 | --> t={"first", "second", "word"} |
1929 | \end{verbatim} | 1933 | \end{verbatim} |
1930 | 1934 | ||