diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-18 17:14:52 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-06-18 17:14:52 -0300 |
commit | 6b78040840bbd457cc325f7a31bb5fbaf549f23f (patch) | |
tree | 3bf0bf4c7d52e8bf2559cdda15b98b472520c0b1 | |
parent | e931c7c0f605f140fa60d0b676fe7caf12a6f410 (diff) | |
download | lua-6b78040840bbd457cc325f7a31bb5fbaf549f23f.tar.gz lua-6b78040840bbd457cc325f7a31bb5fbaf549f23f.tar.bz2 lua-6b78040840bbd457cc325f7a31bb5fbaf549f23f.zip |
lhf corrections + new gsub
-rw-r--r-- | manual.tex | 474 |
1 files changed, 254 insertions, 220 deletions
@@ -1,4 +1,4 @@ | |||
1 | % $Id: manual.tex,v 1.30 1997/06/09 18:16:33 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 2.0 1997/06/17 18:45:16 roberto Exp roberto $ |
2 | 2 | ||
3 | \documentstyle[fullpage,11pt,bnf]{article} | 3 | \documentstyle[fullpage,11pt,bnf]{article} |
4 | 4 | ||
@@ -31,13 +31,13 @@ Luiz Henrique de Figueiredo\quad | |||
31 | Waldemar Celes | 31 | Waldemar Celes |
32 | \vspace{1.0ex}\\ | 32 | \vspace{1.0ex}\\ |
33 | \smallskip | 33 | \smallskip |
34 | \small\tt lua@icad.puc-rio.br | 34 | \small\tt lua@tecgraf.puc-rio.br |
35 | \vspace{2.0ex}\\ | 35 | \vspace{2.0ex}\\ |
36 | %MCC 08/95 --- | 36 | %MCC 08/95 --- |
37 | \tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio | 37 | \tecgraf\ --- Computer Science Department --- PUC-Rio |
38 | } | 38 | } |
39 | 39 | ||
40 | \date{\small \verb$Date: 1997/06/09 18:16:33 $} | 40 | \date{\small \verb$Date: 1997/06/17 18:45:16 $} |
41 | 41 | ||
42 | \maketitle | 42 | \maketitle |
43 | 43 | ||
@@ -71,8 +71,10 @@ a intera\c{c}\~ao entre programas Lua e programas C hospedeiros. | |||
71 | \begin{quotation} | 71 | \begin{quotation} |
72 | \noindent | 72 | \noindent |
73 | \footnotesize | 73 | \footnotesize |
74 | Copyright (c) 1994--1997 TeCGraf, PUC-Rio. Written by Waldemar Celes Filho, | 74 | Copyright \copyright\ 1994--1997 TeCGraf, PUC-Rio. |
75 | Roberto Ierusalimschy, Luiz Henrique de Figueiredo. All rights reserved. | 75 | Written by Waldemar Celes Filho, |
76 | Roberto Ierusalimschy, Luiz Henrique de Figueiredo. | ||
77 | All rights reserved. | ||
76 | % | 78 | % |
77 | Permission is hereby granted, without written agreement and without license or | 79 | Permission is hereby granted, without written agreement and without license or |
78 | royalty fees, to use, copy, modify, and distribute this software and its | 80 | royalty fees, to use, copy, modify, and distribute this software and its |
@@ -81,17 +83,20 @@ documentation for any purpose, subject to the following conditions: | |||
81 | The above copyright notice and this permission notice shall appear in all | 83 | The above copyright notice and this permission notice shall appear in all |
82 | copies or substantial portions of this software. | 84 | copies or substantial portions of this software. |
83 | % | 85 | % |
84 | The name "Lua" cannot be used for any modified form of this software that does | 86 | The name ``Lua'' cannot be used for any modified form |
85 | not originate from the authors. Nevertheless, the name "Lua" may and should be | 87 | of this software that does not originate from the authors. |
88 | Nevertheless, the name ``Lua'' may and should be | ||
86 | used to designate the language implemented and described in this package, | 89 | used to designate the language implemented and described in this package, |
87 | even if embedded in any other system, as long as its syntax and semantics | 90 | even if embedded in any other system, as long as its syntax and semantics |
88 | remain unchanged. | 91 | remain unchanged. |
89 | % | 92 | % |
90 | The authors specifically disclaim any warranties, including, but not limited | 93 | The authors specifically disclaim any warranties, including, |
91 | to, the implied warranties of merchantability and fitness for a particular | 94 | but not limited to, the implied warranties of merchantability |
92 | purpose. The software provided hereunder is on an "as is" basis, and the | 95 | and fitness for a particular purpose. |
96 | The software provided hereunder is on an ``as is'' basis, and the | ||
93 | authors have no obligation to provide maintenance, support, updates, | 97 | authors have no obligation to provide maintenance, support, updates, |
94 | enhancements, or modifications. In no event shall TeCGraf, PUC-Rio, or the | 98 | enhancements, or modifications. |
99 | In no event shall TeCGraf, PUC-Rio, or the | ||
95 | authors be liable to any party for direct, indirect, special, incidental, or | 100 | authors be liable to any party for direct, indirect, special, incidental, or |
96 | consequential damages arising out of the use of this software and its | 101 | consequential damages arising out of the use of this software and its |
97 | documentation. | 102 | documentation. |
@@ -110,7 +115,7 @@ documentation. | |||
110 | \section{Introduction} | 115 | \section{Introduction} |
111 | 116 | ||
112 | Lua is an extension programming language designed to support | 117 | Lua is an extension programming language designed to support |
113 | general procedural programming features with data description | 118 | general procedural programming with data description |
114 | facilities. | 119 | facilities. |
115 | It is intended to be used as a light-weight, but powerful, | 120 | It is intended to be used as a light-weight, but powerful, |
116 | configuration language for any program that needs one. | 121 | configuration language for any program that needs one. |
@@ -127,11 +132,12 @@ This host program can invoke functions to execute a piece of | |||
127 | code in Lua, can write and read Lua variables, | 132 | code in Lua, can write and read Lua variables, |
128 | and can register C functions to be called by Lua code. | 133 | and can register C functions to be called by Lua code. |
129 | Through the use of C functions, Lua can be augmented to cope with | 134 | Through the use of C functions, Lua can be augmented to cope with |
130 | many, completely different domains, | 135 | a wide range of different domains, |
131 | thus creating customized programming languages sharing a syntactical framework. | 136 | thus creating customized programming languages sharing a syntactical framework. |
132 | 137 | ||
133 | Lua is free-distribution software, | 138 | Lua is free-distribution software, |
134 | and provided as usual with no guarantees. | 139 | and provided as usual with no guarantees, |
140 | as stated in the copyright notice in the front page of this manual. | ||
135 | The implementation described in this manual is available | 141 | The implementation described in this manual is available |
136 | at the following URL's: | 142 | at the following URL's: |
137 | \begin{verbatim} | 143 | \begin{verbatim} |
@@ -155,7 +161,8 @@ using functions in the library that implements Lua. | |||
155 | \Index{Global variables} do not need declaration. | 161 | \Index{Global variables} do not need declaration. |
156 | Any variable is assumed to be global unless explicitly declared local | 162 | Any variable is assumed to be global unless explicitly declared local |
157 | \see{localvar}. | 163 | \see{localvar}. |
158 | Before the first assignment, the value of a global variable is \nil. | 164 | Before the first assignment, the value of a global variable is \nil; |
165 | this default can be changed \see{tag-method}. | ||
159 | 166 | ||
160 | The unit of execution of Lua is called a \Def{chunk}. | 167 | The unit of execution of Lua is called a \Def{chunk}. |
161 | The syntax% | 168 | The syntax% |
@@ -178,7 +185,8 @@ of new functions% | |||
178 | \footnote{Actually, a function definition is an | 185 | \footnote{Actually, a function definition is an |
179 | assignment to a global variable \see{TypesSec}.}. | 186 | assignment to a global variable \see{TypesSec}.}. |
180 | 187 | ||
181 | Chunks may be pre-compiled; see program \IndexVerb{luac} for details. | 188 | Chunks may be pre-compiled into binary form; |
189 | see program \IndexVerb{luac} for details. | ||
182 | Text files with chunks and their binary pre-compiled forms | 190 | Text files with chunks and their binary pre-compiled forms |
183 | are interchangeable. | 191 | are interchangeable. |
184 | Lua automatically detects the file type and acts accordingly. | 192 | Lua automatically detects the file type and acts accordingly. |
@@ -196,10 +204,10 @@ There are six \Index{basic types} in Lua: \Def{nil}, \Def{number}, | |||
196 | \Def{string}, \Def{function}, \Def{userdata}, and \Def{table}. | 204 | \Def{string}, \Def{function}, \Def{userdata}, and \Def{table}. |
197 | {\em Nil\/} is the type of the value \nil, | 205 | {\em Nil\/} is the type of the value \nil, |
198 | whose main property is to be different from any other value. | 206 | whose main property is to be different from any other value. |
199 | {\em Number\/} represents real (floating point) numbers, | 207 | {\em Number\/} represents real (floating-point) numbers, |
200 | while {\em string\/} has the usual meaning. | 208 | while {\em string\/} has the usual meaning. |
201 | The function \verb|type| returns a string describing the type | 209 | The function \verb|type| returns a string describing the type |
202 | of a given value. | 210 | of a given value \see{pdf-type}. |
203 | 211 | ||
204 | Functions are considered first-class values in Lua. | 212 | Functions are considered first-class values in Lua. |
205 | This means that functions can be stored in variables, | 213 | This means that functions can be stored in variables, |
@@ -210,7 +218,8 @@ Lua can call (and manipulate) functions written in Lua and | |||
210 | functions written in C. | 218 | functions written in C. |
211 | They can be distinguished by their tags: | 219 | They can be distinguished by their tags: |
212 | all Lua functions have the same tag, | 220 | all Lua functions have the same tag, |
213 | which is different from the tag for all C functions. | 221 | and all C functions have the same tag, |
222 | which is different from the tag of a Lua function. | ||
214 | 223 | ||
215 | The type {\em userdata\/} is provided to allow | 224 | The type {\em userdata\/} is provided to allow |
216 | arbitrary \Index{C pointers} to be stored in Lua variables. | 225 | arbitrary \Index{C pointers} to be stored in Lua variables. |
@@ -233,7 +242,7 @@ Because functions are first class values, | |||
233 | table fields may contain functions. | 242 | table fields may contain functions. |
234 | The form \verb|t:f(x)| is syntactic sugar for \verb|t.f(t,x)|, | 243 | The form \verb|t:f(x)| is syntactic sugar for \verb|t.f(t,x)|, |
235 | which calls the method \verb|f| from the table \verb|t| passing | 244 | which calls the method \verb|f| from the table \verb|t| passing |
236 | itself as the first parameter. | 245 | itself as the first parameter \see{func-def}. |
237 | 246 | ||
238 | It is important to notice that tables are {\em objects}, and not values. | 247 | It is important to notice that tables are {\em objects}, and not values. |
239 | Variables cannot contain tables, only {\em references\/} to them. | 248 | Variables cannot contain tables, only {\em references\/} to them. |
@@ -244,10 +253,10 @@ Moreover, tables must be explicitly created before used | |||
244 | 253 | ||
245 | Tags are mainly used to select tag methods when | 254 | Tags are mainly used to select tag methods when |
246 | some events occur \see{tag-method}. | 255 | some events occur \see{tag-method}. |
247 | Each of the types nil, number and string have a different tag. | 256 | Each of the types nil, number and string has a different tag. |
248 | All values of each of these types have this same pre-defined tag. | 257 | All values of each of these types have this same pre-defined tag. |
249 | Values of type function may have two different tags, | 258 | Values of type function can have two different tags, |
250 | depending whether they are Lua or C functions. | 259 | depending on whether they are Lua or C functions. |
251 | Finally, | 260 | Finally, |
252 | values of type userdata and table can have | 261 | values of type userdata and table can have |
253 | as many different tags as needed \see{tag-method}. | 262 | as many different tags as needed \see{tag-method}. |
@@ -264,7 +273,7 @@ This section describes the lexis, the syntax and the semantics of Lua. | |||
264 | 273 | ||
265 | \subsection{Lexical Conventions} \label{lexical} | 274 | \subsection{Lexical Conventions} \label{lexical} |
266 | 275 | ||
267 | Lua is a case sensitive language. | 276 | Lua is a case-sensitive language. |
268 | \Index{Identifiers} can be any string of letters, digits, and underscores, | 277 | \Index{Identifiers} can be any string of letters, digits, and underscores, |
269 | not beginning with a digit. | 278 | not beginning with a digit. |
270 | The following words are reserved, and cannot be used as identifiers: | 279 | The following words are reserved, and cannot be used as identifiers: |
@@ -295,8 +304,8 @@ other quoted strings. | |||
295 | 304 | ||
296 | \Index{Comments} start anywhere outside a string with a | 305 | \Index{Comments} start anywhere outside a string with a |
297 | double hyphen (\verb|--|) and run until the end of the line. | 306 | double hyphen (\verb|--|) and run until the end of the line. |
298 | Moreover, if the first line of a chunk file starts with \verb|#|, | 307 | Moreover, |
299 | this line is skipped% | 308 | the first line of a chunk file is skipped if it starts with \verb|#|% |
300 | \footnote{This facility allows the use of Lua as a script interpreter | 309 | \footnote{This facility allows the use of Lua as a script interpreter |
301 | in Unix systems \see{lua-sa}.}. | 310 | in Unix systems \see{lua-sa}.}. |
302 | 311 | ||
@@ -314,10 +323,10 @@ The \verb|$| can be followed by any of the following directives: | |||
314 | \begin{description} | 323 | \begin{description} |
315 | \item[{\tt debug}] --- turn on some debugging facilities \see{pragma}. | 324 | \item[{\tt debug}] --- turn on some debugging facilities \see{pragma}. |
316 | \item[{\tt nodebug}] --- turn off some debugging facilities \see{pragma}. | 325 | \item[{\tt nodebug}] --- turn off some debugging facilities \see{pragma}. |
317 | \item[{\tt if \M{cond}}] --- starts a condicional part. | 326 | \item[{\tt if \M{cond}}] --- starts a conditional part. |
318 | If \M{cond} is false, this part is skiped by the lexical analizer. | 327 | If \M{cond} is false, then this part is skipped by the lexical analyzer. |
319 | \item[{\tt ifnot \M{cond}}] --- starts a condicional part. | 328 | \item[{\tt ifnot \M{cond}}] --- starts a conditional part. |
320 | If \M{cond} is true, this part is skiped by the lexical analizer. | 329 | If \M{cond} is true, then this part is skipped by the lexical analyzer. |
321 | \item[{\tt end}] --- ends a conditional part. | 330 | \item[{\tt end}] --- ends a conditional part. |
322 | \item[{\tt else}] --- starts an ``else'' conditional part, | 331 | \item[{\tt else}] --- starts an ``else'' conditional part, |
323 | switching the ``skip'' status. | 332 | switching the ``skip'' status. |
@@ -325,15 +334,16 @@ switching the ``skip'' status. | |||
325 | \end{description} | 334 | \end{description} |
326 | 335 | ||
327 | Directives can be freely nested. | 336 | Directives can be freely nested. |
328 | Particularlly, a \verb|$endinput| may ocurr inside a \verb|$if|; | 337 | Particularly, a \verb|$endinput| may occur inside a \verb|$if|; |
329 | in that case, even the matching \verb|$end| is not parsed. | 338 | in that case, even the matching \verb|$end| is not parsed. |
330 | 339 | ||
331 | A \M{cond} part may be: | 340 | A \M{cond} part may be: |
332 | \begin{description} | 341 | \begin{description} |
333 | \item[{\tt nil}] --- always false. | 342 | \item[{\tt nil}] --- always false. |
334 | \item[{\tt 1}] --- always true. | 343 | \item[{\tt 1}] --- always true. |
335 | \item[\M{name}] --- true if global variable \M{name} is different from \nil. | 344 | \item[\M{name}] --- true if the value of the |
336 | Notice that this is evaluated before the chunk starts its execution. | 345 | global variable \M{name} is different from \nil. |
346 | Notice that \M{name} is evaluated before the chunk starts its execution. | ||
337 | Therefore, actions in a chunk do not affect its own conditional directives. | 347 | Therefore, actions in a chunk do not affect its own conditional directives. |
338 | \end{description} | 348 | \end{description} |
339 | 349 | ||
@@ -389,7 +399,8 @@ This restriction also avoids some ``statement not reached'' conditions. | |||
389 | 399 | ||
390 | \subsubsection{\Index{Assignment}} \label{assignment} | 400 | \subsubsection{\Index{Assignment}} \label{assignment} |
391 | The language allows \Index{multiple assignment}. | 401 | The language allows \Index{multiple assignment}. |
392 | Therefore, the syntax defines a list of variables on the left side, | 402 | Therefore, the syntax for assignment |
403 | defines a list of variables on the left side, | ||
393 | and a list of expressions on the right side. | 404 | and a list of expressions on the right side. |
394 | Both lists have their elements separated by commas: | 405 | Both lists have their elements separated by commas: |
395 | \begin{Produc} | 406 | \begin{Produc} |
@@ -403,6 +414,7 @@ Therefore, it can be used to exchange two values, as in | |||
403 | \begin{verbatim} | 414 | \begin{verbatim} |
404 | x, y = y, x | 415 | x, y = y, x |
405 | \end{verbatim} | 416 | \end{verbatim} |
417 | The two lists may have different lengths. | ||
406 | Before the assignment, the list of values is {\em adjusted\/} to | 418 | Before the assignment, the list of values is {\em adjusted\/} to |
407 | the length of the list of variables \see{adjust}. | 419 | the length of the list of variables \see{adjust}. |
408 | 420 | ||
@@ -422,10 +434,12 @@ The meaning of assignments and evaluations of global variables and | |||
422 | indexed variables can be changed by tag methods \see{tag-method}. | 434 | indexed variables can be changed by tag methods \see{tag-method}. |
423 | Actually, | 435 | Actually, |
424 | an assignment \verb|x = val|, where \verb|x| is a global variable, | 436 | an assignment \verb|x = val|, where \verb|x| is a global variable, |
425 | is equivalent to a call \verb|setglobal('x', val)|, | 437 | is equivalent to a call \verb|setglobal('x', val)|; |
426 | and an assignment \verb|t[i] = val| is equivalent to | 438 | an assignment \verb|t[i] = val| is equivalent to |
427 | \verb|settable(t, i, val)|. | 439 | \verb|settable_event(t, i, val)|. |
428 | See \See{tag-method} for a description of these ``functions''. | 440 | See \See{tag-method} for a description of these functions% |
441 | \footnote{Function \verb|setglobal| is pre-defined in Lua. | ||
442 | Function {\tt settable\_event} is used only for explanation purposes.}. | ||
429 | 443 | ||
430 | The syntax \verb|var.NAME| is just syntactic sugar for | 444 | The syntax \verb|var.NAME| is just syntactic sugar for |
431 | \verb|var["NAME"]|: | 445 | \verb|var["NAME"]|: |
@@ -498,27 +512,27 @@ Variables are explained in Section~\ref{assignment}. | |||
498 | An access to a global variable \verb|x| is equivalent to a | 512 | An access to a global variable \verb|x| is equivalent to a |
499 | call \verb|getglobal('x')|; | 513 | call \verb|getglobal('x')|; |
500 | an access to an indexed variable \verb|t[i]| is equivalent to | 514 | an access to an indexed variable \verb|t[i]| is equivalent to |
501 | a call \verb|gettable(t, i)|. | 515 | a call \verb|gettable_event(t, i)|. |
502 | See \See{tag-method} for a description of these ``functions''. | 516 | See \See{tag-method} for a description of these functions% |
517 | \footnote{Function \verb|getglobal| is pre-defined in Lua. | ||
518 | Function {\tt gettable\_event} is used only for explanation purposes.}. | ||
503 | 519 | ||
504 | The non-terminal \verb|exp1| is used to indicate that the values | 520 | The non-terminal \M{exp1} is used to indicate that the values |
505 | returned by an expression must be adjusted to one single value: | 521 | returned by an expression must be adjusted to one single value: |
506 | \begin{Produc} | 522 | \begin{Produc} |
507 | \produc{exp1}{exp} | 523 | \produc{exp1}{exp} |
508 | \end{Produc} | 524 | \end{Produc} |
509 | 525 | ||
510 | \subsubsection{Arithmetic Operators} | 526 | \subsubsection{Arithmetic Operators} |
511 | Lua supports the usual \Index{arithmetic operators}. | 527 | Lua supports the usual \Index{arithmetic operators}: |
512 | These operators are the binary | 528 | the binary \verb|+| (addition), |
513 | \verb|+| (addition), | 529 | \verb|-| (subtraction), \verb|*| (multiplication), |
514 | \verb|-| (subtraction), | ||
515 | \verb|*| (multiplication), | ||
516 | \verb|/| (division) and \verb|^| (exponentiation), | 530 | \verb|/| (division) and \verb|^| (exponentiation), |
517 | and the unary \verb|-| (negation). | 531 | and unary \verb|-| (negation). |
518 | If the operands are numbers, or strings that can be converted to | 532 | If the operands are numbers, or strings that can be converted to |
519 | numbers, according to the rules given in Section~\ref{coercion}, | 533 | numbers, according to the rules given in Section~\ref{coercion}, |
520 | then all operations except exponentiation have the usual meaning. | 534 | then all operations except exponentiation have the usual meaning. |
521 | Otherwise, a tag method is called \see{tag-method}. | 535 | Otherwise, an appropriate tag method is called \see{tag-method}. |
522 | An exponentiation always calls a tag method. | 536 | An exponentiation always calls a tag method. |
523 | The standard mathematical library redefines this method for numbers, | 537 | The standard mathematical library redefines this method for numbers, |
524 | giving the expected meaning to \Index{exponentiation} | 538 | giving the expected meaning to \Index{exponentiation} |
@@ -535,7 +549,7 @@ Equality first compares the types of its operands. | |||
535 | If they are different, then the result is \nil. | 549 | If they are different, then the result is \nil. |
536 | Otherwise, their values are compared. | 550 | Otherwise, their values are compared. |
537 | Numbers and strings are compared in the usual way. | 551 | Numbers and strings are compared in the usual way. |
538 | Tables, userdatas and functions are compared by reference, | 552 | Tables, userdata and functions are compared by reference, |
539 | that is, two tables are considered equal only if they are the same table. | 553 | that is, two tables are considered equal only if they are the same table. |
540 | The operator \verb|~=| is exactly the negation of equality (\verb|==|). | 554 | The operator \verb|~=| is exactly the negation of equality (\verb|==|). |
541 | Note that the conversion rules of Section~\ref{coercion} | 555 | Note that the conversion rules of Section~\ref{coercion} |
@@ -560,10 +574,10 @@ The \Index{logical operators} are: | |||
560 | and or not | 574 | and or not |
561 | \end{verbatim} | 575 | \end{verbatim} |
562 | The operator \verb|and| returns \nil\ if its first argument is \nil; | 576 | The operator \verb|and| returns \nil\ if its first argument is \nil; |
563 | otherwise it returns its second argument. | 577 | otherwise, it returns its second argument. |
564 | The operator \verb|or| returns its first argument | 578 | The operator \verb|or| returns its first argument |
565 | if it is different from \nil; | 579 | if it is different from \nil; |
566 | otherwise it returns its second argument. | 580 | otherwise, it returns its second argument. |
567 | Both \verb|and| and \verb|or| use \Index{short-cut evaluation}, | 581 | Both \verb|and| and \verb|or| use \Index{short-cut evaluation}, |
568 | that is, | 582 | that is, |
569 | the second operand is evaluated only when necessary. | 583 | the second operand is evaluated only when necessary. |
@@ -573,7 +587,7 @@ Lua offers a string \Index{concatenation} operator, | |||
573 | denoted by ``\IndexVerb{..}''. | 587 | denoted by ``\IndexVerb{..}''. |
574 | If operands are strings or numbers, then they are converted to | 588 | If operands are strings or numbers, then they are converted to |
575 | strings according to the rules in Section~\ref{coercion}. | 589 | strings according to the rules in Section~\ref{coercion}. |
576 | Otherwise, the tag method ``concat'' is called \see{tag-method}. | 590 | Otherwise, the ``concat'' tag method is called \see{tag-method}. |
577 | 591 | ||
578 | \subsubsection{Precedence} | 592 | \subsubsection{Precedence} |
579 | \Index{Operator precedence} follows the table below, | 593 | \Index{Operator precedence} follows the table below, |
@@ -615,7 +629,7 @@ For example: | |||
615 | \begin{verbatim} | 629 | \begin{verbatim} |
616 | a = {"v1", "v2", 34} | 630 | a = {"v1", "v2", 34} |
617 | \end{verbatim} | 631 | \end{verbatim} |
618 | is essentialy equivalent to: | 632 | is essentially equivalent to: |
619 | \begin{verbatim} | 633 | \begin{verbatim} |
620 | temp = {} | 634 | temp = {} |
621 | temp[1] = "v1" | 635 | temp[1] = "v1" |
@@ -633,7 +647,7 @@ For example: | |||
633 | \begin{verbatim} | 647 | \begin{verbatim} |
634 | a = {[f(k)] = g(y), x = 1, y = 3, [0] = b+c} | 648 | a = {[f(k)] = g(y), x = 1, y = 3, [0] = b+c} |
635 | \end{verbatim} | 649 | \end{verbatim} |
636 | is essentialy equivalent to: | 650 | is essentially equivalent to: |
637 | \begin{verbatim} | 651 | \begin{verbatim} |
638 | temp = {} | 652 | temp = {} |
639 | temp[f(k)] = g(y) | 653 | temp[f(k)] = g(y) |
@@ -642,22 +656,19 @@ is essentialy equivalent to: | |||
642 | temp[0] = b+c | 656 | temp[0] = b+c |
643 | a = temp | 657 | a = temp |
644 | \end{verbatim} | 658 | \end{verbatim} |
645 | Notice that an expression like \verb|{x = 1, y = 4}| is | 659 | An expression like \verb|{x = 1, y = 4}| is |
646 | in fact a syntactic sugar for | 660 | in fact syntactic sugar for \verb|{["x"] = 1, ["y"] = 4}|. |
647 | \begin{verbatim} | ||
648 | {["x"] = 1, ["y"] = 4} | ||
649 | \end{verbatim} | ||
650 | 661 | ||
651 | \subsubsection{Function Calls} \label{functioncall} | 662 | \subsubsection{Function Calls} \label{functioncall} |
652 | A \Index{function call} has the following syntax: | 663 | A \Index{function call} has the following syntax: |
653 | \begin{Produc} | 664 | \begin{Produc} |
654 | \produc{functioncall}{var realParams} | 665 | \produc{functioncall}{var realParams} |
655 | \end{Produc}% | 666 | \end{Produc}% |
656 | Here, \verb|var| can be any variable (global, local, indexed, etc). | 667 | Here, \M{var} can be any variable (global, local, indexed, etc). |
657 | If its value has type {\em function\/}, | 668 | If its value has type {\em function\/}, |
658 | then this function is called. | 669 | then this function is called. |
659 | Otherwise, the ``function'' tag method is called, | 670 | Otherwise, the ``function'' tag method is called, |
660 | having as first parameter the value of \verb|var|, | 671 | having as first parameter the value of \M{var}, |
661 | and then the original call parameters. | 672 | and then the original call parameters. |
662 | 673 | ||
663 | The form: | 674 | The form: |
@@ -686,18 +697,18 @@ Because a function can return any number of results | |||
686 | \see{return}, | 697 | \see{return}, |
687 | the number of results must be adjusted before used. | 698 | the number of results must be adjusted before used. |
688 | If the function is called as a statement \see{funcstat}, | 699 | If the function is called as a statement \see{funcstat}, |
689 | its return list is adjusted to 0, | 700 | then its return list is adjusted to~0, |
690 | thus discarding all returned values. | 701 | thus discarding all returned values. |
691 | If the function is called in a place that needs a single value | 702 | If the function is called in a place that needs a single value |
692 | (syntactically denoted by the non-terminal \verb|exp1|), | 703 | (syntactically denoted by the non-terminal \M{exp1}), |
693 | then its return list is adjusted to 1, | 704 | then its return list is adjusted to~1, |
694 | thus discarding all returned values but the first one. | 705 | thus discarding all returned values but the first one. |
695 | If the function is called in a place that can hold many values | 706 | If the function is called in a place that can hold many values |
696 | (syntactically denoted by the non-terminal \verb|exp|), | 707 | (syntactically denoted by the non-terminal \M{exp}), |
697 | then no adjustment is made. | 708 | then no adjustment is made. |
698 | 709 | ||
699 | 710 | ||
700 | \subsection{\Index{Function Definitions}} | 711 | \subsection{\Index{Function Definitions}} \label{func-def} |
701 | 712 | ||
702 | Functions in Lua can be defined anywhere in the global level of a chunk. | 713 | Functions in Lua can be defined anywhere in the global level of a chunk. |
703 | The syntax for function definition is: | 714 | The syntax for function definition is: |
@@ -731,7 +742,7 @@ instead, it collects any extra arguments in an implicit parameter, | |||
731 | called \Def{arg}. | 742 | called \Def{arg}. |
732 | This parameter is always initialized as a table, | 743 | This parameter is always initialized as a table, |
733 | with a field \verb|n| with the number of extra arguments, | 744 | with a field \verb|n| with the number of extra arguments, |
734 | and the extra arguments at positions 1, 2, \ldots. | 745 | and the extra arguments at positions 1, 2, \ldots |
735 | 746 | ||
736 | As an example, suppose definitions like: | 747 | As an example, suppose definitions like: |
737 | \begin{verbatim} | 748 | \begin{verbatim} |
@@ -783,14 +794,14 @@ previously initialized with a table value. | |||
783 | 794 | ||
784 | Lua provides a powerful mechanism to extend its semantics, | 795 | Lua provides a powerful mechanism to extend its semantics, |
785 | called \Def{Tag Methods}. | 796 | called \Def{Tag Methods}. |
786 | A tag method (TM) is a programmer defined function | 797 | A tag method (TM) is a programmer-defined function |
787 | that can be called in many key points of the evaluation of a program, | 798 | that can be called at many key points of the evaluation of a program, |
788 | allowing a programmer to change the standard Lua behavior at these points. | 799 | allowing a programmer to change the standard Lua behavior at these points. |
789 | Each of these points is called an \Def{event}. | 800 | Each of these points is called an \Def{event}. |
790 | 801 | ||
791 | The tag method called for any specific event is selected | 802 | The tag method called for any specific event is selected |
792 | accordingly with the tag~\see{TypesSec} of the values involved | 803 | according to the tag of the values involved |
793 | in the event. | 804 | in the event \see{TypesSec}. |
794 | The function \IndexVerb{settagmethod} changes the tag method | 805 | The function \IndexVerb{settagmethod} changes the tag method |
795 | associated with a given pair $<tag, event>$. | 806 | associated with a given pair $<tag, event>$. |
796 | Its first parameter is the tag, the second the event name | 807 | Its first parameter is the tag, the second the event name |
@@ -810,7 +821,7 @@ The function not only shows when a tag method is called, | |||
810 | but also its arguments, its results and the default behavior. | 821 | but also its arguments, its results and the default behavior. |
811 | Please notice that the code shown here is only illustrative; | 822 | Please notice that the code shown here is only illustrative; |
812 | the real behavior is hard coded in the interpreter, | 823 | the real behavior is hard coded in the interpreter, |
813 | and it is much more eficient than this simulation. | 824 | and it is much more efficient than this simulation. |
814 | All functions used in these descriptions | 825 | All functions used in these descriptions |
815 | (\verb|rawgetglobal|, \verb|tonumber|, \verb|call|, etc) | 826 | (\verb|rawgetglobal|, \verb|tonumber|, \verb|call|, etc) |
816 | are described in \See{predefined}. | 827 | are described in \See{predefined}. |
@@ -822,10 +833,10 @@ called when a \verb|+| operation is applied to non numerical operands. | |||
822 | 833 | ||
823 | The function \verb|getbinmethod| defines how Lua chooses a tag method | 834 | The function \verb|getbinmethod| defines how Lua chooses a tag method |
824 | for a binary operation. | 835 | for a binary operation. |
825 | First Lua trys the first operand. | 836 | First Lua tries the first operand. |
826 | If its tag does not define a tag method for the operation, | 837 | If its tag does not define a tag method for the operation, |
827 | Lua trys the second operand. | 838 | then Lua tries the second operand. |
828 | If it also fails, it gets a tag method from tag 0: | 839 | If it also fails, then it gets a tag method from tag~0: |
829 | \begin{verbatim} | 840 | \begin{verbatim} |
830 | function getbinmethod (op1, op2, event) | 841 | function getbinmethod (op1, op2, event) |
831 | return gettagmethod(tag(op1), event) or | 842 | return gettagmethod(tag(op1), event) or |
@@ -853,18 +864,18 @@ If it also fails, it gets a tag method from tag 0: | |||
853 | 864 | ||
854 | \item[``sub'':]\index{sub event} | 865 | \item[``sub'':]\index{sub event} |
855 | called when a \verb|-| operation is applied to non numerical operands. | 866 | called when a \verb|-| operation is applied to non numerical operands. |
856 | Behavior is similar to \verb|"add"| event. | 867 | Behavior similar to \verb|"add"| event. |
857 | 868 | ||
858 | \item[``mul'':]\index{mul event} | 869 | \item[``mul'':]\index{mul event} |
859 | called when a \verb|*| operation is applied to non numerical operands. | 870 | called when a \verb|*| operation is applied to non numerical operands. |
860 | Behavior is similar to \verb|"add"| event. | 871 | Behavior similar to \verb|"add"| event. |
861 | 872 | ||
862 | \item[``div'':]\index{div event} | 873 | \item[``div'':]\index{div event} |
863 | called when a \verb|/| operation is applied to non numerical operands. | 874 | called when a \verb|/| operation is applied to non numerical operands. |
864 | Behavior is similar to \verb|"add"| event. | 875 | Behavior similar to \verb|"add"| event. |
865 | 876 | ||
866 | \item[``pow'':]\index{pow event} | 877 | \item[``pow'':]\index{pow event} |
867 | called whenenver a \verb|^| operation is applied. | 878 | called when a \verb|^| operation is applied. |
868 | \begin{verbatim} | 879 | \begin{verbatim} |
869 | function pow_event (op1, op2) | 880 | function pow_event (op1, op2) |
870 | local tm = getbinmethod(op1, op2, "pow") | 881 | local tm = getbinmethod(op1, op2, "pow") |
@@ -924,17 +935,17 @@ or non string operands. | |||
924 | \item[``gt'':]\index{gt event} | 935 | \item[``gt'':]\index{gt event} |
925 | called when a \verb|>| operation is applied to non numerical | 936 | called when a \verb|>| operation is applied to non numerical |
926 | or non string operands. | 937 | or non string operands. |
927 | Behavior is similar to \verb|"lt"| event. | 938 | Behavior similar to \verb|"lt"| event. |
928 | 939 | ||
929 | \item[``le'':]\index{le event} | 940 | \item[``le'':]\index{le event} |
930 | called when a \verb|<=| operation is applied to non numerical | 941 | called when a \verb|<=| operation is applied to non numerical |
931 | or non string operands. | 942 | or non string operands. |
932 | Behavior is similar to \verb|"lt"| event. | 943 | Behavior similar to \verb|"lt"| event. |
933 | 944 | ||
934 | \item[``ge'':]\index{ge event} | 945 | \item[``ge'':]\index{ge event} |
935 | called when a \verb|>=| operation is applied to non numerical | 946 | called when a \verb|>=| operation is applied to non numerical |
936 | or non string operands. | 947 | or non string operands. |
937 | Behavior is similar to \verb|"lt"| event. | 948 | Behavior similar to \verb|"lt"| event. |
938 | 949 | ||
939 | \item[``concat'':]\index{concatenation event} | 950 | \item[``concat'':]\index{concatenation event} |
940 | called when a concatenation is applied to non string operands. | 951 | called when a concatenation is applied to non string operands. |
@@ -1011,8 +1022,7 @@ called whenever Lua accesses an indexed variable. | |||
1011 | \end{verbatim} | 1022 | \end{verbatim} |
1012 | 1023 | ||
1013 | \item[``settable'':]\index{settable event} | 1024 | \item[``settable'':]\index{settable event} |
1014 | called whenever Lua assigns to an indexed variable. | 1025 | called when Lua assigns to an indexed variable. |
1015 | in a table. | ||
1016 | \begin{verbatim} | 1026 | \begin{verbatim} |
1017 | function settable_event (table, index, value) | 1027 | function settable_event (table, index, value) |
1018 | local tm = gettagmethod(tag(table), "settable") | 1028 | local tm = gettagmethod(tag(table), "settable") |
@@ -1062,8 +1072,8 @@ Lua does the equivalent of the following function: | |||
1062 | end | 1072 | end |
1063 | end | 1073 | end |
1064 | \end{verbatim} | 1074 | \end{verbatim} |
1065 | Moreover, at the end of a garbage collection cicle, | 1075 | Moreover, at the end of a garbage collection cycle, |
1066 | Lua does the equivalent to the call \verb|gc_event(nil)|. | 1076 | Lua does the equivalent of the call \verb|gc_event(nil)|. |
1067 | 1077 | ||
1068 | \end{description} | 1078 | \end{description} |
1069 | 1079 | ||
@@ -1086,14 +1096,15 @@ using the debug facilities \see{debugI}, | |||
1086 | in order to print some extra information, | 1096 | in order to print some extra information, |
1087 | like the call stack. | 1097 | like the call stack. |
1088 | To provide more information about errors, | 1098 | To provide more information about errors, |
1089 | Lua programs can include the compilation pragma \verb|$debug|. | 1099 | Lua programs should include the compilation pragma \verb|$debug|. |
1090 | \index{debug pragma}\label{pragma} | 1100 | \index{debug pragma}\label{pragma} |
1091 | When an error occurs in a program compiled with this option, | 1101 | When an error occurs in a program compiled with this option, |
1092 | the error routine is able to print the number of the lines where the calls | 1102 | the error routine is able to print the number of the lines where the calls |
1093 | (and the error) were made. | 1103 | (and the error) were made. |
1094 | If needed, it is possible to change the error method with the | 1104 | If needed, it is possible to change the error method with the |
1095 | function \verb|seterrormethod|, | 1105 | function \verb|seterrormethod|, |
1096 | which gets the new error handler as its only parameter. | 1106 | which gets the new error handler as its only parameter |
1107 | \see{pdf-seterrormethod}. | ||
1097 | 1108 | ||
1098 | Lua code can explicitly generate an error by calling the built-in | 1109 | Lua code can explicitly generate an error by calling the built-in |
1099 | function \verb|error| \see{pdf-error}. | 1110 | function \verb|error| \see{pdf-error}. |
@@ -1103,7 +1114,7 @@ function \verb|error| \see{pdf-error}. | |||
1103 | 1114 | ||
1104 | This section describes the API for Lua, that is, | 1115 | This section describes the API for Lua, that is, |
1105 | the set of C functions available to the host program to communicate | 1116 | the set of C functions available to the host program to communicate |
1106 | with the library. | 1117 | with the Lua library. |
1107 | The API functions can be classified in the following categories: | 1118 | The API functions can be classified in the following categories: |
1108 | \begin{enumerate} | 1119 | \begin{enumerate} |
1109 | \item exchanging values between C and Lua; | 1120 | \item exchanging values between C and Lua; |
@@ -1123,7 +1134,7 @@ all values passed between Lua and C have type | |||
1123 | which works like an abstract type in C that can hold any Lua value. | 1134 | which works like an abstract type in C that can hold any Lua value. |
1124 | Values of type \verb|lua_Object| have no meaning outside Lua; | 1135 | Values of type \verb|lua_Object| have no meaning outside Lua; |
1125 | for instance, | 1136 | for instance, |
1126 | the comparisson of two \verb|lua_Object's| is undefined. | 1137 | the comparison of two \verb|lua_Object's| is undefined. |
1127 | 1138 | ||
1128 | To check the type of a \verb|lua_Object|, | 1139 | To check the type of a \verb|lua_Object|, |
1129 | the following functions are available: | 1140 | the following functions are available: |
@@ -1163,17 +1174,19 @@ char *lua_getstring (lua_Object object); | |||
1163 | lua_CFunction lua_getcfunction (lua_Object object); | 1174 | lua_CFunction lua_getcfunction (lua_Object object); |
1164 | void *lua_getuserdata (lua_Object object); | 1175 | void *lua_getuserdata (lua_Object object); |
1165 | \end{verbatim} | 1176 | \end{verbatim} |
1177 | |||
1166 | \verb|lua_getnumber| converts a \verb|lua_Object| to a floating-point number. | 1178 | \verb|lua_getnumber| converts a \verb|lua_Object| to a floating-point number. |
1167 | This \verb|lua_Object| must be a number or a string convertible to number | 1179 | This \verb|lua_Object| must be a number or a string convertible to number |
1168 | \see{coercion}; otherwise, the function returns 0. | 1180 | \see{coercion}; otherwise, the function returns~0. |
1169 | 1181 | ||
1170 | \verb|lua_getstring| converts a \verb|lua_Object| to a string (\verb|char *|). | 1182 | \verb|lua_getstring| converts a \verb|lua_Object| to a string (\verb|char*|). |
1171 | This \verb|lua_Object| must be a string or a number; | 1183 | This \verb|lua_Object| must be a string or a number; |
1172 | otherwise, the function returns 0 (the \verb|NULL| pointer). | 1184 | otherwise, the function returns~0 (the \verb|NULL| pointer). |
1173 | This function does not create a new string, | 1185 | This function does not create a new string, |
1174 | but returns a pointer to a string inside the Lua environment. | 1186 | but returns a pointer to a string inside the Lua environment. |
1175 | Because Lua has garbage collection, | 1187 | Because Lua has garbage collection, |
1176 | there is no guarantee that such pointer will be valid after the block ends. | 1188 | there is no guarantee that such pointer will be valid after the block ends |
1189 | (see below). | ||
1177 | 1190 | ||
1178 | \verb|lua_getcfunction| converts a \verb|lua_Object| to a C function. | 1191 | \verb|lua_getcfunction| converts a \verb|lua_Object| to a C function. |
1179 | This \verb|lua_Object| must have type {\em CFunction\/}; | 1192 | This \verb|lua_Object| must have type {\em CFunction\/}; |
@@ -1193,18 +1206,18 @@ It is good programming practice to convert Lua objects to C values | |||
1193 | as soon as they are available, | 1206 | as soon as they are available, |
1194 | and never to store \verb|lua_Object|s in C global variables. | 1207 | and never to store \verb|lua_Object|s in C global variables. |
1195 | 1208 | ||
1196 | A garbage collection cicle can be forced by: | 1209 | A garbage collection cycle can be forced by: |
1197 | \Deffunc{lua_collectgarbage} | 1210 | \Deffunc{lua_collectgarbage} |
1198 | \begin{verbatim} | 1211 | \begin{verbatim} |
1199 | long lua_collectgarbage (long limit); | 1212 | long lua_collectgarbage (long limit); |
1200 | \end{verbatim} | 1213 | \end{verbatim} |
1201 | This function returns the number of objects collected. | 1214 | This function returns the number of objects collected. |
1202 | The argument \verb|limit| makes the next cicle occur when that number | 1215 | The argument \verb|limit| makes the next cycle occur only |
1203 | of new objects have been created. | 1216 | when that number of new objects have been created. |
1204 | If \verb|limit|=0, Lua uses an adaptative algorithm to set this limit. | 1217 | If \verb|limit|=0, then Lua uses an adaptable heuristics to set this limit. |
1205 | 1218 | ||
1206 | 1219 | ||
1207 | All comunication between Lua and C is done through two | 1220 | All communication between Lua and C is done through two |
1208 | abstract data types, called \Def{lua2C} and \Def{C2lua}. | 1221 | abstract data types, called \Def{lua2C} and \Def{C2lua}. |
1209 | The first one, as the name implies, is used to pass values | 1222 | The first one, as the name implies, is used to pass values |
1210 | from Lua to C: parameters when Lua calls C and results when C calls Lua. | 1223 | from Lua to C: parameters when Lua calls C and results when C calls Lua. |
@@ -1227,7 +1240,7 @@ Notice that the structure lua2C cannot be directly modified by C code. | |||
1227 | 1240 | ||
1228 | The second structure, C2lua, is a stack. | 1241 | The second structure, C2lua, is a stack. |
1229 | Pushing elements into this stack | 1242 | Pushing elements into this stack |
1230 | is done by using the following functions: | 1243 | is done with the following functions: |
1231 | \Deffunc{lua_pushnumber}\Deffunc{lua_pushstring} | 1244 | \Deffunc{lua_pushnumber}\Deffunc{lua_pushstring} |
1232 | \Deffunc{lua_pushcfunction}\Deffunc{lua_pushusertag} | 1245 | \Deffunc{lua_pushcfunction}\Deffunc{lua_pushusertag} |
1233 | \Deffunc{lua_pushnil}\Deffunc{lua_pushobject} | 1246 | \Deffunc{lua_pushnil}\Deffunc{lua_pushobject} |
@@ -1256,17 +1269,17 @@ all elements that they use. | |||
1256 | 1269 | ||
1257 | Because userdata are objects, | 1270 | Because userdata are objects, |
1258 | the function \verb|lua_pushusertag| may create a new userdata. | 1271 | the function \verb|lua_pushusertag| may create a new userdata. |
1259 | If Lua has a userdata with the given value (\verb|void *|) and tag, | 1272 | If Lua has a userdata with the given value (\verb|void*|) and tag, |
1260 | that userdata is pushed. | 1273 | that userdata is pushed. |
1261 | Otherwise, a new userdata is created, with the given value and tag. | 1274 | Otherwise, a new userdata is created, with the given value and tag. |
1262 | If this function is called with | 1275 | If this function is called with |
1263 | \verb|tag|=\verb|LUA_ANYTAG|\Deffunc{LUA_ANYTAG}, | 1276 | \verb|tag|=\verb|LUA_ANYTAG|\Deffunc{LUA_ANYTAG}, |
1264 | then Lua will try to find any userdata with the given value, | 1277 | then Lua will try to find any userdata with the given value, |
1265 | no matter its tag. | 1278 | no matter its tag. |
1266 | If there is no userdata with that value, a new one is created, | 1279 | If there is no userdata with that value, then a new one is created, |
1267 | with tag=0. | 1280 | with tag=0. |
1268 | 1281 | ||
1269 | User data can have different tags, | 1282 | Userdata can have different tags, |
1270 | whose semantics are only known to the host program. | 1283 | whose semantics are only known to the host program. |
1271 | Tags are created with the function: | 1284 | Tags are created with the function: |
1272 | \Deffunc{lua_newtag} | 1285 | \Deffunc{lua_newtag} |
@@ -1283,8 +1296,8 @@ void lua_settag (int tag); | |||
1283 | \verb|tag| must be a value created with \verb|lua_newtag|. | 1296 | \verb|tag| must be a value created with \verb|lua_newtag|. |
1284 | 1297 | ||
1285 | When C code calls Lua repeatedly, as in a loop, | 1298 | When C code calls Lua repeatedly, as in a loop, |
1286 | objects returned by these calls accumulate, | 1299 | objects returned by these calls can accumulate, |
1287 | and may create a memory problem. | 1300 | and may cause a stack overflow. |
1288 | To avoid this, | 1301 | To avoid this, |
1289 | nested blocks can be defined with the functions: | 1302 | nested blocks can be defined with the functions: |
1290 | \begin{verbatim} | 1303 | \begin{verbatim} |
@@ -1297,7 +1310,7 @@ The use of explicit nested blocks is strongly encouraged. | |||
1297 | 1310 | ||
1298 | \subsection{Executing Lua Code} | 1311 | \subsection{Executing Lua Code} |
1299 | A host program can execute Lua chunks written in a file or in a string | 1312 | A host program can execute Lua chunks written in a file or in a string |
1300 | using the following functions: | 1313 | using the following functions:% |
1301 | \Deffunc{lua_dofile}\Deffunc{lua_dostring} | 1314 | \Deffunc{lua_dofile}\Deffunc{lua_dostring} |
1302 | \begin{verbatim} | 1315 | \begin{verbatim} |
1303 | int lua_dofile (char *filename); | 1316 | int lua_dofile (char *filename); |
@@ -1325,7 +1338,7 @@ one uses the function: | |||
1325 | \begin{verbatim} | 1338 | \begin{verbatim} |
1326 | lua_Object lua_getglobal (char *varname); | 1339 | lua_Object lua_getglobal (char *varname); |
1327 | \end{verbatim} | 1340 | \end{verbatim} |
1328 | As in Lua, this function may call a tag method. | 1341 | As in Lua, this function may trigger a tag method. |
1329 | To read the real value of any global variable, | 1342 | To read the real value of any global variable, |
1330 | without invoking any tag method, | 1343 | without invoking any tag method, |
1331 | this function has a {\em raw\/} version: | 1344 | this function has a {\em raw\/} version: |
@@ -1336,11 +1349,11 @@ lua_Object lua_rawgetglobal (char *varname); | |||
1336 | 1349 | ||
1337 | To store a value previously pushed onto C2lua in a global variable, | 1350 | To store a value previously pushed onto C2lua in a global variable, |
1338 | there is the function: | 1351 | there is the function: |
1339 | \Deffunc{lua_storeglobal} | 1352 | \Deffunc{lua_setglobal} |
1340 | \begin{verbatim} | 1353 | \begin{verbatim} |
1341 | void lua_setglobal (char *varname); | 1354 | void lua_setglobal (char *varname); |
1342 | \end{verbatim} | 1355 | \end{verbatim} |
1343 | As in Lua, this function may call a tag method. | 1356 | As in Lua, this function may trigger a tag method. |
1344 | To set the real value of any global variable, | 1357 | To set the real value of any global variable, |
1345 | without invoking any tag method, | 1358 | without invoking any tag method, |
1346 | this function has a {\em raw\/} version: | 1359 | this function has a {\em raw\/} version: |
@@ -1357,7 +1370,7 @@ lua_Object lua_gettable (void); | |||
1357 | \end{verbatim} | 1370 | \end{verbatim} |
1358 | pops from the stack C2lua a table and an index, | 1371 | pops from the stack C2lua a table and an index, |
1359 | and returns the contents of the table at that index. | 1372 | and returns the contents of the table at that index. |
1360 | As in Lua, this operation may call a tag method. | 1373 | As in Lua, this operation may trigger a tag method. |
1361 | To get the real value of any table index, | 1374 | To get the real value of any table index, |
1362 | without invoking any tag method, | 1375 | without invoking any tag method, |
1363 | this function has a {\em raw\/} version: | 1376 | this function has a {\em raw\/} version: |
@@ -1419,13 +1432,13 @@ equivalent to the Lua code: | |||
1419 | a = f(t.x, 4) | 1432 | a = f(t.x, 4) |
1420 | \end{verbatim} | 1433 | \end{verbatim} |
1421 | \begin{verbatim} | 1434 | \begin{verbatim} |
1422 | lua_pushobject(lua_getglobal("t")); /* push value of global 't' */ | 1435 | lua_pushobject(lua_getglobal("t")); /* push value of global 't' */ |
1423 | lua_pushstring("x"); /* push the string 'x' */ | 1436 | lua_pushstring("x"); /* push the string 'x' */ |
1424 | lua_pushobject(lua_gettable()); /* push result of t.x (= t['x']) */ | 1437 | lua_pushobject(lua_gettable()); /* push result of t.x (= t['x']) */ |
1425 | lua_pushnumber(4); /* 2nd argument */ | 1438 | lua_pushnumber(4); /* 2nd argument */ |
1426 | lua_callfunction(lua_getglobal("f")); /* call Lua function */ | 1439 | lua_callfunction(lua_getglobal("f")); /* call Lua function */ |
1427 | lua_pushobject(lua_getresult(1)); /* push first result of the call */ | 1440 | lua_pushobject(lua_getresult(1)); /* push first result of the call */ |
1428 | lua_setglobal("a"); /* sets global variable 'a' */ | 1441 | lua_setglobal("a"); /* sets global variable 'a' */ |
1429 | \end{verbatim} | 1442 | \end{verbatim} |
1430 | 1443 | ||
1431 | Some special Lua functions have exclusive interfaces. | 1444 | Some special Lua functions have exclusive interfaces. |
@@ -1458,7 +1471,7 @@ the second is the event name \see{tag-method}, | |||
1458 | and the third is a CFunction to be used as the new method. | 1471 | and the third is a CFunction to be used as the new method. |
1459 | This function returns a \verb|lua_Object|, | 1472 | This function returns a \verb|lua_Object|, |
1460 | which is the old tag method value. | 1473 | which is the old tag method value. |
1461 | To only get the current value of a tag method, | 1474 | To get just the current value of a tag method, |
1462 | there is the function | 1475 | there is the function |
1463 | \Deffunc{lua_gettagmethod} | 1476 | \Deffunc{lua_gettagmethod} |
1464 | \begin{verbatim} | 1477 | \begin{verbatim} |
@@ -1471,7 +1484,7 @@ To register a C function to Lua, | |||
1471 | there is the following macro: | 1484 | there is the following macro: |
1472 | \Deffunc{lua_register} | 1485 | \Deffunc{lua_register} |
1473 | \begin{verbatim} | 1486 | \begin{verbatim} |
1474 | #define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n)) | 1487 | #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n)) |
1475 | /* char *n; */ | 1488 | /* char *n; */ |
1476 | /* lua_CFunction f; */ | 1489 | /* lua_CFunction f; */ |
1477 | \end{verbatim} | 1490 | \end{verbatim} |
@@ -1505,7 +1518,7 @@ For some examples, see files \verb|strlib.c|, | |||
1505 | As noted in Section~\ref{LuacallC}, \verb|lua_Object|s are volatile. | 1518 | As noted in Section~\ref{LuacallC}, \verb|lua_Object|s are volatile. |
1506 | If the C code needs to keep a \verb|lua_Object| | 1519 | If the C code needs to keep a \verb|lua_Object| |
1507 | outside block boundaries, | 1520 | outside block boundaries, |
1508 | it must create a \Def{reference} to the object. | 1521 | then it must create a \Def{reference} to the object. |
1509 | The routines to manipulate references are the following: | 1522 | The routines to manipulate references are the following: |
1510 | \Deffunc{lua_ref}\Deffunc{lua_getref} | 1523 | \Deffunc{lua_ref}\Deffunc{lua_getref} |
1511 | \Deffunc{lua_unref} | 1524 | \Deffunc{lua_unref} |
@@ -1537,7 +1550,7 @@ The set of \Index{predefined functions} in Lua is small but powerful. | |||
1537 | Most of them provide features that allow some degree of | 1550 | Most of them provide features that allow some degree of |
1538 | \Index{reflexivity} in the language. | 1551 | \Index{reflexivity} in the language. |
1539 | Some of these features cannot be simulated with the rest of the | 1552 | Some of these features cannot be simulated with the rest of the |
1540 | Language nor with the standard Lua API. | 1553 | language nor with the standard Lua API. |
1541 | Others are just convenient interfaces to common API functions. | 1554 | Others are just convenient interfaces to common API functions. |
1542 | 1555 | ||
1543 | The libraries, on the other hand, provide useful routines | 1556 | The libraries, on the other hand, provide useful routines |
@@ -1558,7 +1571,7 @@ declared in \verb|lualib.h|. | |||
1558 | 1571 | ||
1559 | \subsection{Predefined Functions} \label{predefined} | 1572 | \subsection{Predefined Functions} \label{predefined} |
1560 | 1573 | ||
1561 | \subsection*{\ff{\tt call (func, arg, [retmode])}}\Deffunc{call} | 1574 | \subsubsection*{\ff {\tt call (func, arg, [retmode])}}\Deffunc{call} |
1562 | This function calls function \verb|func| with | 1575 | This function calls function \verb|func| with |
1563 | the arguments given by the table \verb|arg|. | 1576 | the arguments given by the table \verb|arg|. |
1564 | The call is equivalent to | 1577 | The call is equivalent to |
@@ -1566,59 +1579,61 @@ The call is equivalent to | |||
1566 | func(arg[1], arg[2], ..., arg[arg.n]) | 1579 | func(arg[1], arg[2], ..., arg[arg.n]) |
1567 | \end{verbatim} | 1580 | \end{verbatim} |
1568 | If \verb|arg.n| is not defined, | 1581 | If \verb|arg.n| is not defined, |
1569 | Lua gets the arguments from \verb|arg[1]| until the first nil value. | 1582 | then Lua stops getting arguments at the first nil value. |
1570 | 1583 | ||
1571 | If \verb|retmode| is equal to \verb|"plain"| or is absent, | 1584 | If \verb|retmode| is absent, |
1572 | all results from \verb|func| are just returned by the call. | 1585 | all results from \verb|func| are just returned by the call. |
1573 | If \verb|retmode| is equal to \verb|"pack"|, | 1586 | If \verb|retmode| is equal to \verb|"pack"|, |
1574 | the results are {\em packed\/} in a single table.\index{packed results} | 1587 | the results are {\em packed\/} in a single table.\index{packed results} |
1575 | That is, \verb|call| returns just one table. | 1588 | That is, \verb|call| returns just one table. |
1576 | At index \verb|n| the table has the total number of results | 1589 | At index \verb|n|, the table has the total number of results |
1577 | from the call; | 1590 | from the call; |
1578 | the first result is at index 1, etc. | 1591 | the first result is at index 1, etc. |
1579 | 1592 | ||
1580 | For instance, the following calls produce the following results: | 1593 | For instance, the following calls produce the following results: |
1581 | \begin{verbatim} | 1594 | \begin{verbatim} |
1582 | a = call(sin, {5}) -- a = 0.0871557 = sin(5) | 1595 | a = call(sin, {5}) --> a = 0.0871557 = sin(5) |
1583 | a = call(max, {1,4,5; n=2}) -- a = 4 (only 1 and 4 are arguments) | 1596 | a = call(max, {1,4,5; n=2}) --> a = 4 (only 1 and 4 are arguments) |
1584 | t = {x=1} | 1597 | t = {x=1} |
1585 | a = call(next, {t,nil;n=2}, "pack") -- a={"x", 1; n=2} | 1598 | a = call(next, {t,nil;n=2}, "pack") --> a={"x", 1; n=2} |
1586 | \end{verbatim} | 1599 | \end{verbatim} |
1587 | 1600 | ||
1588 | \subsection*{\ff{\tt callgc ([nextgc])}}\Deffunc{callgc} | 1601 | \subsubsection*{\ff {\tt collectgarbage ([limit])}}\Deffunc{collectgarbage} |
1589 | Forces a garbage collection cicle. | 1602 | Forces a garbage collection cycle. |
1590 | Returns the number of objects collected. | 1603 | Returns the number of objects collected. |
1591 | An optional argument, \verb|nextgc|, is a number that | 1604 | An optional argument, \verb|limit|, is a number that |
1592 | makes the next cicle occur when that number of new | 1605 | makes the next cycle occur when that number of new |
1593 | objects have been created. | 1606 | objects have been created. |
1594 | If absent, Lua uses an adaptative algorithm to set | 1607 | If absent, Lua uses an adaptable algorithm to set |
1595 | this limit. | 1608 | this limit. |
1596 | \verb|nextgc| is simply an interface to \verb|lua_collectgarbage|. | 1609 | \verb|collectgarbage| is equivalent to |
1610 | the API function \verb|lua_collectgarbage|. | ||
1597 | 1611 | ||
1598 | \subsubsection*{\ff{\tt dofile (filename)}}\Deffunc{dofile} | 1612 | \subsubsection*{\ff {\tt dofile (filename)}}\Deffunc{dofile} |
1599 | This function receives a file name, | 1613 | This function receives a file name, |
1600 | opens it, and executes its contents as a Lua chunk, | 1614 | opens it, and executes its contents as a Lua chunk, |
1601 | or as pre-compiled chunks. | 1615 | or as pre-compiled chunks. |
1602 | When called without arguments, | 1616 | When called without arguments, |
1603 | it executes the contents of the standard input (\verb|stdin|). | 1617 | it executes the contents of the standard input (\verb|stdin|). |
1604 | If there is any error executing the file, it returns \nil. | 1618 | If there is any error executing the file, |
1619 | then \verb|dofile| returns \nil. | ||
1605 | Otherwise, it returns the values returned by the chunk, | 1620 | Otherwise, it returns the values returned by the chunk, |
1606 | or a non \nil\ value if the chunk returns no values. | 1621 | or a non \nil\ value if the chunk returns no values. |
1607 | It issues an error when called with a non string argument. | 1622 | It issues an error when called with a non string argument. |
1608 | \verb|dofile| is simply an interface to \verb|lua_dofile|. | 1623 | \verb|dofile| is equivalent to the API function \verb|lua_dofile|. |
1609 | 1624 | ||
1610 | \subsubsection*{\ff{\tt dostring (string)}}\Deffunc{dostring} | 1625 | \subsubsection*{\ff {\tt dostring (string)}}\Deffunc{dostring} |
1611 | This function executes a given string as a Lua chunk. | 1626 | This function executes a given string as a Lua chunk. |
1612 | If there is any error executing the string, it returns \nil. | 1627 | If there is any error executing the string, it returns \nil. |
1613 | Otherwise, it returns the values returned by the chunk, | 1628 | Otherwise, it returns the values returned by the chunk, |
1614 | or a non \nil\ value if the chunk returns no values. | 1629 | or a non \nil\ value if the chunk returns no values. |
1615 | \verb|dostring| is simply an interface to \verb|lua_dostring|. | 1630 | \verb|dostring| is equivalent to the API function \verb|lua_dostring|. |
1616 | 1631 | ||
1617 | \subsubsection*{\ff{\tt newtag ()}}\Deffunc{newtag}\label{pdf-newtag} | 1632 | \subsubsection*{\ff {\tt newtag ()}}\Deffunc{newtag}\label{pdf-newtag} |
1618 | Returns a new tag. | 1633 | Returns a new tag. |
1619 | \verb|newtag| is simply an interface to \verb|lua_newtag|. | 1634 | \verb|newtag| is equivalent to the API function \verb|lua_newtag|. |
1620 | 1635 | ||
1621 | \subsubsection*{\ff{\tt next (table, index)}}\Deffunc{next} | 1636 | \subsubsection*{\ff {\tt next (table, index)}}\Deffunc{next} |
1622 | This function allows a program to traverse all fields of a table. | 1637 | This function allows a program to traverse all fields of a table. |
1623 | Its first argument is a table and its second argument | 1638 | Its first argument is a table and its second argument |
1624 | is an index in this table. | 1639 | is an index in this table. |
@@ -1635,13 +1650,13 @@ semantically, there is no difference between a | |||
1635 | field not present in a table or a field with value \nil. | 1650 | field not present in a table or a field with value \nil. |
1636 | Therefore, the function only considers fields with non \nil\ values. | 1651 | Therefore, the function only considers fields with non \nil\ values. |
1637 | The order in which the indices are enumerated is not specified, | 1652 | The order in which the indices are enumerated is not specified, |
1638 | {\em even for numeric indices}. | 1653 | {\em not even for numeric indices}. |
1639 | If the table is modified in any way during a traversal, | 1654 | If the table is modified in any way during a traversal, |
1640 | the semantics of \verb|next| is undefined. | 1655 | the semantics of \verb|next| is undefined. |
1641 | 1656 | ||
1642 | This function cannot be written with the standard API. | 1657 | This function cannot be written with the standard API. |
1643 | 1658 | ||
1644 | \subsubsection*{\ff{\tt nextvar (name)}}\Deffunc{nextvar} | 1659 | \subsubsection*{\ff {\tt nextvar (name)}}\Deffunc{nextvar} |
1645 | This function is similar to the function \verb|next|, | 1660 | This function is similar to the function \verb|next|, |
1646 | but iterates over the global variables. | 1661 | but iterates over the global variables. |
1647 | Its single argument is the name of a global variable, | 1662 | Its single argument is the name of a global variable, |
@@ -1654,11 +1669,11 @@ otherwise the semantics of \verb|nextvar| is undefined. | |||
1654 | 1669 | ||
1655 | This function cannot be written with the standard API. | 1670 | This function cannot be written with the standard API. |
1656 | 1671 | ||
1657 | \subsubsection*{\ff{\tt tostring (e)}}\Deffunc{tostring} | 1672 | \subsubsection*{\ff {\tt tostring (e)}}\Deffunc{tostring} |
1658 | This function receives an argument of any type and | 1673 | This function receives an argument of any type and |
1659 | converts it to a string in a reasonable format. | 1674 | converts it to a string in a reasonable format. |
1660 | 1675 | ||
1661 | \subsubsection*{\ff{\tt print (e1, e2, ...)}}\Deffunc{print} | 1676 | \subsubsection*{\ff {\tt print (e1, e2, ...)}}\Deffunc{print} |
1662 | This function receives any number of arguments, | 1677 | This function receives any number of arguments, |
1663 | and prints their values in a reasonable format. | 1678 | and prints their values in a reasonable format. |
1664 | Each value is printed in a new line. | 1679 | Each value is printed in a new line. |
@@ -1667,14 +1682,14 @@ but as a quick way to show a value, | |||
1667 | for instance for error messages or debugging. | 1682 | for instance for error messages or debugging. |
1668 | See Section~\ref{libio} for functions for formatted output. | 1683 | See Section~\ref{libio} for functions for formatted output. |
1669 | 1684 | ||
1670 | \subsubsection*{\ff{\tt tonumber (e)}}\Deffunc{tonumber} | 1685 | \subsubsection*{\ff {\tt tonumber (e)}}\Deffunc{tonumber} |
1671 | This function receives one argument, | 1686 | This function receives one argument, |
1672 | and tries to convert it to a number. | 1687 | and tries to convert it to a number. |
1673 | If the argument is already a number or a string convertible | 1688 | If the argument is already a number or a string convertible |
1674 | to a number \see{coercion}, then it returns that number; | 1689 | to a number \see{coercion}, then it returns that number; |
1675 | otherwise, it returns \nil. | 1690 | otherwise, it returns \nil. |
1676 | 1691 | ||
1677 | \subsubsection*{\ff{\tt type (v)}}\Deffunc{type} | 1692 | \subsubsection*{\ff {\tt type (v)}}\Deffunc{type}\label{pdf-type} |
1678 | This function allows Lua to test the type of a value. | 1693 | This function allows Lua to test the type of a value. |
1679 | It receives one argument, and returns its type, coded as a string. | 1694 | It receives one argument, and returns its type, coded as a string. |
1680 | The possible results of this function are | 1695 | The possible results of this function are |
@@ -1684,79 +1699,81 @@ The possible results of this function are | |||
1684 | \verb|"table"|, | 1699 | \verb|"table"|, |
1685 | \verb|"function"|, | 1700 | \verb|"function"|, |
1686 | and \verb|"userdata"|. | 1701 | and \verb|"userdata"|. |
1702 | \verb|type| is equivalent to the API function \verb|lua_type|. | ||
1687 | 1703 | ||
1688 | \verb|type| is simply an interface to \verb|lua_type|. | 1704 | \subsubsection*{\ff {\tt tag (v)}}\Deffunc{tag} |
1689 | |||
1690 | \subsubsection*{\ff{\tt tag (v)}}\Deffunc{tag} | ||
1691 | This function allows Lua to test the tag of a value \see{TypesSec}. | 1705 | This function allows Lua to test the tag of a value \see{TypesSec}. |
1692 | It receives one argument, and returns its tag (a number). | 1706 | It receives one argument, and returns its tag (a number). |
1707 | \verb|tag| is equivalent to the API function \verb|lua_tag|. | ||
1693 | 1708 | ||
1694 | \subsubsection*{\ff{\tt settag (o, tag)}}\Deffunc{settag} | 1709 | \subsubsection*{\ff {\tt settag (o, tag)}}\Deffunc{settag} |
1695 | This function sets the tag of a given object \see{TypesSec}. | 1710 | This function sets the tag of a given object \see{TypesSec}. |
1696 | The object \verb|o| must be a userdata or a table. | 1711 | The object \verb|o| must be a userdata or a table. |
1697 | \verb|tag| must be a value created with \verb|newtag| | 1712 | \verb|tag| must be a value created with \verb|newtag| |
1698 | \see{pdf-newtag}. | 1713 | \see{pdf-newtag}. |
1714 | \verb|settag| is equivalent to the API function \verb|lua_settag|. | ||
1699 | 1715 | ||
1700 | \subsubsection*{\ff{\tt assert (v)}}\Deffunc{assert} | 1716 | \subsubsection*{\ff {\tt assert (v)}}\Deffunc{assert} |
1701 | This function issues an {\em ``assertion failed!''} error | 1717 | This function issues an {\em ``assertion failed!''} error |
1702 | when its argument is \nil. | 1718 | when its argument is \nil. |
1703 | 1719 | ||
1704 | \subsubsection*{\ff{\tt error (message)}}\Deffunc{error}\label{pdf-error} | 1720 | \subsubsection*{\ff {\tt error (message)}}\Deffunc{error}\label{pdf-error} |
1705 | This function issues an error message and terminates | 1721 | This function issues an error message and terminates |
1706 | the last called function from the library | 1722 | the last called function from the library |
1707 | (\verb|lua_dofile|, \verb|lua_dostring|, or \verb|lua_callfunction|). | 1723 | (\verb|lua_dofile|, \verb|lua_dostring|, or \verb|lua_callfunction|). |
1708 | It never returns. | 1724 | It never returns. |
1709 | \verb|error| is simply an interface to \verb|lua_error|. | 1725 | \verb|error| is equivalent to the API function \verb|lua_error|. |
1710 | 1726 | ||
1711 | \subsubsection*{\ff{\tt rawgettable (table, index)}}\Deffunc{rawgettable} | 1727 | \subsubsection*{\ff {\tt rawgettable (table, index)}}\Deffunc{rawgettable} |
1712 | Gets the real value of \verb|table[index]|, | 1728 | Gets the real value of \verb|table[index]|, |
1713 | without invoking any tag method. | 1729 | without invoking any tag method. |
1714 | \verb|table| must be a table, | 1730 | \verb|table| must be a table, |
1715 | and \verb|index| is any value different from \nil. | 1731 | and \verb|index| is any value different from \nil. |
1716 | 1732 | ||
1717 | \subsubsection*{\ff{\tt rawsettable (table, index, value)}}\Deffunc{rawsettable} | 1733 | \subsubsection*{\ff {\tt rawsettable (table, index, value)}}\Deffunc{rawsettable} |
1718 | Sets the real value \verb|table[index]=value|, | 1734 | Sets the real value \verb|table[index]=value|, |
1719 | without invoking any tag method. | 1735 | without invoking any tag method. |
1720 | \verb|table| must be a table, | 1736 | \verb|table| must be a table, |
1721 | \verb|index| is any value different from \nil, | 1737 | \verb|index| is any value different from \nil, |
1722 | and \verb|value| is any Lua value. | 1738 | and \verb|value| is any Lua value. |
1723 | 1739 | ||
1724 | \subsubsection*{\ff{\tt rawsetglobal (name, value)}}\Deffunc{rawsetglobal} | 1740 | \subsubsection*{\ff {\tt rawsetglobal (name, value)}}\Deffunc{rawsetglobal} |
1725 | This function assigns the given value to a global variable. | 1741 | This function assigns the given value to a global variable. |
1726 | The string \verb|name| does not need to be a syntactically valid variable name. | 1742 | The string \verb|name| does not need to be a syntactically valid variable name. |
1727 | Therefore, this function can set global variables with strange names like | 1743 | Therefore, this function can set global variables with strange names like |
1728 | \verb|`m v 1'| or \verb|34|. | 1744 | \verb|"m v 1"| or \verb|34|. |
1729 | It returns the value of its second argument. | 1745 | It returns the value of its second argument. |
1730 | 1746 | ||
1731 | \subsubsection*{\ff{\tt setglobal (name, value)}}\Deffunc{setglobal} | 1747 | \subsubsection*{\ff {\tt setglobal (name, value)}}\Deffunc{setglobal} |
1732 | This function assigns the given value to a global variable, | 1748 | This function assigns the given value to a global variable, |
1733 | or calls a tag method. | 1749 | or calls a tag method. |
1734 | Its full semantics is explained in \See{tag-method}. | 1750 | Its full semantics is explained in \See{tag-method}. |
1735 | 1751 | ||
1736 | \subsubsection*{\ff{\tt rawgetglobal (name)}}\Deffunc{rawgetglobal} | 1752 | \subsubsection*{\ff {\tt rawgetglobal (name)}}\Deffunc{rawgetglobal} |
1737 | This function retrieves the value of a global variable. | 1753 | This function retrieves the value of a global variable. |
1738 | The string \verb|name| does not need to be a | 1754 | The string \verb|name| does not need to be a |
1739 | syntactically valid variable name. | 1755 | syntactically valid variable name. |
1740 | 1756 | ||
1741 | \subsubsection*{\ff{\tt getglobal (name)}}\Deffunc{getglobal} | 1757 | \subsubsection*{\ff {\tt getglobal (name)}}\Deffunc{getglobal} |
1742 | This function retrieves the value of a global variable, | 1758 | This function retrieves the value of a global variable, |
1743 | or calls a tag method. | 1759 | or calls a tag method. |
1744 | Its full semantics is explained in \See{tag-method}. | 1760 | Its full semantics is explained in \See{tag-method}. |
1745 | 1761 | ||
1746 | \subsubsection*{\ff{\tt seterrormethod (newmethod)}} | 1762 | \subsubsection*{\ff {\tt seterrormethod (newmethod)}} |
1763 | \label{pdf-seterrormethod} | ||
1747 | Sets the error handler \see{error}. | 1764 | Sets the error handler \see{error}. |
1748 | \verb|newmethod| must be a function or \nil, | 1765 | \verb|newmethod| must be a function or \nil, |
1749 | in which case the error handler does nothing. | 1766 | in which case the error handler does nothing. |
1750 | Returns the old handler. | 1767 | Returns the old error handler. |
1751 | 1768 | ||
1752 | \subsubsection*{\ff{\tt settagmethod (tag, event, newmethod)}} | 1769 | \subsubsection*{\ff {\tt settagmethod (tag, event, newmethod)}} |
1753 | \Deffunc{settagmethod} | 1770 | \Deffunc{settagmethod} |
1754 | This function sets a new tag method to the given pair $<tag, event>$. | 1771 | This function sets a new tag method to the given pair $<tag, event>$. |
1755 | It returns the old method. | 1772 | It returns the old method. |
1756 | If \verb|newmethod| is \nil, | 1773 | If \verb|newmethod| is \nil, |
1757 | it restores the default behavior for the given event. | 1774 | it restores the default behavior for the given event. |
1758 | 1775 | ||
1759 | \subsubsection*{\ff{\tt gettagmethod (tag, event)}} | 1776 | \subsubsection*{\ff {\tt gettagmethod (tag, event)}} |
1760 | \Deffunc{gettagmethod} | 1777 | \Deffunc{gettagmethod} |
1761 | This function returns the current tag method | 1778 | This function returns the current tag method |
1762 | for a given pair $<tag, event>$. | 1779 | for a given pair $<tag, event>$. |
@@ -1765,30 +1782,31 @@ for a given pair $<tag, event>$. | |||
1765 | \subsection{String Manipulation} | 1782 | \subsection{String Manipulation} |
1766 | This library provides generic functions for string manipulation, | 1783 | This library provides generic functions for string manipulation, |
1767 | such as finding and extracting substrings and pattern matching. | 1784 | such as finding and extracting substrings and pattern matching. |
1768 | When indexing a string, the first character is at position 1, | 1785 | When indexing a string, the first character is at position~1, |
1769 | not 0, as in C. | 1786 | not~0, as in C. |
1770 | 1787 | ||
1771 | \subsubsection*{\ff{\tt strfind (str, pattern [, init [, plain]])}} | 1788 | \subsubsection*{\ff {\tt strfind (str, pattern [, init [, plain]])}} |
1772 | \Deffunc{strfind} | 1789 | \Deffunc{strfind} |
1773 | This function looks for the first {\em match\/} of | 1790 | This function looks for the first {\em match\/} of |
1774 | \verb|pattern| in \verb|str|. | 1791 | \verb|pattern| in \verb|str|. |
1775 | If it finds one, then it returns the indices on \verb|str| | 1792 | If it finds one, then it returns the indices on \verb|str| |
1776 | where this occurence starts and ends; | 1793 | where this occurrence starts and ends; |
1777 | otherwise, it returns \nil. | 1794 | otherwise, it returns \nil. |
1778 | If the pattern specifies captures, | 1795 | If the pattern specifies captures, |
1779 | the captured strings are returned as extra results. | 1796 | the captured strings are returned as extra results. |
1780 | A third optional numerical argument specifies where to start the search; | 1797 | A third optional numerical argument specifies where to start the search; |
1781 | its default value is 1. | 1798 | its default value is 1. |
1782 | A value of 1 as a forth optional argument | 1799 | A value of 1 as a fourth optional argument |
1783 | turns off the pattern matching facilities, | 1800 | turns off the pattern matching facilities, |
1784 | so the function does a plain ``find substring'' operation. | 1801 | so the function does a plain ``find substring'' operation, |
1802 | with no characters in \verb|pattern| being considered ``magic''. | ||
1785 | 1803 | ||
1786 | \subsubsection*{\ff{\tt strlen (s)}}\Deffunc{strlen} | 1804 | \subsubsection*{\ff {\tt strlen (s)}}\Deffunc{strlen} |
1787 | Receives a string and returns its length. | 1805 | Receives a string and returns its length. |
1788 | 1806 | ||
1789 | \subsubsection*{\ff{\tt strsub (s, i [, j])}}\Deffunc{strsub} | 1807 | \subsubsection*{\ff {\tt strsub (s, i [, j])}}\Deffunc{strsub} |
1790 | Returns another string, which is a substring of \verb|s|, | 1808 | Returns another string, which is a substring of \verb|s|, |
1791 | starting at \verb|i| and runing until \verb|j|. | 1809 | starting at \verb|i| and running until \verb|j|. |
1792 | If \verb|i| or \verb|j| are negative, | 1810 | If \verb|i| or \verb|j| are negative, |
1793 | they are replaced by the length of the string minus their | 1811 | they are replaced by the length of the string minus their |
1794 | absolute value plus 1. | 1812 | absolute value plus 1. |
@@ -1802,25 +1820,25 @@ with length \verb|j|, | |||
1802 | and the call \verb|strsub(s, -i)| returns a suffix of \verb|s| | 1820 | and the call \verb|strsub(s, -i)| returns a suffix of \verb|s| |
1803 | with length \verb|i|. | 1821 | with length \verb|i|. |
1804 | 1822 | ||
1805 | \subsubsection*{\ff{\tt strlower (s)}}\Deffunc{strlower} | 1823 | \subsubsection*{\ff {\tt strlower (s)}}\Deffunc{strlower} |
1806 | Receives a string and returns a copy of that string with all | 1824 | Receives a string and returns a copy of that string with all |
1807 | upper case letters changed to lower case. | 1825 | upper case letters changed to lower case. |
1808 | All other characters are left unchanged. | 1826 | All other characters are left unchanged. |
1809 | 1827 | ||
1810 | \subsubsection*{\ff{\tt strupper (s)}}\Deffunc{strupper} | 1828 | \subsubsection*{\ff {\tt strupper (s)}}\Deffunc{strupper} |
1811 | Receives a string and returns a copy of that string with all | 1829 | Receives a string and returns a copy of that string with all |
1812 | lower case letters changed to upper case. | 1830 | lower case letters changed to upper case. |
1813 | All other characters are left unchanged. | 1831 | All other characters are left unchanged. |
1814 | 1832 | ||
1815 | \subsubsection*{\ff{\tt strrep (s, n)}}\Deffunc{strrep} | 1833 | \subsubsection*{\ff {\tt strrep (s, n)}}\Deffunc{strrep} |
1816 | Returns a string which is the concatenation of \verb|n| copies of | 1834 | Returns a string which is the concatenation of \verb|n| copies of |
1817 | the string \verb|s|. | 1835 | the string \verb|s|. |
1818 | 1836 | ||
1819 | \subsubsection*{\ff{\tt ascii (s [, i])}}\Deffunc{ascii} | 1837 | \subsubsection*{\ff {\tt ascii (s [, i])}}\Deffunc{ascii} |
1820 | Returns the ASCII code of the character \verb|s[i]|. | 1838 | Returns the ASCII code of the character \verb|s[i]|. |
1821 | If \verb|i| is absent, then it is assumed to be 1. | 1839 | If \verb|i| is absent, then it is assumed to be 1. |
1822 | 1840 | ||
1823 | \subsubsection*{\ff{\tt format (formatstring, e1, e2, \ldots)}}\Deffunc{format} | 1841 | \subsubsection*{\ff {\tt format (formatstring, e1, e2, \ldots)}}\Deffunc{format} |
1824 | \label{format} | 1842 | \label{format} |
1825 | This function returns a formated version of its variable number of arguments | 1843 | This function returns a formated version of its variable number of arguments |
1826 | following the description given in its first argument (which must be a string). | 1844 | following the description given in its first argument (which must be a string). |
@@ -1855,7 +1873,8 @@ the appropriate format string. | |||
1855 | For example, \verb|"%*g"| can be simulated with | 1873 | For example, \verb|"%*g"| can be simulated with |
1856 | \verb|"%"..width.."g"|. | 1874 | \verb|"%"..width.."g"|. |
1857 | 1875 | ||
1858 | \subsubsection*{\ff{\tt gsub (s, pat, repl [, n])}}\Deffunc{gsub} | 1876 | \subsubsection*{\ff {\tt gsub (s, pat, repl [, table] [, n])}} |
1877 | \Deffunc{gsub} | ||
1859 | Returns a copy of \verb|s|, | 1878 | Returns a copy of \verb|s|, |
1860 | where all occurrences of the pattern \verb|pat| have been | 1879 | where all occurrences of the pattern \verb|pat| have been |
1861 | replaced by a replacement string specified by \verb|repl|. | 1880 | replaced by a replacement string specified by \verb|repl|. |
@@ -1868,38 +1887,53 @@ with \verb|n| between 1 and 9 | |||
1868 | stands for the value of the n-th captured substring. | 1887 | stands for the value of the n-th captured substring. |
1869 | 1888 | ||
1870 | If \verb|repl| is a function, then this function is called every time a | 1889 | If \verb|repl| is a function, then this function is called every time a |
1871 | match occurs, with all captured substrings as parameters | 1890 | match occurs, with the following arguments: |
1872 | (see below). | 1891 | If \verb|table| is present, it is the first argument; |
1892 | then all captured substrings, in order (see below); | ||
1893 | finally, the last argument is a match counter | ||
1894 | (1 for the first call). | ||
1873 | If the value returned by this function is a string, | 1895 | If the value returned by this function is a string, |
1874 | then it is used as the replacement string; | 1896 | then it is used as the replacement string; |
1875 | otherwise, the replacement string is the empty string. | 1897 | otherwise, the replacement string is the empty string. |
1876 | 1898 | ||
1877 | An optional parameter \verb|n| limits | 1899 | A last optional parameter \verb|n| limits |
1878 | the maximum number of substitutions to occur. | 1900 | the maximum number of substitutions to occur. |
1879 | For instance, when \verb|n| is 1 only the first occurrence of | 1901 | For instance, when \verb|n| is 1 only the first occurrence of |
1880 | \verb|pat| is replaced. | 1902 | \verb|pat| is replaced. |
1881 | 1903 | ||
1882 | As an example, in the following expression each occurrence of the form | 1904 | See some examples below: |
1883 | \verb|$name| calls the function \verb|getenv|, | ||
1884 | passing \verb|name| as argument | ||
1885 | (because only this part of the pattern is captured). | ||
1886 | The value returned by \verb|getenv| will replace the pattern. | ||
1887 | Therefore, the whole expression: | ||
1888 | \begin{verbatim} | 1905 | \begin{verbatim} |
1889 | gsub("home = $HOME, user = $USER", "$(%w%w*)", getenv) | 1906 | x = gsub("hello world", "(%w%w*)", "%1 %1", 1) |
1890 | \end{verbatim} | 1907 | --> x="hello hello world" |
1891 | returns a string like: | 1908 | |
1892 | \begin{verbatim} | 1909 | x = gsub("home = $HOME, user = $USER", "$(%w%w*)", getenv) |
1893 | home = /home/roberto, user = roberto | 1910 | --> x="home = /home/roberto, user = roberto" (for instance) |
1911 | |||
1912 | x = gsub("4+5 = $return 4+5$", "$(.-)%$", dostring) | ||
1913 | --> x="4+5 = 9" | ||
1914 | |||
1915 | t = {name="lua", version="3.0"} | ||
1916 | x = gsub("$name - $version", "$(%w%w*)", rawgettable, t) | ||
1917 | --> x="lua - 3.0" | ||
1918 | |||
1919 | t = {"apple", "orange", "lime"} | ||
1920 | x = gsub("x and x and x", "x", rawgettable, t) | ||
1921 | --> x="apple and orange and lime" | ||
1922 | |||
1923 | function f(t,v,i) t[i]=v end | ||
1924 | t = {} | ||
1925 | gsub("first second word", "(%w%w*)", f, t) | ||
1926 | --> t={"first", "second", "word"} | ||
1894 | \end{verbatim} | 1927 | \end{verbatim} |
1895 | 1928 | ||
1929 | |||
1896 | \subsubsection*{Patterns} \label{pm} | 1930 | \subsubsection*{Patterns} \label{pm} |
1897 | 1931 | ||
1898 | \paragraph{Character Class:} | 1932 | \paragraph{Character Class:} |
1899 | a \Def{character class} is used to represent a set of characters. | 1933 | a \Def{character class} is used to represent a set of characters. |
1900 | The following combinations are allowed in describing a character class: | 1934 | The following combinations are allowed in describing a character class: |
1901 | \begin{description} | 1935 | \begin{description} |
1902 | \item[{\em x}] (where {\em x} is any character not in the list \verb|()%.[*?|) | 1936 | \item[{\em x}] (where {\em x} is any character not in the list \verb|()%.[*-?|) |
1903 | --- represents the character {\em x} itself. | 1937 | --- represents the character {\em x} itself. |
1904 | \item[{\tt .}] --- represents all characters. | 1938 | \item[{\tt .}] --- represents all characters. |
1905 | \item[{\tt \%a}] --- represents all letters. | 1939 | \item[{\tt \%a}] --- represents all letters. |
@@ -1916,7 +1950,7 @@ The following combinations are allowed in describing a character class: | |||
1916 | \item[{\tt \%W}] --- represents all non alphanumeric characters. | 1950 | \item[{\tt \%W}] --- represents all non alphanumeric characters. |
1917 | \item[{\tt \%\M{x}}] (where \M{x} is any non alphanumeric character) --- | 1951 | \item[{\tt \%\M{x}}] (where \M{x} is any non alphanumeric character) --- |
1918 | represents the character \M{x}. | 1952 | represents the character \M{x}. |
1919 | This is the standard way to escape the magic characters \verb|()%.[*?|. | 1953 | This is the standard way to escape the magic characters \verb|()%.[*-?|. |
1920 | \item[{\tt [char-set]}] --- | 1954 | \item[{\tt [char-set]}] --- |
1921 | Represents the class which is the union of all | 1955 | Represents the class which is the union of all |
1922 | characters in char-set. | 1956 | characters in char-set. |
@@ -1943,12 +1977,12 @@ which matches any single character in the class; | |||
1943 | \item | 1977 | \item |
1944 | a single character class followed by \verb|*|, | 1978 | a single character class followed by \verb|*|, |
1945 | which matches 0 or more repetitions of characters in the class. | 1979 | which matches 0 or more repetitions of characters in the class. |
1946 | These repetition itens will always match the longest possible sequence. | 1980 | These repetition items will always match the longest possible sequence. |
1947 | \item | 1981 | \item |
1948 | a single character class followed by \verb|-|, | 1982 | a single character class followed by \verb|-|, |
1949 | which also matches 0 or more repetitions of characters in the class. | 1983 | which also matches 0 or more repetitions of characters in the class. |
1950 | Unlike \verb|*|, | 1984 | Unlike \verb|*|, |
1951 | these repetition itens will always match the shortest possible sequence. | 1985 | these repetition items will always match the shortest possible sequence. |
1952 | \item | 1986 | \item |
1953 | a single character class followed by \verb|?|, | 1987 | a single character class followed by \verb|?|, |
1954 | which matches 0 or 1 occurrence of a character in the class; | 1988 | which matches 0 or 1 occurrence of a character in the class; |
@@ -1958,12 +1992,12 @@ such item matches a sub-string equal to the n-th captured string | |||
1958 | (see below); | 1992 | (see below); |
1959 | \item | 1993 | \item |
1960 | {\tt \%b\M{xy}}, where \M{x} and \M{y} are two distinct characters; | 1994 | {\tt \%b\M{xy}}, where \M{x} and \M{y} are two distinct characters; |
1961 | such item mathes strings that start with \M{x}, end with \M{y}, | 1995 | such item matches strings that start with \M{x}, end with \M{y}, |
1962 | and where the \M{x} and \M{y} are {\em balanced}. | 1996 | and where the \M{x} and \M{y} are {\em balanced}. |
1963 | That means that, if one reads the string from left to write, | 1997 | That means that, if one reads the string from left to write, |
1964 | counting plus 1 for an \M{x} and minus 1 for a \M{y}, | 1998 | counting plus 1 for an \M{x} and minus 1 for a \M{y}, |
1965 | the ending \M{y} is the first where the count reaches 0. | 1999 | the ending \M{y} is the first where the count reaches 0. |
1966 | For instance, the item \verb|%()| matches expressions with | 2000 | For instance, the item \verb|%b()| matches expressions with |
1967 | balanced parentheses. | 2001 | balanced parentheses. |
1968 | \end{itemize} | 2002 | \end{itemize} |
1969 | 2003 | ||
@@ -2021,7 +2055,7 @@ range \M{[0,1)}. | |||
2021 | 2055 | ||
2022 | \subsection{I/O Facilities} \label{libio} | 2056 | \subsection{I/O Facilities} \label{libio} |
2023 | 2057 | ||
2024 | All input and outpu operations in Lua are done over two {\em current\/} files: | 2058 | All input and output operations in Lua are done over two {\em current\/} files: |
2025 | one for reading and one for writing. | 2059 | one for reading and one for writing. |
2026 | Initially, the current input file is \verb|stdin|, | 2060 | Initially, the current input file is \verb|stdin|, |
2027 | and the current output file is \verb|stdout|. | 2061 | and the current output file is \verb|stdout|. |
@@ -2030,16 +2064,16 @@ Unless otherwise stated, | |||
2030 | all I/O functions return \nil\ on failure and | 2064 | all I/O functions return \nil\ on failure and |
2031 | some value different from \nil\ on success. | 2065 | some value different from \nil\ on success. |
2032 | 2066 | ||
2033 | \subsubsection*{\ff{\tt readfrom (filename)}}\Deffunc{readfrom} | 2067 | \subsubsection*{\ff {\tt readfrom (filename)}}\Deffunc{readfrom} |
2034 | 2068 | ||
2035 | This function may be called in three ways. | 2069 | This function may be called in three ways. |
2036 | When called with a file name, | 2070 | When called with a file name, |
2037 | it opens the named file, | 2071 | it opens the named file, |
2038 | sets it as the {\em current\/} input file, | 2072 | sets it as the {\em current\/} input file, |
2039 | and returns a {\em handle\/} to the file | 2073 | and returns a {\em handle\/} to the file |
2040 | (this handle is a user data containing the file stream \verb|FILE*|). | 2074 | (this handle is a userdata containing the file stream \verb|FILE*|). |
2041 | It does not close the current input file. | 2075 | It does not close the current input file. |
2042 | When called with a file handle, returned by a previous call, | 2076 | When called with a file handle returned by a previous call, |
2043 | it restores the file as the current input. | 2077 | it restores the file as the current input. |
2044 | When called without parameters, | 2078 | When called without parameters, |
2045 | it closes the current input file, | 2079 | it closes the current input file, |
@@ -2058,7 +2092,7 @@ the number of files that can be open at the same time is usually limited and | |||
2058 | depends on the system. | 2092 | depends on the system. |
2059 | \end{quotation} | 2093 | \end{quotation} |
2060 | 2094 | ||
2061 | \subsubsection*{\ff{\tt writeto (filename)}}\Deffunc{writeto} | 2095 | \subsubsection*{\ff {\tt writeto (filename)}}\Deffunc{writeto} |
2062 | 2096 | ||
2063 | This function may be called in three ways. | 2097 | This function may be called in three ways. |
2064 | When called with a file name, | 2098 | When called with a file name, |
@@ -2068,8 +2102,8 @@ and returns a {\em handle\/} to the file | |||
2068 | (this handle is a user data containing the file stream \verb|FILE*|). | 2102 | (this handle is a user data containing the file stream \verb|FILE*|). |
2069 | It does not close the current output file. | 2103 | It does not close the current output file. |
2070 | Notice that, if the file already exists, | 2104 | Notice that, if the file already exists, |
2071 | it will be {\em completely erased\/} with this operation. | 2105 | then it will be {\em completely erased\/} with this operation. |
2072 | When called with a file handle, returned by a previous call, | 2106 | When called with a file handle returned by a previous call, |
2073 | it restores the file as the current output. | 2107 | it restores the file as the current output. |
2074 | When called without parameters, | 2108 | When called without parameters, |
2075 | this function closes the current output file, | 2109 | this function closes the current output file, |
@@ -2090,7 +2124,7 @@ the number of files that can be open at the same time is usually limited and | |||
2090 | depends on the system. | 2124 | depends on the system. |
2091 | \end{quotation} | 2125 | \end{quotation} |
2092 | 2126 | ||
2093 | \subsubsection*{\ff{\tt appendto (filename)}}\Deffunc{appendto} | 2127 | \subsubsection*{\ff {\tt appendto (filename)}}\Deffunc{appendto} |
2094 | 2128 | ||
2095 | This function opens a file named \verb|filename| and sets it as the | 2129 | This function opens a file named \verb|filename| and sets it as the |
2096 | {\em current\/} output file. | 2130 | {\em current\/} output file. |
@@ -2103,24 +2137,25 @@ plus a string describing the error. | |||
2103 | 2137 | ||
2104 | Notice that function \verb|writeto| is available to close an output file. | 2138 | Notice that function \verb|writeto| is available to close an output file. |
2105 | 2139 | ||
2106 | \subsubsection*{\ff{\tt remove (filename)}}\Deffunc{remove} | 2140 | \subsubsection*{\ff {\tt remove (filename)}}\Deffunc{remove} |
2107 | 2141 | ||
2108 | This function deletes the file with the given name. | 2142 | This function deletes the file with the given name. |
2109 | If this function fails, it returns \nil, | 2143 | If this function fails, it returns \nil, |
2110 | plus a string describing the error. | 2144 | plus a string describing the error. |
2111 | 2145 | ||
2112 | \subsubsection*{\ff{\tt rename (name1, name2)}}\Deffunc{rename} | 2146 | \subsubsection*{\ff {\tt rename (name1, name2)}}\Deffunc{rename} |
2113 | 2147 | ||
2114 | This function renames file named \verb|name1| to \verb|name2|. | 2148 | This function renames file named \verb|name1| to \verb|name2|. |
2115 | If this function fails, it returns \nil, | 2149 | If this function fails, it returns \nil, |
2116 | plus a string describing the error. | 2150 | plus a string describing the error. |
2117 | 2151 | ||
2118 | \subsubsection*{\ff{\tt tmpname ()}}\Deffunc{tmpname} | 2152 | \subsubsection*{\ff {\tt tmpname ()}}\Deffunc{tmpname} |
2119 | 2153 | ||
2120 | This function returns a string with a file name that can safely | 2154 | This function returns a string with a file name that can safely |
2121 | be used for a temporary file. | 2155 | be used for a temporary file. |
2156 | The file must be explicitly removed when no longer needed. | ||
2122 | 2157 | ||
2123 | \subsubsection*{\ff{\tt read ([readpattern])}}\Deffunc{read} | 2158 | \subsubsection*{\ff {\tt read ([readpattern])}}\Deffunc{read} |
2124 | 2159 | ||
2125 | This function reads the current input | 2160 | This function reads the current input |
2126 | according to a read pattern, that specifies how much to read; | 2161 | according to a read pattern, that specifies how much to read; |
@@ -2173,7 +2208,7 @@ or \nil\ on end of file. | |||
2173 | or \nil\ if the next characters do not conform to an integer format. | 2208 | or \nil\ if the next characters do not conform to an integer format. |
2174 | \end{itemize} | 2209 | \end{itemize} |
2175 | 2210 | ||
2176 | \subsubsection*{\ff{\tt write (value1, ...)}}\Deffunc{write} | 2211 | \subsubsection*{\ff {\tt write (value1, ...)}}\Deffunc{write} |
2177 | 2212 | ||
2178 | This function writes the value of each of its arguments to the | 2213 | This function writes the value of each of its arguments to the |
2179 | current output file. | 2214 | current output file. |
@@ -2183,7 +2218,7 @@ use \verb|tostring| before \verb|write|. | |||
2183 | If this function fails, it returns \nil, | 2218 | If this function fails, it returns \nil, |
2184 | plus a string describing the error. | 2219 | plus a string describing the error. |
2185 | 2220 | ||
2186 | \subsubsection*{\ff{\tt date ([format])}}\Deffunc{date} | 2221 | \subsubsection*{\ff {\tt date ([format])}}\Deffunc{date} |
2187 | 2222 | ||
2188 | This function returns a string containing date and time | 2223 | This function returns a string containing date and time |
2189 | formatted according to the given string \verb|format|, | 2224 | formatted according to the given string \verb|format|, |
@@ -2192,19 +2227,19 @@ When called without arguments, | |||
2192 | it returns a reasonable date and time representation that depends on | 2227 | it returns a reasonable date and time representation that depends on |
2193 | the host system. | 2228 | the host system. |
2194 | 2229 | ||
2195 | \subsubsection*{\ff{\tt exit ([code])}}\Deffunc{exit} | 2230 | \subsubsection*{\ff {\tt exit ([code])}}\Deffunc{exit} |
2196 | 2231 | ||
2197 | This function calls the C function \verb|exit|, | 2232 | This function calls the C function \verb|exit|, |
2198 | with an optional \verb|code|, | 2233 | with an optional \verb|code|, |
2199 | to terminate the program. | 2234 | to terminate the program. |
2200 | The default value for \verb|code| is 1. | 2235 | The default value for \verb|code| is 1. |
2201 | 2236 | ||
2202 | \subsubsection*{\ff{\tt getenv (varname)}}\Deffunc{getenv} | 2237 | \subsubsection*{\ff {\tt getenv (varname)}}\Deffunc{getenv} |
2203 | 2238 | ||
2204 | Returns the value of the environment variable \verb|varname|, | 2239 | Returns the value of the environment variable \verb|varname|, |
2205 | or \nil\ if the variable is not defined. | 2240 | or \nil\ if the variable is not defined. |
2206 | 2241 | ||
2207 | \subsubsection*{\ff{\tt execute (command)}}\Deffunc{execute} | 2242 | \subsubsection*{\ff {\tt execute (command)}}\Deffunc{execute} |
2208 | 2243 | ||
2209 | This function is equivalent to the C function \verb|system|. | 2244 | This function is equivalent to the C function \verb|system|. |
2210 | It passes \verb|command| to be executed by an operating system shell. | 2245 | It passes \verb|command| to be executed by an operating system shell. |
@@ -2301,7 +2336,6 @@ or if the activation record has no debug information, | |||
2301 | Formal parameters are the first local variables. | 2336 | Formal parameters are the first local variables. |
2302 | 2337 | ||
2303 | The function \verb|lua_setlocal| sets the local variable | 2338 | The function \verb|lua_setlocal| sets the local variable |
2304 | %%LHF: please, lua_setglobal! | ||
2305 | \verb|local_number| to the value previously pushed on the stack | 2339 | \verb|local_number| to the value previously pushed on the stack |
2306 | \see{valuesCLua}. | 2340 | \see{valuesCLua}. |
2307 | If the function succeeds, then it returns 1. | 2341 | If the function succeeds, then it returns 1. |