aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-11-01 15:02:10 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-11-01 15:02:10 -0200
commit2f44cc9f4d62cbdc6e752d5328408fc5123bedcc (patch)
tree13ad26e096a874166522f1b5bc257298c39288b4
parentd106f3f43c147b872df7b3304b2e42e92bc1b7bf (diff)
downloadlua-2f44cc9f4d62cbdc6e752d5328408fc5123bedcc.tar.gz
lua-2f44cc9f4d62cbdc6e752d5328408fc5123bedcc.tar.bz2
lua-2f44cc9f4d62cbdc6e752d5328408fc5123bedcc.zip
new pattern matching facilities; new version of i/o lib;
other small corrections.
-rw-r--r--manual.tex552
1 files changed, 363 insertions, 189 deletions
diff --git a/manual.tex b/manual.tex
index b69805ae..aa42c255 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.18 1996/06/18 20:08:40 roberto Exp roberto $ 1% $Id: manual.tex,v 1.19 1996/08/28 20:46:26 roberto Exp roberto $
2 2
3\documentstyle[fullpage,11pt,bnf]{article} 3\documentstyle[fullpage,11pt,bnf]{article}
4 4
@@ -13,7 +13,9 @@
13\newcommand{\Def}[1]{{\em #1}\index{#1}} 13\newcommand{\Def}[1]{{\em #1}\index{#1}}
14\newcommand{\Deffunc}[1]{\index{#1}} 14\newcommand{\Deffunc}[1]{\index{#1}}
15 15
16\newcommand{\Version}{2.4} 16\newcommand{\ff}{$\bullet$\ }
17
18\newcommand{\Version}{2.5 (beta)}
17 19
18\makeindex 20\makeindex
19 21
@@ -24,7 +26,7 @@
24\author{% 26\author{%
25Roberto Ierusalimschy\quad 27Roberto Ierusalimschy\quad
26Luiz Henrique de Figueiredo\quad 28Luiz Henrique de Figueiredo\quad
27Waldemar Celes Filho 29Waldemar Celes
28\vspace{1.0ex}\\ 30\vspace{1.0ex}\\
29%\small \tecgraf \ --- PUC-Rio\\ 31%\small \tecgraf \ --- PUC-Rio\\
30\smallskip 32\smallskip
@@ -34,7 +36,7 @@ Waldemar Celes Filho
34\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio 36\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio
35} 37}
36 38
37\date{\small \verb$Date: 1996/06/18 20:08:40 $} 39\date{\small \verb$Date: 1996/08/28 20:46:26 $}
38 40
39\maketitle 41\maketitle
40 42
@@ -72,11 +74,8 @@ general procedural programming features with data description
72facilities. 74facilities.
73It is intended to be used as a configuration language for any 75It is intended to be used as a configuration language for any
74program that needs one. 76program that needs one.
75%Its main extensions are related to object-oriented facilities,
76%and fallbacks,
77%but it has some other minor contributions.
78Lua has been designed and implemented by 77Lua has been designed and implemented by
79W.~Celes~F., L.~H.~de Figueiredo and R.~Ierusalimschy. 78W.~Celes, L.~H.~de Figueiredo and R.~Ierusalimschy.
80 79
81Lua is implemented as a library, written in C. 80Lua is implemented as a library, written in C.
82Being an extension language, Lua has no notion of a ``main'' program: 81Being an extension language, Lua has no notion of a ``main'' program:
@@ -123,10 +122,11 @@ The syntax%
123one or more {\em a\/}'s.} 122one or more {\em a\/}'s.}
124for chunks is: 123for chunks is:
125\begin{Produc} 124\begin{Produc}
126\produc{chunk}{\rep{statement \Or function}} 125\produc{chunk}{\rep{statement \Or function} \opt{ret}}
127\end{Produc}% 126\end{Produc}%
128A chunk may contain statements and function definitions, 127A chunk may contain statements and function definitions,
129and may be in a file or in a string inside the host program. 128and may be in a file or in a string inside the host program.
129A chunk may optionally ends with a return statement (\see{return}).
130When a chunk is executed, first all its functions and statements are compiled, 130When a chunk is executed, first all its functions and statements are compiled,
131then the statements are executed in sequential order. 131then the statements are executed in sequential order.
132All modifications a chunk effects on the global environment persist 132All modifications a chunk effects on the global environment persist
@@ -231,6 +231,10 @@ and do not interpret escape sequences.
231 231
232\Index{Comments} start anywhere outside a string with a 232\Index{Comments} start anywhere outside a string with a
233double hyphen (\verb'--') and run until the end of the line. 233double hyphen (\verb'--') and run until the end of the line.
234Moreover, if the first line of a chunk file starts with \verb'#',
235this line is skiped%
236\footnote{This facility allows the use of Lua as a script interpreter
237in Unix systems.}.
234 238
235\Index{Numerical constants} may be written with an optional decimal part, 239\Index{Numerical constants} may be written with an optional decimal part,
236and an optional decimal exponent. 240and an optional decimal exponent.
@@ -281,7 +285,7 @@ and local variable declarations (Section~\ref{localvar}).
281A \Index{block} is a list of statements, which is executed sequentially. 285A \Index{block} is a list of statements, which is executed sequentially.
282Any statement can be optionally followed by a semicolon: 286Any statement can be optionally followed by a semicolon:
283\begin{Produc} 287\begin{Produc}
284\produc{block}{\rep{stat sc} \opt{ret sc}} 288\produc{block}{\rep{stat sc} \opt{ret}}
285\produc{sc}{\opt{\ter{;}}} 289\produc{sc}{\opt{\ter{;}}}
286\end{Produc}% 290\end{Produc}%
287For syntactic reasons, a \IndexVerb{return} statement can only be written 291For syntactic reasons, a \IndexVerb{return} statement can only be written
@@ -344,11 +348,12 @@ All values different from \nil\ are considered true;
344\produc{elseif}{\rwd{elseif} exp1 \rwd{then} block} 348\produc{elseif}{\rwd{elseif} exp1 \rwd{then} block}
345\end{Produc} 349\end{Produc}
346 350
347A {\tt return} is used to return values from a function. \label{return} 351A {\tt return} is used to return values from a function or a chunk.
348Because a function may return more than one value, 352\label{return}
353Because they may return more than one value,
349the syntax for a \Index{return statement} is: 354the syntax for a \Index{return statement} is:
350\begin{Produc} 355\begin{Produc}
351\produc{ret}{\rwd{return} explist} 356\produc{ret}{\rwd{return} explist \opt{sc}}
352\end{Produc} 357\end{Produc}
353 358
354\subsubsection{Function Calls as Statements} \label{funcstat} 359\subsubsection{Function Calls as Statements} \label{funcstat}
@@ -434,7 +439,12 @@ The \Index{logical operators} are:
434\begin{verbatim} 439\begin{verbatim}
435 and or not 440 and or not
436\end{verbatim} 441\end{verbatim}
437The operators \verb'and' and \verb'or' use \Index{short-cut evaluation}, 442The operator \verb'and' returns \nil\ if its first argument is \nil;
443otherwise it returns its second argument.
444The operator \verb'or' returns its first argument
445if it is different from \nil;
446otherwise it returns its second argument.
447Both \verb'and' and \verb'or' use \Index{short-cut evaluation},
438that is, 448that is,
439the second operand is evaluated only if necessary. 449the second operand is evaluated only if necessary.
440 450
@@ -485,7 +495,7 @@ For example:
485\begin{verbatim} 495\begin{verbatim}
486 a = {"v1", "v2", 34} 496 a = {"v1", "v2", 34}
487\end{verbatim} 497\end{verbatim}
488is equivalent to: 498is roughly equivalent to:
489\begin{verbatim} 499\begin{verbatim}
490 temp = {} 500 temp = {}
491 temp[1] = "v1" 501 temp[1] = "v1"
@@ -503,11 +513,11 @@ For example:
503\begin{verbatim} 513\begin{verbatim}
504 a = {x = 1, y = 3} 514 a = {x = 1, y = 3}
505\end{verbatim} 515\end{verbatim}
506is equivalent to: 516is roughly equivalent to:
507\begin{verbatim} 517\begin{verbatim}
508 temp = {} 518 temp = {}
509 temp.x = 1 519 temp.x = 1 -- or temp["x"] = 1
510 temp.y = 3 520 temp.y = 3 -- or temp["y"] = 3
511 a = temp 521 a = temp
512\end{verbatim} 522\end{verbatim}
513 523
@@ -518,7 +528,7 @@ A \Index{function call} has the following syntax:
518\produc{functioncall}{var realParams} 528\produc{functioncall}{var realParams}
519\end{Produc}% 529\end{Produc}%
520Here, \verb'var' can be any variable (global, local, indexed, etc). 530Here, \verb'var' can be any variable (global, local, indexed, etc).
521If its type is {\em function\/} or {\em CFunction\/}, 531If its value has type {\em function\/} or {\em CFunction\/},
522then this function is called. 532then this function is called.
523Otherwise, the ``function'' fallback is called, 533Otherwise, the ``function'' fallback is called,
524having as first parameter the value of \verb'var', 534having as first parameter the value of \verb'var',
@@ -630,7 +640,7 @@ and one of the following strings describing the offended operator:
630 add sub mul div pow unm 640 add sub mul div pow unm
631\end{verbatim} 641\end{verbatim}
632Its return value is the final result of the arithmetic operation. 642Its return value is the final result of the arithmetic operation.
633The default function issues an error. 643The default handler issues an error.
634\item[``order'':]\index{order fallback} 644\item[``order'':]\index{order fallback}
635called when an order comparison is applied to non numerical or 645called when an order comparison is applied to non numerical or
636non string operands. 646non string operands.
@@ -641,40 +651,40 @@ one of the following strings describing the offended operator:
641 lt gt le ge 651 lt gt le ge
642\end{verbatim} 652\end{verbatim}
643Its return value is the final result of the comparison operation. 653Its return value is the final result of the comparison operation.
644The default function issues an error. 654The default handler issues an error.
645\item[``concat'':]\index{concatenation fallback} 655\item[``concat'':]\index{concatenation fallback}
646called when a concatenation is applied to non string operands. 656called when a concatenation is applied to non string operands.
647It receives the two operands as arguments. 657It receives the two operands as arguments.
648Its return value is the final result of the concatenation operation. 658Its return value is the final result of the concatenation operation.
649The default function issues an error. 659The default handler issues an error.
650\item[``index'':]\index{index fallback} 660\item[``index'':]\index{index fallback}
651called when Lua tries to retrieve the value of an index 661called when Lua tries to retrieve the value of an index
652not present in a table. 662not present in a table.
653It receives as arguments the table and the index. 663It receives as arguments the table and the index.
654Its return value is the final result of the indexing operation. 664Its return value is the final result of the indexing operation.
655The default function returns nil. 665The default handler returns nil.
656\item[``getglobal'':]\index{index getglobal} 666\item[``getglobal'':]\index{index getglobal}
657called when Lua tries to retrieve the value of a global variable 667called when Lua tries to retrieve the value of a global variable
658which has a nil value (or which has not been initialized). 668which has a nil value (or which has not been initialized).
659It receives as argument the name of the variable. 669It receives as argument the name of the variable.
660Its return value is the final result of the expression. 670Its return value is the final result of the expression.
661The default function returns nil. 671The default handler returns nil.
662\item[``gettable'':]\index{gettable fallback} 672\item[``gettable'':]\index{gettable fallback}
663called when Lua tries to index a non table value. 673called when Lua tries to index a non table value.
664It receives as arguments the non table value and the index. 674It receives as arguments the non table value and the index.
665Its return value is the final result of the indexing operation. 675Its return value is the final result of the indexing operation.
666The default function issues an error. 676The default handler issues an error.
667\item[``settable'':]\index{settable fallback} 677\item[``settable'':]\index{settable fallback}
668called when Lua tries to assign indexed a non table value. 678called when Lua tries to assign indexed a non table value.
669It receives as arguments the non table value, 679It receives as arguments the non table value,
670the index, and the assigned value. 680the index, and the assigned value.
671The default function issues an error. 681The default handler issues an error.
672\item[``function'':]\index{function falback} 682\item[``function'':]\index{function falback}
673called when Lua tries to call a non function value. 683called when Lua tries to call a non function value.
674It receives as arguments the non function value and the 684It receives as arguments the non function value and the
675arguments given in the original call. 685arguments given in the original call.
676Its return values are the final results of the call operation. 686Its return values are the final results of the call operation.
677The default function issues an error. 687The default handler issues an error.
678\item[``gc'':] 688\item[``gc'':]
679called during garbage collection. 689called during garbage collection.
680It receives as argument the table being collected. 690It receives as argument the table being collected.
@@ -683,17 +693,17 @@ Because this function operates during garbage collection,
683it must be used with great care, 693it must be used with great care,
684and programmers should avoid the creation of new objects 694and programmers should avoid the creation of new objects
685(tables or strings) in this function. 695(tables or strings) in this function.
686The default function does nothing. 696The default handler does nothing.
687\item[``error'':]\index{error fallback} 697\item[``error'':]\index{error fallback}
688called when an error occurs. 698called when an error occurs.
689It receives as argument a string describing the error. 699It receives as argument a string describing the error.
690The default function prints the message on the standard error output. 700The default handler prints the message on the standard error output.
691\end{description} 701\end{description}
692 702
693The function \IndexVerb{setfallback} is used to change a fallback function. 703The function \IndexVerb{setfallback} is used to change a fallback handler.
694Its first argument is the name of a fallback condition, 704Its first argument is the name of a fallback condition,
695and the second argument is the new function to be called. 705and the second argument is the new function to be called.
696It returns the old function for the given fallback. 706It returns the old handler function for the given fallback.
697 707
698Section \ref{exfallback} shows an example of the use of fallbacks. 708Section \ref{exfallback} shows an example of the use of fallbacks.
699 709
@@ -706,7 +716,7 @@ Whenever an error occurs during Lua compilation or execution,
706an ``error'' fallback function is called, 716an ``error'' fallback function is called,
707and then the corresponding function from the library 717and then the corresponding function from the library
708(\verb'lua_dofile', \verb'lua_dostring', 718(\verb'lua_dofile', \verb'lua_dostring',
709\verb'lua_call', and \verb'lua_callfunction') 719\verb'lua_call', or \verb'lua_callfunction')
710is terminated returning an error condition. 720is terminated returning an error condition.
711 721
712The only argument to the ``error'' fallback function is a string 722The only argument to the ``error'' fallback function is a string
@@ -722,10 +732,10 @@ This pragma must be written in a line by itself.
722When an error occurs in a program compiled with this option, 732When an error occurs in a program compiled with this option,
723the error routine is able to print also the lines where the calls 733the error routine is able to print also the lines where the calls
724(and the error) were made. 734(and the error) were made.
725If needed, it is possible to change the ``error'' fallback routine 735If needed, it is possible to change the ``error'' fallback handler
726(\see{fallback}). 736(\see{fallback}).
727 737
728Lua code can generate an error by calling the built-in 738Lua code can explicitly generate an error by calling the built-in
729function \verb'error' (\see{pdf-error}). 739function \verb'error' (\see{pdf-error}).
730 740
731 741
@@ -917,16 +927,6 @@ As in Lua, if the first object is not a table,
917or the index is not present in the table, 927or the index is not present in the table,
918the corresponding fallback is called. 928the corresponding fallback is called.
919 929
920%For compatibility with previous versions of the API,
921%the following macros are supported:
922%\Deffunc{lua_getindexed}\Deffunc{lua_getfield}
923%\begin{verbatim}
924%lua_Object lua_getindexed (lua_Object table, float index);
925%lua_Object lua_getfield (lua_Object table, char *field);
926%\end{verbatim}
927%The first one is used for numeric indices,
928%while the second can be used for any string index.
929
930To store a value in an index, 930To store a value in an index,
931the program must push onto the stack the table, the index, 931the program must push onto the stack the table, the index,
932and the value, 932and the value,
@@ -1133,20 +1133,24 @@ declared in \verb-lualib.h-.
1133 1133
1134\subsection{Predefined Functions} 1134\subsection{Predefined Functions}
1135 1135
1136\subsubsection*{{\tt dofile (filename)}}\Deffunc{dofile} 1136\subsubsection*{\ff{\tt dofile (filename)}}\Deffunc{dofile}
1137This function receives a file name, 1137This function receives a file name,
1138opens it, and executes its contents as a Lua chunk, 1138opens it, and executes its contents as a Lua chunk,
1139or as pre-compiled chunks. 1139or as pre-compiled chunks.
1140When called without arguments, 1140When called without arguments,
1141it executes the contents of the standard input (\verb'stdin'). 1141it executes the contents of the standard input (\verb'stdin').
1142It returns 1 if there are no errors, \nil\ otherwise. 1142If there is any error executing the file, it returns \nil.
1143Otherwise, it returns the values returned by the chunk,
1144or a non \nil\ value if the chunk returns no values.
1143It issues an error when called with a non string argument. 1145It issues an error when called with a non string argument.
1144 1146
1145\subsubsection*{{\tt dostring (string)}}\Deffunc{dostring} 1147\subsubsection*{\ff{\tt dostring (string)}}\Deffunc{dostring}
1146This function executes a given string as a Lua chunk. 1148This function executes a given string as a Lua chunk.
1147It returns 1 if there are no errors, \nil\ otherwise. 1149If there is any error executing the string, it returns \nil.
1150Otherwise, it returns the values returned by the chunk,
1151or a non \nil\ value if the chunk returns no values.
1148 1152
1149\subsubsection*{{\tt next (table, index)}}\Deffunc{next} 1153\subsubsection*{\ff{\tt next (table, index)}}\Deffunc{next}
1150This function allows a program to traverse all fields of a table. 1154This function allows a program to traverse all fields of a table.
1151Its first argument is a table and its second argument 1155Its first argument is a table and its second argument
1152is an index in this table. 1156is an index in this table.
@@ -1167,7 +1171,7 @@ The order the indices are enumerated is not specified,
1167 1171
1168See Section \ref{exnext} for an example of the use of this function. 1172See Section \ref{exnext} for an example of the use of this function.
1169 1173
1170\subsubsection*{{\tt nextvar (name)}}\Deffunc{nextvar} 1174\subsubsection*{\ff{\tt nextvar (name)}}\Deffunc{nextvar}
1171This function is similar to the function \verb'next', 1175This function is similar to the function \verb'next',
1172but iterates over the global variables. 1176but iterates over the global variables.
1173Its single argument is the name of a global variable, 1177Its single argument is the name of a global variable,
@@ -1177,11 +1181,11 @@ and its value,
1177or \nil\ if there are no more variables. 1181or \nil\ if there are no more variables.
1178See Section \ref{exnext} for an example of the use of this function. 1182See Section \ref{exnext} for an example of the use of this function.
1179 1183
1180\subsubsection*{{\tt tostring (e)}}\Deffunc{tostring} 1184\subsubsection*{\ff{\tt tostring (e)}}\Deffunc{tostring}
1181This function receives an argument of any type and 1185This function receives an argument of any type and
1182converts it to a string in a reasonable format. 1186converts it to a string in a reasonable format.
1183 1187
1184\subsubsection*{{\tt print (e1, e2, ...)}}\Deffunc{print} 1188\subsubsection*{\ff{\tt print (e1, e2, ...)}}\Deffunc{print}
1185This function receives any number of arguments, 1189This function receives any number of arguments,
1186and prints their values in a reasonable format. 1190and prints their values in a reasonable format.
1187Each value is printed in a new line. 1191Each value is printed in a new line.
@@ -1190,14 +1194,14 @@ but as a quick way to show a value,
1190for instance for error messages or debugging. 1194for instance for error messages or debugging.
1191See Section~\ref{libio} for functions for formatted output. 1195See Section~\ref{libio} for functions for formatted output.
1192 1196
1193\subsubsection*{{\tt tonumber (e)}}\Deffunc{tonumber} 1197\subsubsection*{\ff{\tt tonumber (e)}}\Deffunc{tonumber}
1194This function receives one argument, 1198This function receives one argument,
1195and tries to convert it to a number. 1199and tries to convert it to a number.
1196If the argument is already a number or a string convertible 1200If the argument is already a number or a string convertible
1197to a number (\see{coercion}), then it returns that number; 1201to a number (\see{coercion}), then it returns that number;
1198otherwise, it returns \nil. 1202otherwise, it returns \nil.
1199 1203
1200\subsubsection*{{\tt type (v)}}\Deffunc{type} 1204\subsubsection*{\ff{\tt type (v)}}\Deffunc{type}
1201This function allows Lua to test the type of a value. 1205This function allows Lua to test the type of a value.
1202It receives one argument, and returns its type, coded as a string. 1206It receives one argument, and returns its type, coded as a string.
1203The possible results of this function are 1207The possible results of this function are
@@ -1214,54 +1218,59 @@ This tag can be used to distinguish between user
1214data with different tags, 1218data with different tags,
1215and between C functions and Lua functions. 1219and between C functions and Lua functions.
1216 1220
1217\subsubsection*{{\tt assert (v)}}\Deffunc{assert} 1221\subsubsection*{\ff{\tt assert (v)}}\Deffunc{assert}
1218This function issues an {\em ``assertion failed!''} error 1222This function issues an {\em ``assertion failed!''} error
1219when its argument is \nil. 1223when its argument is \nil.
1220 1224
1221\subsubsection*{{\tt error (message)}}\Deffunc{error}\label{pdf-error} 1225\subsubsection*{\ff{\tt error (message)}}\Deffunc{error}\label{pdf-error}
1222This function issues an error message and terminates 1226This function issues an error message and terminates
1223the last called function from the library 1227the last called function from the library
1224(\verb'lua_dofile', \verb'lua_dostring', \ldots). 1228(\verb'lua_dofile', \verb'lua_dostring', \ldots).
1225It never returns. 1229It never returns.
1226 1230
1227\subsubsection*{{\tt setglobal (name, value)}}\Deffunc{setglobal} 1231\subsubsection*{\ff{\tt setglobal (name, value)}}\Deffunc{setglobal}
1228This function assigns the given value to a global variable. 1232This function assigns the given value to a global variable.
1229The string \verb'name' does not need to be a syntactically valid variable name. 1233The string \verb'name' does not need to be a syntactically valid variable name.
1230Therefore, this function can set global variables with strange names like 1234Therefore, this function can set global variables with strange names like
1231\verb'm v 1' or \verb'34'. 1235\verb|`m v 1'| or \verb'34'.
1232It returns the value of its second argument. 1236It returns the value of its second argument.
1233 1237
1234\subsubsection*{{\tt getglobal (name)}}\Deffunc{getglobal} 1238\subsubsection*{\ff{\tt getglobal (name)}}\Deffunc{getglobal}
1235This function retrieves the value of a global variable. 1239This function retrieves the value of a global variable.
1236The string \verb'name' does not need to be a syntactically valid variable name. 1240The string \verb'name' does not need to be a syntactically valid variable name.
1237 1241
1238\subsubsection*{{\tt setfallback (fallbackname, newfallback)}} 1242\subsubsection*{\ff{\tt setfallback (fallbackname, newfallback)}}
1239\Deffunc{setfallback} 1243\Deffunc{setfallback}
1240This function sets a new fallback function to the given fallback. 1244This function sets a new fallback function to the given fallback.
1241It returns the old fallback function. 1245It returns the old fallback function.
1242 1246
1243\subsection{String Manipulation} 1247\subsection{String Manipulation}
1244This library provides generic functions for string manipulation, 1248This library provides generic functions for string manipulation,
1245such as finding and extracting substrings. 1249such as finding and extracting substrings and pattern matching.
1246When indexing a string, the first character has position 1. 1250When indexing a string, the first character has position 1.
1247See Section \ref{exstring} for some examples on string manipulation 1251See Page~\pageref{pm} for an explanation about patterns,
1252and Section~\ref{exstring} for some examples on string manipulation
1248in Lua. 1253in Lua.
1249 1254
1250\subsubsection*{{\tt strfind (str, substr, [init, [end]])}} 1255\subsubsection*{\ff{\tt strfind (str, pattern [, init [, plain]])}}
1251\Deffunc{strfind} 1256\Deffunc{strfind}
1252Receives two string arguments, 1257This function looks for the first {\em match} of
1253and returns a number. 1258\verb-pattern- in \verb-str-.
1254This number indicates the first position where the second argument appears 1259If it finds one, it returns the indexes on \verb-str-
1255in the first argument. 1260where this occurence starts and ends;
1256If the second argument is not a substring of the first one, 1261otherwise, it returns \nil.
1257then \verb'strfind' returns \nil. 1262If the pattern specifies captures,
1258A third optional numerical argument specifies where to start the search. 1263the captured strings are returned as extra results.
1259Another optional numerical argument specifies where to stop it. 1264A third optional numerical argument specifies where to start the search;
1260 1265its default value is 1.
1261\subsubsection*{{\tt strlen (s)}}\Deffunc{strlen} 1266A value of 1 as a forth optional argument
1267turns off the pattern matching facilities,
1268so the function does a plain ``find substring'' operation.
1269
1270\subsubsection*{\ff{\tt strlen (s)}}\Deffunc{strlen}
1262Receives a string and returns its length. 1271Receives a string and returns its length.
1263 1272
1264\subsubsection*{{\tt strsub (s, i, [j])}}\Deffunc{strsub} 1273\subsubsection*{\ff{\tt strsub (s, i [, j])}}\Deffunc{strsub}
1265Returns another string, which is a substring of \verb's', 1274Returns another string, which is a substring of \verb's',
1266starting at \verb'i' and runing until \verb'j'. 1275starting at \verb'i' and runing until \verb'j'.
1267If \verb'j' is absent, 1276If \verb'j' is absent,
@@ -1271,21 +1280,25 @@ with length \verb'j',
1271whereas the call \verb'strsub(s,i)' returns a suffix of \verb's', 1280whereas the call \verb'strsub(s,i)' returns a suffix of \verb's',
1272starting at \verb'i'. 1281starting at \verb'i'.
1273 1282
1274\subsubsection*{{\tt strlower (s)}}\Deffunc{strlower} 1283\subsubsection*{\ff{\tt strlower (s)}}\Deffunc{strlower}
1275Receives a string and returns a copy of that string with all 1284Receives a string and returns a copy of that string with all
1276upper case letters changed to lower case. 1285upper case letters changed to lower case.
1277All other characters are left unchanged. 1286All other characters are left unchanged.
1278 1287
1279\subsubsection*{{\tt strupper (s)}}\Deffunc{strupper} 1288\subsubsection*{\ff{\tt strupper (s)}}\Deffunc{strupper}
1280Receives a string and returns a copy of that string with all 1289Receives a string and returns a copy of that string with all
1281lower case letters changed to upper case. 1290lower case letters changed to upper case.
1282All other characters are left unchanged. 1291All other characters are left unchanged.
1283 1292
1284\subsubsection*{{\tt ascii (s, [i])}}\Deffunc{ascii} 1293\subsubsection*{\ff{\tt strrep (s, n)}}\Deffunc{strrep}
1294Returns a string which is the concatenation of \verb-n- copies of
1295the string \verb-s-.
1296
1297\subsubsection*{\ff{\tt ascii (s [, i])}}\Deffunc{ascii}
1285Returns the ascii code of the character \verb's[i]'. 1298Returns the ascii code of the character \verb's[i]'.
1286If \verb'i' is absent, then it is assumed to be 1. 1299If \verb'i' is absent, then it is assumed to be 1.
1287 1300
1288\subsubsection*{{\tt format (formatstring, e1, e2, \ldots)}}\Deffunc{format} 1301\subsubsection*{\ff{\tt format (formatstring, e1, e2, \ldots)}}\Deffunc{format}
1289\label{format} 1302\label{format}
1290This function returns a formated version of its variable number of arguments 1303This function returns a formated version of its variable number of arguments
1291following the description given in its first argument (which must be a string). 1304following the description given in its first argument (which must be a string).
@@ -1300,12 +1313,120 @@ back by the Lua interpreter.
1300The string is written between double quotes, 1313The string is written between double quotes,
1301and all double quotes, returns and backslashes in the string 1314and all double quotes, returns and backslashes in the string
1302are correctly escaped when written. 1315are correctly escaped when written.
1316For instance, the call
1317\begin{verbatim}
1318format('%q', 'a string with "quotes" and \n new line')
1319\end{verbatim}
1320will produce the string:
1321\begin{verbatim}
1322"a string with \"quotes\" and \
1323 new line"
1324\end{verbatim}
1303 1325
1304The options \verb'c', \verb'd', \verb'E', \verb'e', \verb'f', 1326The options \verb'c', \verb'd', \verb'E', \verb'e', \verb'f',
1305\verb'g' \verb'i', \verb'o', \verb'u', \verb'X', and \verb'x' all 1327\verb'g' \verb'i', \verb'o', \verb'u', \verb'X', and \verb'x' all
1306expect a number argument, 1328expect a number as argument,
1307whereas \verb'q' and \verb's' expect a string. 1329whereas \verb'q' and \verb's' expect a string.
1308 1330
1331\subsubsection*{\ff{\tt gsub (s, from, to [, n])}}\Deffunc{gsub}
1332Returns a copy of \verb-s-,
1333where all ocurrences of the pattern \verb-from- have been
1334replaced by a replacement string specified by \verb-to-.
1335This function also returns, as a second value,
1336the total number of substitutions made.
1337
1338If \verb-to- 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
1340stands for the value of the n-th captured substring.
1341
1342If \verb-to- is a function, this function is called every time a
1343match occurs, with all captured substrings as parameters.
1344If the value returned by this function is a string,
1345it is used as the replacement string;
1346otherwise, the replacement string is the empty string.
1347
1348An optional parameter \verb-n- limits
1349the maximum number of substitutions to occur.
1350For instance, when \verb-n- is 1 only the first ocurrence of
1351\verb-from- is replaced.
1352
1353As an example, in the following expression each ocurrence of the form
1354\verb-$name$- calls the function \verb|getenv|,
1355passing \verb|name| as argument
1356(because only this part of the pattern is captured).
1357The value returned by \verb|getenv| will replace the pattern.
1358Therefore, the whole expression:
1359\begin{verbatim}
1360 gsub('home = $HOME$, user = $USER$', "$(%w%w*)$", getenv)
1361\end{verbatim}
1362may return the string:
1363\begin{verbatim}
1364home = /home/roberto, user = roberto
1365\end{verbatim}
1366
1367\subsubsection*{Patterns} \label{pm}
1368
1369A \Def{character class} is used to represent a set of characters.
1370The following combinations are allowed in describing a character class:
1371\begin{description}
1372\item[{\em x}] (where {\em x} is any character not in the list \verb'()%.[*?')
1373--- represents the character {\em x} itself.
1374\item[{\tt .}] --- represents all characters.
1375\item[{\tt \%a}] --- represents all letters.
1376\item[{\tt \%A}] --- represents all non letter characters.
1377\item[{\tt \%d}] --- represents all digits.
1378\item[{\tt \%D}] --- represents all non digits.
1379\item[{\tt \%l}] --- represents all lower case letters.
1380\item[{\tt \%L}] --- represents all non lower case letter characters.
1381\item[{\tt \%s}] --- represents all space characters.
1382\item[{\tt \%S}] --- represents all non space characters.
1383\item[{\tt \%u}] --- represents all upper case letters.
1384\item[{\tt \%U}] --- represents all non upper case letter characters.
1385\item[{\tt \%w}] --- represents all alphanumeric characters.
1386\item[{\tt \%W}] --- represents all non alphanumeric characters.
1387\item[{\tt \%\em x}] (where {\em x} is any non alphanumeric character) ---
1388represents the character {\em x}.
1389\item[{\tt [char-set]}] ---
1390Represents the class which is the union of all
1391characters in char-set.
1392To include a \verb']' in char-set, it must be the first character.
1393A range of characters may be specified by
1394separating the end characters of the range with a \verb'-';
1395e.g., \verb'A-Z' specifies the upper case characters.
1396If \verb'-' appears as the first or last character of char-set,
1397then it represents itself.
1398All classes \verb'%'{\em x} described above can also be used as
1399components in a char-set.
1400All other characters in char-set represent themselves.
1401\item[{\tt [\^{ }char-set]}] ---
1402represents the complement of char-set,
1403where char-set is interpreted as above.
1404\end{description}
1405
1406A \Def{pattern item} may be a single character class,
1407or a character class followed by \verb'*' or by \verb'?'.
1408A single character class matches any single character in the class.
1409A character class followed by \verb'*' matches 0 or more repetitions
1410of characters in the class.
1411A character class followed by \verb'?' matches 0 or one ocurrence
1412of a character in the class.
1413A pattern item may also has the form \verb'%n',
1414for \verb-n- between 1 and 9.
1415Such item matches a sub-string equal to the n-th captured string.
1416
1417A \Def{pattern} is a sequence of pattern items.
1418Any repetition item (\verb'*') inside a pattern will always
1419match the longest possible sequence.
1420A \verb'^' at the beginning of a pattern anchors the match at the
1421beginning of the subject string.
1422A \verb'$' at the end of a pattern anchors the match at the
1423end of the subject string.
1424
1425A pattern may contain sub-patterns enclosed in parentheses,
1426that describe \Def{captures}.
1427When a match succeeds, the sub-strings of the subject string
1428that match captures are {\em captured} for future use.
1429Captures are numbered according to their left delimiter.
1309 1430
1310\subsection{Mathematical Functions} \label{mathlib} 1431\subsection{Mathematical Functions} \label{mathlib}
1311 1432
@@ -1333,8 +1454,6 @@ value of its numeric arguments.
1333Similarly, \verb'min' computes the minimum. 1454Similarly, \verb'min' computes the minimum.
1334Both can be used with an unlimited number of arguments. 1455Both can be used with an unlimited number of arguments.
1335 1456
1336The function \verb'mod' is equivalent to the \verb'%' operator in C.
1337
1338The functions \verb'random' and \verb'randomseed' are interfaces to 1457The functions \verb'random' and \verb'randomseed' are interfaces to
1339the simple random generator functions \verb'rand' and \verb'srand', 1458the simple random generator functions \verb'rand' and \verb'srand',
1340provided by ANSI C. 1459provided by ANSI C.
@@ -1350,129 +1469,127 @@ Initially, the current input file is \verb'stdin',
1350and the current output file is \verb'stdout'. 1469and the current output file is \verb'stdout'.
1351 1470
1352Unless otherwise stated, 1471Unless otherwise stated,
1353all I/O functions return 1 on success and \nil\ on failure. 1472all I/O functions return \nil\ on failure and
1354 1473some value different from \nil\ on success.
1355\subsubsection*{{\tt readfrom (filename)}}\Deffunc{readfrom} 1474
1356 1475\subsubsection*{\ff{\tt readfrom (filename)}}\Deffunc{readfrom}
1357This function opens a file named \verb'filename' and sets it as the 1476
1358{\em current} input file. 1477This function may be called in three ways.
1478When called with a file name,
1479it opens the named file,
1480sets it as the {\em current} input file,
1481and returns a {\em handle} to the file
1482(this handle is a user data containing the file stream \verb|FILE *|).
1483When called with a file handle, returned by a previous call,
1484it restores the file as the current input.
1359When called without parameters, 1485When called without parameters,
1360this function closes the current input file, 1486it closes the current input file,
1361and restores \verb'stdin' as the current input file. 1487and restores \verb'stdin' as the current input file.
1362 1488
1489If this function fails, it returns \nil.
1490
1363{\em System dependent:} if \verb'filename' starts with a \verb'|', 1491{\em System dependent:} if \verb'filename' starts with a \verb'|',
1364then a \Index{piped input} is open, via function \IndexVerb{popen}. 1492then a \Index{piped input} is open, via function \IndexVerb{popen}.
1365 1493
1366\subsubsection*{{\tt writeto (filename)}}\Deffunc{writeto} 1494\subsubsection*{\ff{\tt writeto (filename)}}\Deffunc{writeto}
1367 1495
1368This function opens a file named \verb'filename' and sets it as the 1496This function may be called in three ways.
1369{\em current} output file. 1497When called with a file name,
1498it opens the named file,
1499sets it as the {\em current} output file,
1500and returns a {\em handle} to the file
1501(this handle is a user data containing the file stream \verb|FILE *|).
1370Notice that, if the file already exists, 1502Notice that, if the file already exists,
1371it will be {\em completely erased} with this operation. 1503it will be {\em completely erased} with this operation.
1504When called with a file handle, returned by a previous call,
1505it restores the file as the current output.
1372When called without parameters, 1506When called without parameters,
1373this function closes the current output file, 1507this function closes the current output file,
1374and restores \verb'stdout' as the current output file. 1508and restores \verb'stdout' as the current output file.
1375\index{closing a file} 1509\index{closing a file}
1376 1510
1511If this function fails, it returns \nil.
1512
1377{\em System dependent:} if \verb'filename' starts with a \verb'|', 1513{\em System dependent:} if \verb'filename' starts with a \verb'|',
1378then a \Index{piped output} is open, via function \IndexVerb{popen}. 1514then a \Index{piped output} is open, via function \IndexVerb{popen}.
1379 1515
1380\subsubsection*{{\tt appendto (filename)}}\Deffunc{appendto} 1516\subsubsection*{\ff{\tt appendto (filename)}}\Deffunc{appendto}
1381 1517
1382This function opens a file named \verb'filename' and sets it as the 1518This function opens a file named \verb'filename' and sets it as the
1383{\em current} output file. 1519{\em current} output file.
1520It returns the file handle,
1521or \nil\ in case of error.
1384Unlike the \verb'writeto' operation, 1522Unlike the \verb'writeto' operation,
1385this function does not erase any previous content of the file. 1523this function does not erase any previous content of the file.
1386 1524
1387\subsubsection*{{\tt remove (filename)}}\Deffunc{remove} 1525\subsubsection*{\ff{\tt remove (filename)}}\Deffunc{remove}
1388 1526
1389This function deletes the file with the given name. 1527This function deletes the file with the given name.
1390 1528
1391\subsubsection*{{\tt rename (name1, name2)}}\Deffunc{rename} 1529\subsubsection*{\ff{\tt rename (name1, name2)}}\Deffunc{rename}
1392 1530
1393This function renames file \verb'name1' to \verb'name2'. 1531This function renames file \verb'name1' to \verb'name2'.
1394 1532
1395\subsubsection*{{\tt tmpname ()}}\Deffunc{tmpname} 1533\subsubsection*{\ff{\tt tmpname ()}}\Deffunc{tmpname}
1396 1534
1397This function returns a string with a file name that can safely 1535This function returns a string with a file name that can safely
1398be used for a temporary file. 1536be used for a temporary file.
1399 1537
1400\subsubsection*{{\tt read ([format])}}\Deffunc{read} 1538\subsubsection*{\ff{\tt read ([readpattern])}}\Deffunc{read}
1401
1402This function returns a value read from the current input.
1403An optional string argument specifies the way the input is interpreted.
1404
1405Without a format argument, {\tt read} first skips blanks, tabs and newlines.
1406Then it checks whether the current character is \verb'"' or \verb-'-.
1407If so, it reads a string up to the ending quotation mark,
1408and returns this string, without the quotation marks.
1409Otherwise it reads up to a blank, tab or newline.
1410
1411The format string can have the following format:
1412\begin{verbatim}
1413 ?[n]
1414\end{verbatim}
1415where \verb'?' can be:
1416\begin{description}
1417\item['s' or 'S'] to read a string;
1418\item['f' or 'F'] to read a real number;
1419\item['i' or 'I'] to read an integer.
1420\end{description}
1421The optional \verb'n' is a number which specifies how many characters
1422must be read to compose the input value.
1423Particularly, the format \verb'"s1"' reads a single character.
1424
1425\subsubsection*{{\tt readuntil (char)}}\Deffunc{readuntil}
1426 1539
1427Reads the current input until the first ocurrence of the given character. 1540This function reads the current input
1428When called with no parameters, 1541according to a read pattern, that specifies how much to read;
1429reads until the end of the current input file. 1542characters are read from the current input file until
1430Returns the string read. 1543the read pattern fails or ends.
1431The character itself is not read. 1544The function \verb|read| returns a string with the characters read,
1432 1545or \nil\ if the result string would be empty {\em and\/}
1433\subsubsection*{{\tt write (value, [format])}}\Deffunc{write} 1546the read pattern fails.
1434 1547When called without parameters,
1435This function writes the value of its first argument to the current output. 1548it uses a default pattern that reads the next line
1436An optional second argument specifies the format to be used. 1549(see below).
1437This format is given as a string, composed of four parts. 1550
1438The first part is the only one not optional, and must be one of the 1551A \Def{read pattern} is a sequence of read pattern items.
1439following characters: 1552An item may be a single character class
1440\begin{description} 1553or a character class followed by \verb'?' or by \verb'*'.
1441\item['s' or 'S'] to write strings; 1554A single character class reads the next character from the input
1442\item['f' or 'F'] to write floats; 1555if it belongs to the class, otherwise it fails.
1443\item['i' or 'I'] to write integers; 1556A character class followed by \verb'?' reads the next character
1444\item['q' or 'Q'] to write quoted strings. 1557from the input if it belongs to the class;
1445This format writes the string in a form suitable to be safely read 1558it never fails.
1446back by the Lua interpreter. 1559A character class followed by \verb'*' reads until a character that
1447The string is written between double quotes, 1560does not belong to the class, or end of file;
1448and all double quotes, returns and backslashes in the string 1561it never fails.%
1449are correctly escaped when written. 1562\footnote{
1450\end{description} 1563Notice that this behaviour is different from regular pattern matching,
1451These characters can be followed by 1564where a \verb'*' expands to the maximum length {\em such that}
1452\begin{verbatim} 1565the rest of the pattern does not fail.}
1453 [?][m][.n] 1566
1454\end{verbatim} 1567A pattern item may contain sub-patterns enclosed in curly brackets,
1455where: 1568that describe \Def{skips}.
1456\begin{description} 1569Characters matching a skip are read,
1457\item[\verb'?'] indicates justification inside the field. 1570but are not included in the resulting string.
1571
1572Following are some examples of read patterns and their meanings:
1458\begin{itemize} 1573\begin{itemize}
1459\item['\verb'<''] right justification (default); 1574\item \verb|"."| returns the next character, or \nil\ on end of file.
1460\item['\verb'>''] left justification; 1575\item \verb|".*"| reads the whole file.
1461\item['\verb'|''] center justification. 1576\item \verb|"[^\n]*{\n}"| returns the next line
1577(skipping the end of line), or \nil\ on end of file.
1578This is the default pattern.
1579\item \verb|"{%s*}%S%S*"| returns the next word
1580(maximal sequence of non white-space characters),
1581or \nil\ on end of file.
1582\item \verb|"{%s*}[+-]?%d%d*"| returns the next integer
1583or \nil\ if the next characters do not conform to an integer format.
1462\end{itemize} 1584\end{itemize}
1463\item[\verb'm'] Indicates the field size in characters.
1464\item[\verb'.n'] For reals, indicates the number of digital places.
1465For integers, it is the minimum number of digits.
1466This option has no meaning for strings.
1467\end{description}
1468 1585
1469When called without a format string, 1586\subsubsection*{\ff{\tt write (value1, ...)}}\Deffunc{write}
1470this function writes numbers using the \verb'%g' format 1587
1471and strings with \verb'%s'. 1588This function writes the value of each of its arguments to the
1472For better format facilities, 1589current output file.
1473the function \verb'format' should be used (\see{format}). 1590The arguments must be strings or numbers.
1474 1591
1475\subsubsection*{{\tt date ([format])}}\Deffunc{date} 1592\subsubsection*{\ff{\tt date ([format])}}\Deffunc{date}
1476 1593
1477This function returns a string containing date and time 1594This function returns a string containing date and time
1478formatted according to the given string \verb'format', 1595formatted according to the given string \verb'format',
@@ -1480,15 +1597,23 @@ following the same rules of the ANSI C function \verb'strftime'.
1480When called without arguments, 1597When called without arguments,
1481it returns a reasonable date and time representation. 1598it returns a reasonable date and time representation.
1482 1599
1483This function replaces functions \verb'date' and \verb'time' from 1600\subsubsection*{\ff{\tt exit ([code])}}\Deffunc{exit}
1484previous Lua versions.
1485
1486\subsubsection*{{\tt exit ([code])}}\Deffunc{exit}
1487 1601
1488This function calls the C function \verb-exit-, 1602This function calls the C function \verb-exit-,
1489with an optional \verb-code-, 1603with an optional \verb-code-,
1490to terminate the program. 1604to terminate the program.
1491 1605
1606\subsubsection*{\ff{\tt getenv (varname)}}\Deffunc{getenv}
1607
1608Returns the value of the environment variable \verb|varname|,
1609or \nil\ if the variable is not defined.
1610
1611\subsubsection*{\ff{\tt execute (command)}}\Deffunc{execute}
1612
1613This function is equivalent to the C function \verb|system|.
1614It passes \verb|command| to be executed by an Operating System Shell.
1615It returns an error code, which is implementation-defined.
1616
1492 1617
1493\section{The Debugger Interface} \label{debugI} 1618\section{The Debugger Interface} \label{debugI}
1494 1619
@@ -1496,7 +1621,7 @@ Lua has no built-in debugger facilities.
1496Instead, it offers a special interface, 1621Instead, it offers a special interface,
1497by means of functions and {\em hooks}, 1622by means of functions and {\em hooks},
1498which allows the construction of different 1623which allows the construction of different
1499kinds of debugers, profilers, and other tools 1624kinds of debuggers, profilers, and other tools
1500that need ``inside information'' from the interpreter. 1625that need ``inside information'' from the interpreter.
1501This interface is declared in the header file \verb'luadebug.h'. 1626This interface is declared in the header file \verb'luadebug.h'.
1502 1627
@@ -1699,32 +1824,21 @@ end
1699 1824
1700\subsection{String Manipulation} \label{exstring} 1825\subsection{String Manipulation} \label{exstring}
1701 1826
1702The first example is a function to trim extra blanks at the beginning 1827The first example is a function to trim extra white-spaces at the beginning
1703and end of a string. 1828and end of a string.
1704\begin{verbatim} 1829\begin{verbatim}
1705function trim(s) 1830function trim(s)
1706 local l = 1 1831 local _, i = strfind(s, '^ *')
1707 while strsub(s,l,l) == ' ' do 1832 local f, __ = strfind(s, ' *$')
1708 l = l+1 1833 return strsub(s, i+1, f-1)
1709 end
1710 local r = strlen(s)
1711 while strsub(s,r,r) == ' ' do
1712 r = r-1
1713 end
1714 return strsub(s,l,r)
1715end 1834end
1716\end{verbatim} 1835\end{verbatim}
1717 1836
1718The second example shows a function that eliminates all blanks 1837The second example shows a function that eliminates all spaces
1719of a string. 1838of a string.
1720\begin{verbatim} 1839\begin{verbatim}
1721function remove_blanks (s) 1840function remove_blanks (s)
1722 local b = strfind(s, ' ') 1841 return gsub(s, "%s%s*", "")
1723 while b do
1724 s = strsub(s, 1, b-1) .. strsub(s, b+1)
1725 b = strfind(s, ' ')
1726 end
1727 return s
1728end 1842end
1729\end{verbatim} 1843\end{verbatim}
1730 1844
@@ -2058,6 +2172,46 @@ void remove_blanks (char *s)
2058\end{verbatim} 2172\end{verbatim}
2059 2173
2060 2174
2175\section{\Index{Lua Stand-alone}}
2176
2177Although Lua has been designed as an extension language,
2178the language can also be used as a stand-alone interpreter.
2179An implementation of such an interpreter,
2180called simply \verb|lua|,
2181is provided with the standard distribution.
2182This program can be called with any sequence of the following arguments:
2183\begin{description}
2184\item[{\tt -v}] prints version information.
2185\item[{\tt -}] runs interactively, accepting commands from standard input
2186until an \verb|EOF|.
2187\item[{\tt -e stat}] executes \verb|stat| as a Lua chunck.
2188\item[{\tt var=exp}] executes \verb|var=exp| as a Lua chunck.
2189\item[{\tt filename}] executes file \verb|filename| as a Lua chunck.
2190\end{description}
2191All arguments are handle in order.
2192For instance, an invocation like
2193\begin{verbatim}
2194$ lua - a=1 prog.lua
2195\end{verbatim}
2196will first interact with the user until an \verb|EOF|,
2197then will set \verb'a' to 1,
2198and finally will run file \verb'prog.lua'.
2199
2200Please notice that the interaction with the shell may lead to
2201unintended results.
2202For instance, a call like
2203\begin{verbatim}
2204$ lua a="name" prog.lua
2205\end{verbatim}
2206will {\em not} set \verb|a| to the string \verb|"name"|.
2207Instead, the quotes will be handled by the shell,
2208lua will get only \verb'a=name' to run,
2209and \verb'a' will finish with \nil.
2210Instead, one should write
2211\begin{verbatim}
2212$ lua 'a="name"' prog.lua
2213\end{verbatim}
2214
2061\section*{Acknowledgments} 2215\section*{Acknowledgments}
2062 2216
2063The authors would like to thank CENPES/PETROBR\'AS which, 2217The authors would like to thank CENPES/PETROBR\'AS which,
@@ -2076,7 +2230,27 @@ Lua means {\em moon} in Portuguese.
2076Although great care has been taken to avoid incompatibilities with 2230Although great care has been taken to avoid incompatibilities with
2077the previous public versions of Lua, 2231the previous public versions of Lua,
2078some differences had to be introduced. 2232some differences had to be introduced.
2079Here is a list of all these differences. 2233Here is a list of all these incompatibilities.
2234
2235\subsection*{Incompatibilities with \Index{version 2.4}}
2236The whole I/O facilities have been rewritten.
2237We strongly encourage programmers to addapt their code
2238to this new version.
2239However, we are keeping the old version of the libraries
2240in the distribution,
2241to allow a smooth transition.
2242The incompatibilities between the new and the old libraries are:
2243\begin{itemize}
2244\item The format facility of function \verb'write' has been supersed by
2245function \verb'format';
2246therefore this facility has been dropped.
2247\item Function \verb'read' now uses {\em read patterns} to specify
2248what to read;
2249this is incompatible with the old format options.
2250\item Function \verb'strfind' now accepts patterns,
2251so it may have a different behavior when the pattern includes
2252special characteres.
2253\end{itemize}
2080 2254
2081\subsection*{Incompatibilities with \Index{version 2.2}} 2255\subsection*{Incompatibilities with \Index{version 2.2}}
2082\begin{itemize} 2256\begin{itemize}