dostring has an optional error method argument;

counter for gsub only when there is a table (to keep full compatibility)
This commit is contained in:
Roberto Ierusalimschy 1997-06-19 15:49:40 -03:00
parent c8897f2b08
commit f84c2ebc4a
1 changed files with 15 additions and 11 deletions

View File

@ -1,4 +1,4 @@
% $Id: manual.tex,v 2.2 1997/06/18 21:11:53 roberto Exp roberto $ % $Id: manual.tex,v 2.3 1997/06/19 18:03:04 roberto Exp roberto $
\documentstyle[fullpage,11pt,bnf]{article} \documentstyle[fullpage,11pt,bnf]{article}
@ -38,7 +38,7 @@ Waldemar Celes
\tecgraf\ --- Computer Science Department --- PUC-Rio \tecgraf\ --- Computer Science Department --- PUC-Rio
} }
\date{\small \verb$Date: 1997/06/18 21:11:53 $} \date{\small \verb$Date: 1997/06/19 18:03:04 $}
\maketitle \maketitle
@ -1624,12 +1624,15 @@ or a non \nil\ value if the chunk returns no values.
It issues an error when called with a non string argument. It issues an error when called with a non string argument.
\verb|dofile| is equivalent to the API function \verb|lua_dofile|. \verb|dofile| is equivalent to the API function \verb|lua_dofile|.
\subsubsection*{\ff {\tt dostring (string)}}\Deffunc{dostring} \subsubsection*{\ff {\tt dostring (string [, errmethod])}}\Deffunc{dostring}
This function executes a given string as a Lua chunk. This function executes a given string as a Lua chunk.
If there is any error executing the string, it returns \nil. If there is any error executing the string, it returns \nil.
Otherwise, it returns the values returned by the chunk, Otherwise, it returns the values returned by the chunk,
or a non \nil\ value if the chunk returns no values. or a non \nil\ value if the chunk returns no values.
\verb|dostring| is equivalent to the API function \verb|lua_dostring|. If provided, \verb|errmethod| is temporarily set as the error method,
while \verb|string| runs.
As a particular case, if \verb|errmethod| is \nil,
no error messages will be issued during the execution of the string.
\subsubsection*{\ff {\tt newtag ()}}\Deffunc{newtag}\label{pdf-newtag} \subsubsection*{\ff {\tt newtag ()}}\Deffunc{newtag}\label{pdf-newtag}
Returns a new tag. Returns a new tag.
@ -1890,10 +1893,11 @@ stands for the value of the n-th captured substring.
If \verb|repl| is a function, then this function is called every time a If \verb|repl| is a function, then this function is called every time a
match occurs, with the following arguments: match occurs, with the following arguments:
If \verb|table| is present, it is the first argument; If \verb|table| is present, the the first argument is this table
then all captured substrings, in order (see below); and the second one is a match counter (1 for the first call).
finally, the last argument is a match counter Independently of these two optional arguments,
(1 for the first call). all captured substrings are passed as arguments,
in order (see below);
If the value returned by this function is a string, If the value returned by this function is a string,
then it is used as the replacement string; then it is used as the replacement string;
otherwise, the replacement string is the empty string. otherwise, the replacement string is the empty string.
@ -1914,17 +1918,17 @@ See some examples below:
x = gsub("4+5 = $return 4+5$", "$(.-)%$", dostring) x = gsub("4+5 = $return 4+5$", "$(.-)%$", dostring)
--> x="4+5 = 9" --> x="4+5 = 9"
function f(t, i, v) return t[v] end
t = {name="lua", version="3.0"} t = {name="lua", version="3.0"}
x = gsub("$name - $version", "$(%w%w*)", rawgettable, t) x = gsub("$name - $version", "$(%w%w*)", f, t)
--> x="lua - 3.0" --> x="lua - 3.0"
t = {"apple", "orange", "lime"} t = {"apple", "orange", "lime"}
x = gsub("x and x and x", "x", rawgettable, t) x = gsub("x and x and x", "x", rawgettable, t)
--> x="apple and orange and lime" --> x="apple and orange and lime"
function f(t,v,i) t[i]=v end
t = {} t = {}
gsub("first second word", "(%w%w*)", f, t) gsub("first second word", "(%w%w*)", rawsettable, t)
--> t={"first", "second", "word"} --> t={"first", "second", "word"}
\end{verbatim} \end{verbatim}