| @@ -1,16 +1,16 @@ |
| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> |
| 2 | <html> | 2 | <html> |
| 3 | | 3 | |
| 4 | <head> | 4 | <head> |
| 5 | <title>Lua 5.1 Reference Manual</title> | 5 | <title>Lua 5.1 Reference Manual</title> |
| 6 | <LINK REL="stylesheet" TYPE="text/css" HREF="lua.css"> | 6 | <link rel="stylesheet" href="lua.css"> |
| 7 | </head> | 7 | </head> |
| 8 | | 8 | |
| 9 | <body BGCOLOR="#FFFFFF"> | 9 | <body bgcolor="#FFFFFF"> |
| 10 | | 10 | |
| 11 | <hr> | 11 | <hr/> |
| 12 | <h1> | 12 | <h1> |
| 13 | <a href="http://www.lua.org/home.html"><img src="logo.gif" ALT="[Lua logo]" border=0></a> | 13 | <a href="http://www.lua.org/home.html"><img src="logo.gif" alt="[Lua logo]" border="0"/></a> |
| 14 | Lua 5.1 Reference Manual | 14 | Lua 5.1 Reference Manual |
| 15 | </h1> | 15 | </h1> |
| 16 | | 16 | |
| @@ -20,7 +20,7 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 3 unmodified lines |
| 20 | <a href="http://www.lua.org/copyright.html">Copyright</a> | 20 | <a href="http://www.lua.org/copyright.html">Copyright</a> |
| 21 | © 2005 Lua.org, PUC-Rio. All rights reserved. | 21 | © 2005 Lua.org, PUC-Rio. All rights reserved. |
| 22 | </small> | 22 | </small> |
| 23 | <hr> | 23 | <hr/> |
| 24 | | 24 | |
| 25 | <p> | 25 | <p> |
| 26 | <p> | 26 | <p> |
| @@ -28,7 +28,6 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 1 unmodified line |
| 28 | | 28 | |
| 29 | | 29 | |
| 30 | | 30 | |
| 31 | <p> | | |
| 32 | <a name="1"></a><h1>1 - Introduction</h1> | 31 | <a name="1"></a><h1>1 - Introduction</h1> |
| 33 | | 32 | |
| 34 | <p>Lua is an extension programming language designed to support | 33 | <p>Lua is an extension programming language designed to support |
| @@ -68,21 +67,21 @@ which are available at Lua's web site. · 33 unmodified lines |
| 68 | <ul> | 67 | <ul> |
| 69 | <li> | 68 | <li> |
| 70 | R. Ierusalimschy, L. H. de Figueiredo, and W. Celes. | 69 | R. Ierusalimschy, L. H. de Figueiredo, and W. Celes. |
| 71 | Lua—an extensible extension language. | 70 | Lua---an extensible extension language. |
| 72 | <em>Software: Practice & Experience</em> <b>26</b>:6 (1996) 635–652. | 71 | <em>Software: Practice & Experience</em> <b>26</b>:6 (1996) 635--652. |
| 73 | <li> | 72 | <li> |
| 74 | L. H. de Figueiredo, R. Ierusalimschy, and W. Celes. | 73 | L. H. de Figueiredo, R. Ierusalimschy, and W. Celes. |
| 75 | The design and implementation of a language for extending applications. | 74 | The design and implementation of a language for extending applications. |
| 76 | <em>Proceedings of XXI Brazilian Seminar on Software and Hardware</em> | 75 | <em>Proceedings of XXI Brazilian Seminar on Software and Hardware</em> |
| 77 | (1994) 273–283. | 76 | (1994) 273--283. |
| 78 | <li> | 77 | <li> |
| 79 | L. H. de Figueiredo, R. Ierusalimschy, and W. Celes. | 78 | L. H. de Figueiredo, R. Ierusalimschy, and W. Celes. |
| 80 | Lua: an extensible embedded language. | 79 | Lua: an extensible embedded language. |
| 81 | <em>Dr. Dobb's Journal</em> <b>21</b>:12 (Dec 1996) 26–33. | 80 | <em>Dr. Dobb's Journal</em> <b>21</b>:12 (Dec 1996) 26--33. |
| 82 | <li> | 81 | <li> |
| 83 | R. Ierusalimschy, L. H. de Figueiredo, and W. Celes. | 82 | R. Ierusalimschy, L. H. de Figueiredo, and W. Celes. |
| 84 | The evolution of an extension language: a history of Lua, | 83 | The evolution of an extension language: a history of Lua, |
| 85 | <em>Proceedings of V Brazilian Symposium on Programming Languages</em> (2001) B-14–B-28. | 84 | <em>Proceedings of V Brazilian Symposium on Programming Languages</em> (2001) B-14--B-28. |
| 86 | </ul> | 85 | </ul> |
| 87 | | 86 | |
| 88 | <p>Lua means "moon" in Portuguese and is pronounced LOO-ah. | 87 | <p>Lua means "moon" in Portuguese and is pronounced LOO-ah. |
| @@ -119,12 +118,12 @@ can be used in an identifier.) · 30 unmodified lines |
| 119 | <p>The following <em>keywords</em> are reserved | 118 | <p>The following <em>keywords</em> are reserved |
| 120 | and cannot be used as names: | 119 | and cannot be used as names: |
| 121 | | 120 | |
| 122 | <PRE> | 121 | <pre> |
| 123 | and break do else elseif | 122 | and break do else elseif |
| 124 | end false for function if | 123 | end false for function if |
| 125 | in local nil not or | 124 | in local nil not or |
| 126 | repeat return then true until while | 125 | repeat return then true until while |
| 127 | </PRE> | 126 | </pre> |
| 128 | | 127 | |
| 129 | <p>Lua is a case-sensitive language: | 128 | <p>Lua is a case-sensitive language: |
| 130 | <code>and</code> is a reserved word, but <code>And</code> and <code>AND</code> | 129 | <code>and</code> is a reserved word, but <code>And</code> and <code>AND</code> |
| @@ -134,27 +133,27 @@ uppercase letters (such as <a href="#pdf-_VERSION"><code>_VERSION</code></a>) · 3 unmodified lines |
| 134 | are reserved for internal variables used by Lua. | 133 | are reserved for internal variables used by Lua. |
| 135 | | 134 | |
| 136 | <p>The following strings denote other tokens: | 135 | <p>The following strings denote other tokens: |
| 137 | <PRE> | 136 | <pre> |
| 138 | + - * / % ^ # | 137 | + - * / % ^ # |
| 139 | == ~= <= >= < > = | 138 | == ~= <= >= < > = |
| 140 | ( ) { } [ ] | 139 | ( ) { } [ ] |
| 141 | ; : , . .. ... | 140 | ; : , . .. ... |
| 142 | </PRE> | 141 | </pre> |
| 143 | | 142 | |
| 144 | <p><em>Literal strings</em> | 143 | <p><em>Literal strings</em> |
| 145 | can be delimited by matching single or double quotes, | 144 | can be delimited by matching single or double quotes, |
| 146 | and can contain the following C-like escape sequences: | 145 | and can contain the following C-like escape sequences: |
| 147 | <ul> | 146 | <ul> |
| 148 | <li><b><code>\a</code></b> — bell | 147 | <li><b><code>\a</code></b> --- bell |
| 149 | <li><b><code>\b</code></b> — backspace | 148 | <li><b><code>\b</code></b> --- backspace |
| 150 | <li><b><code>\f</code></b> — form feed | 149 | <li><b><code>\f</code></b> --- form feed |
| 151 | <li><b><code>\n</code></b> — newline | 150 | <li><b><code>\n</code></b> --- newline |
| 152 | <li><b><code>\r</code></b> — carriage return | 151 | <li><b><code>\r</code></b> --- carriage return |
| 153 | <li><b><code>\t</code></b> — horizontal tab | 152 | <li><b><code>\t</code></b> --- horizontal tab |
| 154 | <li><b><code>\v</code></b> — vertical tab | 153 | <li><b><code>\v</code></b> --- vertical tab |
| 155 | <li><b><code>\\</code></b> — backslash | 154 | <li><b><code>\\</code></b> --- backslash |
| 156 | <li><b><code>\"</code></b> — quotation mark | 155 | <li><b><code>\"</code></b> --- quotation mark |
| 157 | <li><b><code>\'</code></b> — apostrophe | 156 | <li><b><code>\'</code></b> --- apostrophe |
| 158 | </ul> | 157 | </ul> |
| 159 | Moreover, a `<code>\</code><em>newline</em>´ | 158 | Moreover, a `<code>\</code><em>newline</em>´ |
| 160 | (that is, a backslash followed by a real newline) | 159 | (that is, a backslash followed by a real newline) |
| @@ -188,7 +187,7 @@ As an example, in a system using ASCII · 27 unmodified lines |
| 188 | (in which `<code>a</code>´ is coded as 97, | 187 | (in which `<code>a</code>´ is coded as 97, |
| 189 | newline is coded as 10, and `<code>1</code>´ is coded as 49), | 188 | newline is coded as 10, and `<code>1</code>´ is coded as 49), |
| 190 | the four literals below denote the same string: | 189 | the four literals below denote the same string: |
| 191 | <PRE> | 190 | <pre> |
| 192 | (1) "alo\n123\"" | 191 | (1) "alo\n123\"" |
| 193 | (2) '\97lo\10\04923"' | 192 | (2) '\97lo\10\04923"' |
| 194 | (3) [[alo | 193 | (3) [[alo |
| @@ -196,14 +195,14 @@ the four literals below denote the same string: · 1 unmodified line |
| 196 | (4) [==[ | 195 | (4) [==[ |
| 197 | alo | 196 | alo |
| 198 | 123"]==] | 197 | 123"]==] |
| 199 | </PRE> | 198 | </pre> |
| 200 | | 199 | |
| 201 | <p><em>Numerical constants</em> may be written with an optional decimal part | 200 | <p><em>Numerical constants</em> may be written with an optional decimal part |
| 202 | and an optional decimal exponent. | 201 | and an optional decimal exponent. |
| 203 | Examples of valid numerical constants are | 202 | Examples of valid numerical constants are |
| 204 | <PRE> | 203 | <pre> |
| 205 | 3 3.0 3.1416 314.16e-2 0.31416E1 | 204 | 3 3.0 3.1416 314.16e-2 0.31416E1 |
| 206 | </PRE> | 205 | </pre> |
| 207 | | 206 | |
| 208 | <p><em>Comments</em> start anywhere outside a string with a | 207 | <p><em>Comments</em> start anywhere outside a string with a |
| 209 | double hyphen (<code>--</code>). | 208 | double hyphen (<code>--</code>). |
| @@ -225,11 +224,11 @@ All values carry their own type. · 15 unmodified lines |
| 225 | <em>nil</em>, <em>boolean</em>, <em>number</em>, | 224 | <em>nil</em>, <em>boolean</em>, <em>number</em>, |
| 226 | <em>string</em>, <em>function</em>, <em>userdata</em>, | 225 | <em>string</em>, <em>function</em>, <em>userdata</em>, |
| 227 | <em>thread</em>, and <em>table</em>. | 226 | <em>thread</em>, and <em>table</em>. |
| 228 | <em>Nil</em> is the type of the value <B>nil</B>, | 227 | <em>Nil</em> is the type of the value <b>nil</b>, |
| 229 | whose main property is to be different from any other value; | 228 | whose main property is to be different from any other value; |
| 230 | usually it represents the absence of a useful value. | 229 | usually it represents the absence of a useful value. |
| 231 | <em>Boolean</em> is the type of the values <B>false</B> and <B>true</B>. | 230 | <em>Boolean</em> is the type of the values <b>false</b> and <b>true</b>. |
| 232 | In Lua, both <B>nil</B> and <B>false</B> make a condition false; | 231 | In Lua, both <b>nil</b> and <b>false</b> make a condition false; |
| 233 | any other value makes it true. | 232 | any other value makes it true. |
| 234 | <em>Number</em> represents real (double-precision floating-point) numbers. | 233 | <em>Number</em> represents real (double-precision floating-point) numbers. |
| 235 | (It is easy to build Lua interpreters that use other | 234 | (It is easy to build Lua interpreters that use other |
| @@ -266,10 +265,10 @@ and it is used to implement coroutines (see <a href="#coroutine">2.11</a>). · 30 unmodified lines |
| 266 | | 265 | |
| 267 | <p>The type <em>table</em> implements associative arrays, | 266 | <p>The type <em>table</em> implements associative arrays, |
| 268 | that is, arrays that can be indexed not only with numbers, | 267 | that is, arrays that can be indexed not only with numbers, |
| 269 | but with any value (except <B>nil</B>). | 268 | but with any value (except <b>nil</b>). |
| 270 | Moreover, | 269 | Moreover, |
| 271 | tables can be <em>heterogeneous</em>, | 270 | tables can be <em>heterogeneous</em>, |
| 272 | that is, they can contain values of all types (except <B>nil</B>). | 271 | that is, they can contain values of all types (except <b>nil</b>). |
| 273 | Tables are the sole data structuring mechanism in Lua; | 272 | Tables are the sole data structuring mechanism in Lua; |
| 274 | they may be used to represent ordinary arrays, | 273 | they may be used to represent ordinary arrays, |
| 275 | symbol tables, sets, records, graphs, trees, etc. | 274 | symbol tables, sets, records, graphs, trees, etc. |
| @@ -280,7 +279,7 @@ There are several convenient ways to create tables in Lua · 4 unmodified lines |
| 280 | (see <a href="#tableconstructor">2.5.7</a>). | 279 | (see <a href="#tableconstructor">2.5.7</a>). |
| 281 | | 280 | |
| 282 | <p>Like indices, | 281 | <p>Like indices, |
| 283 | the value of a table field can be of any type (except <B>nil</B>). | 282 | the value of a table field can be of any type (except <b>nil</b>). |
| 284 | In particular, | 283 | In particular, |
| 285 | because functions are first class values, | 284 | because functions are first class values, |
| 286 | table fields may contain functions. | 285 | table fields may contain functions. |
| @@ -327,7 +326,7 @@ Local variables are <em>lexically scoped</em>: · 40 unmodified lines |
| 327 | Local variables can be freely accessed by functions | 326 | Local variables can be freely accessed by functions |
| 328 | defined inside their scope (see <a href="#visibility">2.6</a>). | 327 | defined inside their scope (see <a href="#visibility">2.6</a>). |
| 329 | | 328 | |
| 330 | <p>Before the first assignment to a variable, its value is <B>nil</B>. | 329 | <p>Before the first assignment to a variable, its value is <b>nil</b>. |
| 331 | | 330 | |
| 332 | <p>Square brackets are used to index a table: | 331 | <p>Square brackets are used to index a table: |
| 333 | <pre> | 332 | <pre> |
| @@ -370,9 +369,9 @@ through the debug library; (see <a href="#libdebug">5.9</a>).) · 36 unmodified lines |
| 370 | <p>An access to a global variable <code>x</code> | 369 | <p>An access to a global variable <code>x</code> |
| 371 | is equivalent to <code>_env.x</code>, | 370 | is equivalent to <code>_env.x</code>, |
| 372 | which in turn is equivalent to | 371 | which in turn is equivalent to |
| 373 | <PRE> | 372 | <pre> |
| 374 | gettable_event(_env, "x") | 373 | gettable_event(_env, "x") |
| 375 | </PRE> | 374 | </pre> |
| 376 | where <code>_env</code> is the environment of the running function. | 375 | where <code>_env</code> is the environment of the running function. |
| 377 | (See <a href="#metatable">2.8</a> for a complete description of the | 376 | (See <a href="#metatable">2.8</a> for a complete description of the |
| 378 | <code>gettable_event</code> function. | 377 | <code>gettable_event</code> function. |
| @@ -454,7 +453,7 @@ the list of variables. · 75 unmodified lines |
| 454 | If there are more values than needed, | 453 | If there are more values than needed, |
| 455 | the excess values are thrown away. | 454 | the excess values are thrown away. |
| 456 | If there are fewer values than needed, | 455 | If there are fewer values than needed, |
| 457 | the list is extended with as many <B>nil</B>'s as needed. | 456 | the list is extended with as many <b>nil</b>'s as needed. |
| 458 | If the list of expressions ends with a function call, | 457 | If the list of expressions ends with a function call, |
| 459 | then all values returned by that function call enter in the list of values, | 458 | then all values returned by that function call enter in the list of values, |
| 460 | before the adjustment | 459 | before the adjustment |
| @@ -463,17 +462,17 @@ before the adjustment · 2 unmodified lines |
| 463 | <p>The assignment statement first evaluates all its expressions | 462 | <p>The assignment statement first evaluates all its expressions |
| 464 | and only then are the assignments performed. | 463 | and only then are the assignments performed. |
| 465 | Thus the code | 464 | Thus the code |
| 466 | <PRE> | 465 | <pre> |
| 467 | i = 3 | 466 | i = 3 |
| 468 | i, a[i] = i+1, 20 | 467 | i, a[i] = i+1, 20 |
| 469 | </PRE> | 468 | </pre> |
| 470 | sets <code>a[3]</code> to 20, without affecting <code>a[4]</code> | 469 | sets <code>a[3]</code> to 20, without affecting <code>a[4]</code> |
| 471 | because the <code>i</code> in <code>a[i]</code> is evaluated (to 3) | 470 | because the <code>i</code> in <code>a[i]</code> is evaluated (to 3) |
| 472 | before it is assigned 4. | 471 | before it is assigned 4. |
| 473 | Similarly, the line | 472 | Similarly, the line |
| 474 | <PRE> | 473 | <pre> |
| 475 | x, y = y, x | 474 | x, y = y, x |
| 476 | </PRE> | 475 | </pre> |
| 477 | exchanges the values of <code>x</code> and <code>y</code>. | 476 | exchanges the values of <code>x</code> and <code>y</code>. |
| 478 | | 477 | |
| 479 | <p>The meaning of assignments to global variables | 478 | <p>The meaning of assignments to global variables |
| @@ -489,9 +488,9 @@ We use it here only for explanatory purposes.) · 9 unmodified lines |
| 489 | is equivalent to the assignment | 488 | is equivalent to the assignment |
| 490 | <code>_env.x = val</code>, | 489 | <code>_env.x = val</code>, |
| 491 | which in turn is equivalent to | 490 | which in turn is equivalent to |
| 492 | <PRE> | 491 | <pre> |
| 493 | settable_event(_env, "x", val) | 492 | settable_event(_env, "x", val) |
| 494 | </PRE> | 493 | </pre> |
| 495 | where <code>_env</code> is the environment of the running function. | 494 | where <code>_env</code> is the environment of the running function. |
| 496 | (The <code>_env</code> variable is not defined in Lua. | 495 | (The <code>_env</code> variable is not defined in Lua. |
| 497 | We use it here only for explanatory purposes.) | 496 | We use it here only for explanatory purposes.) |
| @@ -512,11 +511,11 @@ Lua also has a <b>for</b> statement, in two flavors (see <a href="#for">2.4.5</a · 14 unmodified lines |
| 512 | | 511 | |
| 513 | <p>The condition expression <em>exp</em> of a | 512 | <p>The condition expression <em>exp</em> of a |
| 514 | control structure may return any value. | 513 | control structure may return any value. |
| 515 | Both <B>false</B> and <B>nil</B> are considered false. | 514 | Both <b>false</b> and <b>nil</b> are considered false. |
| 516 | All values different from <B>nil</B> and <B>false</B> are considered true | 515 | All values different from <b>nil</b> and <b>false</b> are considered true |
| 517 | (in particular, the number 0 and the empty string are also true). | 516 | (in particular, the number 0 and the empty string are also true). |
| 518 | | 517 | |
| 519 | <p>In the <b>repeat</b>–<b>until</b> loop, | 518 | <p>In the <b>repeat</b>--<b>until</b> loop, |
| 520 | the inner block does not end at the <b>until</b> keyword, | 519 | the inner block does not end at the <b>until</b> keyword, |
| 521 | but only after the condition. | 520 | but only after the condition. |
| 522 | That means the condition can refer to local variables | 521 | That means the condition can refer to local variables |
| @@ -567,11 +566,11 @@ The <em>block</em> is repeated for <em>name</em> starting at the value of · 44 unmodified lines |
| 567 | the first <em>exp</em>, until it passes the second <em>exp</em> by steps of the | 566 | the first <em>exp</em>, until it passes the second <em>exp</em> by steps of the |
| 568 | third <em>exp</em>. | 567 | third <em>exp</em>. |
| 569 | More precisely, a <b>for</b> statement like | 568 | More precisely, a <b>for</b> statement like |
| 570 | <PRE> | 569 | <pre> |
| 571 | for var = e1, e2, e3 do block end | 570 | for var = e1, e2, e3 do block end |
| 572 | </PRE> | 571 | </pre> |
| 573 | is equivalent to the code: | 572 | is equivalent to the code: |
| 574 | <PRE> | 573 | <pre> |
| 575 | do | 574 | do |
| 576 | local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3) | 575 | local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3) |
| 577 | if not (_var and _limit and _step) then error() end | 576 | if not (_var and _limit and _step) then error() end |
| @@ -581,7 +580,7 @@ is equivalent to the code: · 3 unmodified lines |
| 581 | _var = _var + _step | 580 | _var = _var + _step |
| 582 | end | 581 | end |
| 583 | end | 582 | end |
| 584 | </PRE> | 583 | </pre> |
| 585 | Note the following: | 584 | Note the following: |
| 586 | <ul> | 585 | <ul> |
| 587 | <li> All three control expressions are evaluated only once, | 586 | <li> All three control expressions are evaluated only once, |
| @@ -601,17 +600,17 @@ then assign it to another variable before breaking or exiting the loop. · 13 unmodified lines |
| 601 | <p>The generic <b>for</b> statement works over functions, | 600 | <p>The generic <b>for</b> statement works over functions, |
| 602 | called <em>iterators</em>. | 601 | called <em>iterators</em>. |
| 603 | For each iteration, it calls its iterator function to produce a new value, | 602 | For each iteration, it calls its iterator function to produce a new value, |
| 604 | stopping when the new value is <B>nil</B>. | 603 | stopping when the new value is <b>nil</b>. |
| 605 | The generic <b>for</b> loop has the following syntax: | 604 | The generic <b>for</b> loop has the following syntax: |
| 606 | <pre> | 605 | <pre> |
| 607 | stat ::= <b>for</b> Name {`<b>,</b>´ Name} <b>in</b> explist1 <b>do</b> block <b>end</b> | 606 | stat ::= <b>for</b> Name {`<b>,</b>´ Name} <b>in</b> explist1 <b>do</b> block <b>end</b> |
| 608 | </pre> | 607 | </pre> |
| 609 | A <b>for</b> statement like | 608 | A <b>for</b> statement like |
| 610 | <PRE> | 609 | <pre> |
| 611 | for var_1, ..., var_n in explist do block end | 610 | for var_1, ..., var_n in explist do block end |
| 612 | </PRE> | 611 | </pre> |
| 613 | is equivalent to the code: | 612 | is equivalent to the code: |
| 614 | <PRE> | 613 | <pre> |
| 615 | do | 614 | do |
| 616 | local _f, _s, _var = explist | 615 | local _f, _s, _var = explist |
| 617 | while true do | 616 | while true do |
| @@ -621,7 +620,7 @@ is equivalent to the code: · 3 unmodified lines |
| 621 | block | 620 | block |
| 622 | end | 621 | end |
| 623 | end | 622 | end |
| 624 | </PRE> | 623 | </pre> |
| 625 | Note the following: | 624 | Note the following: |
| 626 | <ul> | 625 | <ul> |
| 627 | <li> <code>explist</code> is evaluated only once. | 626 | <li> <code>explist</code> is evaluated only once. |
| @@ -654,7 +653,7 @@ The declaration may include an initial assignment: · 26 unmodified lines |
| 654 | </pre> | 653 | </pre> |
| 655 | If present, an initial assignment has the same semantics | 654 | If present, an initial assignment has the same semantics |
| 656 | of a multiple assignment (see <a href="#assignment">2.4.3</a>). | 655 | of a multiple assignment (see <a href="#assignment">2.4.3</a>). |
| 657 | Otherwise, all variables are initialized with <B>nil</B>. | 656 | Otherwise, all variables are initialized with <b>nil</b>. |
| 658 | | 657 | |
| 659 | <p>A chunk is also a block (see <a href="#chunks">2.4.1</a>), | 658 | <p>A chunk is also a block (see <a href="#chunks">2.4.1</a>), |
| 660 | so local variables can be declared in a chunk outside any explicit block. | 659 | so local variables can be declared in a chunk outside any explicit block. |
| @@ -668,7 +667,7 @@ The scope of such local variables extends until the end of the chunk. · 7 unmodified lines |
| 668 | The basic expressions in Lua are the following: | 667 | The basic expressions in Lua are the following: |
| 669 | <pre> | 668 | <pre> |
| 670 | exp ::= prefixexp | 669 | exp ::= prefixexp |
| 671 | exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | 670 | exp ::= <b>nil</b> | <b>false</b> | <b>true</b> |
| 672 | exp ::= Number | 671 | exp ::= Number |
| 673 | exp ::= Literal | 672 | exp ::= Literal |
| 674 | exp ::= function | 673 | exp ::= function |
| @@ -676,7 +675,7 @@ The basic expressions in Lua are the following: · 1 unmodified line |
| 676 | exp ::= `<b>...</b>´ | 675 | exp ::= `<b>...</b>´ |
| 677 | exp ::= exp binop exp | 676 | exp ::= exp binop exp |
| 678 | exp ::= unop exp | 677 | exp ::= unop exp |
| 679 | prefixexp ::= var | functioncall | `<b>(</b>´ exp `<b>)</b>´ | 678 | prefixexp ::= var | functioncall | `<b>(</b>´ exp `<b>)</b>´ |
| 680 | </pre> | 679 | </pre> |
| 681 | | 680 | |
| 682 | <p>Numbers and literal strings are explained in <a href="#lexical">2.1</a>; | 681 | <p>Numbers and literal strings are explained in <a href="#lexical">2.1</a>; |
| @@ -710,7 +709,7 @@ then no adjustment is made, · 27 unmodified lines |
| 710 | unless the call is enclosed in parentheses. | 709 | unless the call is enclosed in parentheses. |
| 711 | | 710 | |
| 712 | <p>Here are some examples: | 711 | <p>Here are some examples: |
| 713 | <PRE> | 712 | <pre> |
| 714 | f() -- adjusted to 0 results | 713 | f() -- adjusted to 0 results |
| 715 | g(f(), x) -- f() is adjusted to 1 result | 714 | g(f(), x) -- f() is adjusted to 1 result |
| 716 | g(x, f()) -- g gets x plus all values returned by f() | 715 | g(x, f()) -- g gets x plus all values returned by f() |
| @@ -726,14 +725,14 @@ unless the call is enclosed in parentheses. · 9 unmodified lines |
| 726 | {f()} -- creates a list with all values returned by f() | 725 | {f()} -- creates a list with all values returned by f() |
| 727 | {...} -- creates a list with all vararg parameters | 726 | {...} -- creates a list with all vararg parameters |
| 728 | {f(), nil} -- f() is adjusted to 1 result | 727 | {f(), nil} -- f() is adjusted to 1 result |
| 729 | </PRE> | 728 | </pre> |
| 730 | | 729 | |
| 731 | <p>An expression enclosed in parentheses always results in only one value. | 730 | <p>An expression enclosed in parentheses always results in only one value. |
| 732 | Thus, | 731 | Thus, |
| 733 | <code>(f(x,y,z))</code> is always a single value, | 732 | <code>(f(x,y,z))</code> is always a single value, |
| 734 | even if <code>f</code> returns several values. | 733 | even if <code>f</code> returns several values. |
| 735 | (The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code> | 734 | (The value of <code>(f(x,y,z))</code> is the first value returned by <code>f</code> |
| 736 | or <B>nil</B> if <code>f</code> does not return any values.) | 735 | or <b>nil</b> if <code>f</code> does not return any values.) |
| 737 | | 736 | |
| 738 | <p><a name="arith"></a><a name="2.5.1"></a><h3>2.5.1 - Arithmetic Operators</h3> | 737 | <p><a name="arith"></a><a name="2.5.1"></a><h3>2.5.1 - Arithmetic Operators</h3> |
| 739 | Lua supports the usual arithmetic operators: | 738 | Lua supports the usual arithmetic operators: |
| @@ -747,21 +746,21 @@ then all operations have the usual meaning. · 7 unmodified lines |
| 747 | Exponentiation works for any exponent. | 746 | Exponentiation works for any exponent. |
| 748 | For instance, <code>x^-0.5</code> computes the inverse of the square root of <code>x</code>. | 747 | For instance, <code>x^-0.5</code> computes the inverse of the square root of <code>x</code>. |
| 749 | Modulus is defined as | 748 | Modulus is defined as |
| 750 | <PRE> | 749 | <pre> |
| 751 | a % b == a - math.floor(a/b)*b | 750 | a % b == a - math.floor(a/b)*b |
| 752 | </PRE> | 751 | </pre> |
| 753 | That is, it is the remaining of a division that rounds | 752 | That is, it is the remaining of a division that rounds |
| 754 | the quotient towards minus infinity. | 753 | the quotient towards minus infinity. |
| 755 | | 754 | |
| 756 | <p><a name="rel-ops"></a><a name="2.5.2"></a><h3>2.5.2 - Relational Operators</h3> | 755 | <p><a name="rel-ops"></a><a name="2.5.2"></a><h3>2.5.2 - Relational Operators</h3> |
| 757 | The relational operators in Lua are | 756 | The relational operators in Lua are |
| 758 | <PRE> | 757 | <pre> |
| 759 | == ~= < > <= >= | 758 | == ~= < > <= >= |
| 760 | </PRE> | 759 | </pre> |
| 761 | These operators always result in <B>false</B> or <B>true</B>. | 760 | These operators always result in <b>false</b> or <b>true</b>. |
| 762 | | 761 | |
| 763 | <p>Equality (<code>==</code>) first compares the type of its operands. | 762 | <p>Equality (<code>==</code>) first compares the type of its operands. |
| 764 | If the types are different, then the result is <B>false</B>. | 763 | If the types are different, then the result is <b>false</b>. |
| 765 | Otherwise, the values of the operands are compared. | 764 | Otherwise, the values of the operands are compared. |
| 766 | Numbers and strings are compared in the usual way. | 765 | Numbers and strings are compared in the usual way. |
| 767 | Objects (tables, userdata, threads, and functions) | 766 | Objects (tables, userdata, threads, and functions) |
| @@ -775,7 +774,7 @@ using the "eq" metamethod (see <a href="#metatable">2.8</a>). · 7 unmodified lines |
| 775 | | 774 | |
| 776 | <p>The conversion rules of <a href="#coercion">2.2.1</a> | 775 | <p>The conversion rules of <a href="#coercion">2.2.1</a> |
| 777 | <em>do not</em> apply to equality comparisons. | 776 | <em>do not</em> apply to equality comparisons. |
| 778 | Thus, <code>"0"==0</code> evaluates to <B>false</B>, | 777 | Thus, <code>"0"==0</code> evaluates to <b>false</b>, |
| 779 | and <code>t[0]</code> and <code>t["0"]</code> denote different | 778 | and <code>t[0]</code> and <code>t["0"]</code> denote different |
| 780 | entries in a table. | 779 | entries in a table. |
| 781 | | 780 | |
| @@ -792,27 +791,27 @@ metamethod (see <a href="#metatable">2.8</a>). · 10 unmodified lines |
| 792 | <p><a name="logic"></a><a name="2.5.3"></a><h3>2.5.3 - Logical Operators</h3> | 791 | <p><a name="logic"></a><a name="2.5.3"></a><h3>2.5.3 - Logical Operators</h3> |
| 793 | The logical operators in Lua are | 792 | The logical operators in Lua are |
| 794 | | 793 | |
| 795 | <PRE> | 794 | <pre> |
| 796 | and or not | 795 | and or not |
| 797 | </PRE> | 796 | </pre> |
| 798 | Like the control structures (see <a href="#control">2.4.4</a>), | 797 | Like the control structures (see <a href="#control">2.4.4</a>), |
| 799 | all logical operators consider both <B>false</B> and <B>nil</B> as false | 798 | all logical operators consider both <b>false</b> and <b>nil</b> as false |
| 800 | and anything else as true. | 799 | and anything else as true. |
| 801 | | 800 | |
| 802 | | 801 | |
| 803 | <p>The operator <b>not</b> always returns <B>false</B> or <B>true</B>. | 802 | <p>The operator <b>not</b> always returns <b>false</b> or <b>true</b>. |
| 804 | | 803 | |
| 805 | <p>The conjunction operator <b>and</b> returns its first argument | 804 | <p>The conjunction operator <b>and</b> returns its first argument |
| 806 | if this value is <B>false</B> or <B>nil</B>; | 805 | if this value is <b>false</b> or <b>nil</b>; |
| 807 | otherwise, <b>and</b> returns its second argument. | 806 | otherwise, <b>and</b> returns its second argument. |
| 808 | The disjunction operator <b>or</b> returns its first argument | 807 | The disjunction operator <b>or</b> returns its first argument |
| 809 | if this value is different from <B>nil</B> and <B>false</B>; | 808 | if this value is different from <b>nil</b> and <b>false</b>; |
| 810 | otherwise, <b>or</b> returns its second argument. | 809 | otherwise, <b>or</b> returns its second argument. |
| 811 | Both <b>and</b> and <b>or</b> use short-cut evaluation, | 810 | Both <b>and</b> and <b>or</b> use short-cut evaluation, |
| 812 | that is, | 811 | that is, |
| 813 | the second operand is evaluated only if necessary. | 812 | the second operand is evaluated only if necessary. |
| 814 | For example, | 813 | For example, |
| 815 | <PRE> | 814 | <pre> |
| 816 | 10 or error() -> 10 | 815 | 10 or error() -> 10 |
| 817 | nil or "a" -> "a" | 816 | nil or "a" -> "a" |
| 818 | nil and 10 -> nil | 817 | nil and 10 -> nil |
| @@ -820,7 +819,7 @@ For example, · 1 unmodified line |
| 820 | false and nil -> false | 819 | false and nil -> false |
| 821 | false or nil -> nil | 820 | false or nil -> nil |
| 822 | 10 and 20 -> 20 | 821 | 10 and 20 -> 20 |
| 823 | </PRE> | 822 | </pre> |
| 824 | | 823 | |
| 825 | <p><a name="concat"></a><a name="2.5.4"></a><h3>2.5.4 - Concatenation</h3> | 824 | <p><a name="concat"></a><a name="2.5.4"></a><h3>2.5.4 - Concatenation</h3> |
| 826 | The string concatenation operator in Lua is | 825 | The string concatenation operator in Lua is |
| @@ -837,22 +836,22 @@ The length of a string is its number of bytes · 10 unmodified lines |
| 837 | character is one byte). | 836 | character is one byte). |
| 838 | The length of a table <code>t</code> is defined to be any | 837 | The length of a table <code>t</code> is defined to be any |
| 839 | integer index <code>n</code> | 838 | integer index <code>n</code> |
| 840 | such that <code>t[n]</code> is not <B>nil</B> and <code>t[n+1]</code> is <B>nil</B>; | 839 | such that <code>t[n]</code> is not <b>nil</b> and <code>t[n+1]</code> is <b>nil</b>; |
| 841 | moreover, if <code>t[1]</code> is <B>nil</B>, <code>n</code> may be zero. | 840 | moreover, if <code>t[1]</code> is <b>nil</b>, <code>n</code> may be zero. |
| 842 | | 841 | |
| 843 | <p>For a regular array, with non-nil values from 1 to a given <code>n</code>, | 842 | <p>For a regular array, with non-nil values from 1 to a given <code>n</code>, |
| 844 | its length is exactly that <code>n</code>, | 843 | its length is exactly that <code>n</code>, |
| 845 | the index of its last value. | 844 | the index of its last value. |
| 846 | If the array has "holes" | 845 | If the array has "holes" |
| 847 | (that is, <B>nil</B> values between other non-nil values), | 846 | (that is, <b>nil</b> values between other non-nil values), |
| 848 | then <code>#t</code> may be any of the indices that precede a <B>nil</B> value | 847 | then <code>#t</code> may be any of the indices that precede a <b>nil</b> value |
| 849 | (that is, it may consider any such <B>nil</B> value as the end of | 848 | (that is, it may consider any such <b>nil</b> value as the end of |
| 850 | the array). | 849 | the array). |
| 851 | | 850 | |
| 852 | <p><a name="2.5.6"></a><h3>2.5.6 - Precedence</h3> | 851 | <p><a name="2.5.6"></a><h3>2.5.6 - Precedence</h3> |
| 853 | Operator precedence in Lua follows the table below, | 852 | Operator precedence in Lua follows the table below, |
| 854 | from lower to higher priority: | 853 | from lower to higher priority: |
| 855 | <PRE> | 854 | <pre> |
| 856 | or | 855 | or |
| 857 | and | 856 | and |
| 858 | < > <= >= ~= == | 857 | < > <= >= ~= == |
| @@ -861,7 +860,7 @@ from lower to higher priority: · 2 unmodified lines |
| 861 | * / % | 860 | * / % |
| 862 | not # - (unary) | 861 | not # - (unary) |
| 863 | ^ | 862 | ^ |
| 864 | </PRE> | 863 | </pre> |
| 865 | You can use parentheses to change the precedences of an expression. | 864 | You can use parentheses to change the precedences of an expression. |
| 866 | The concatenation (`<code>..</code>´) and exponentiation (`<code>^</code>´) | 865 | The concatenation (`<code>..</code>´) and exponentiation (`<code>^</code>´) |
| 867 | operators are right associative. | 866 | operators are right associative. |
| @@ -876,8 +875,8 @@ The general syntax for constructors is · 8 unmodified lines |
| 876 | <pre> | 875 | <pre> |
| 877 | tableconstructor ::= `<b>{</b>´ [fieldlist] `<b>}</b>´ | 876 | tableconstructor ::= `<b>{</b>´ [fieldlist] `<b>}</b>´ |
| 878 | fieldlist ::= field {fieldsep field} [fieldsep] | 877 | fieldlist ::= field {fieldsep field} [fieldsep] |
| 879 | field ::= `<b>[</b>´ exp `<b>]</b>´ `<b>=</b>´ exp | Name `<b>=</b>´ exp | exp | 878 | field ::= `<b>[</b>´ exp `<b>]</b>´ `<b>=</b>´ exp | Name `<b>=</b>´ exp | exp |
| 880 | fieldsep ::= `<b>,</b>´ | `<b>;</b>´ | 879 | fieldsep ::= `<b>,</b>´ | `<b>;</b>´ |
| 881 | </pre> | 880 | </pre> |
| 882 | | 881 | |
| 883 | <p>Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry | 882 | <p>Each field of the form <code>[exp1] = exp2</code> adds to the new table an entry |
| @@ -889,11 +888,11 @@ Finally, fields of the form <code>exp</code> are equivalent to · 5 unmodified lines |
| 889 | starting with 1. | 888 | starting with 1. |
| 890 | Fields in the other formats do not affect this counting. | 889 | Fields in the other formats do not affect this counting. |
| 891 | For example, | 890 | For example, |
| 892 | <PRE> | 891 | <pre> |
| 893 | a = {[f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45} | 892 | a = {[f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45} |
| 894 | </PRE> | 893 | </pre> |
| 895 | is equivalent to | 894 | is equivalent to |
| 896 | <PRE> | 895 | <pre> |
| 897 | do | 896 | do |
| 898 | local temp = {} | 897 | local temp = {} |
| 899 | temp[f(1)] = g | 898 | temp[f(1)] = g |
| @@ -905,7 +904,7 @@ is equivalent to · 5 unmodified lines |
| 905 | temp[4] = 45 -- 4th exp | 904 | temp[4] = 45 -- 4th exp |
| 906 | a = temp | 905 | a = temp |
| 907 | end | 906 | end |
| 908 | </PRE> | 907 | </pre> |
| 909 | | 908 | |
| 910 | <p>If the last field in the list has the form <code>exp</code> | 909 | <p>If the last field in the list has the form <code>exp</code> |
| 911 | and the expression is a function call or a vararg expression, | 910 | and the expression is a function call or a vararg expression, |
| @@ -961,10 +960,10 @@ the argument list is a single literal string. · 49 unmodified lines |
| 961 | you cannot put a line break before the `<code>(</code>´ in a function call. | 960 | you cannot put a line break before the `<code>(</code>´ in a function call. |
| 962 | That restriction avoids some ambiguities in the language. | 961 | That restriction avoids some ambiguities in the language. |
| 963 | If you write | 962 | If you write |
| 964 | <PRE> | 963 | <pre> |
| 965 | a = f | 964 | a = f |
| 966 | (g).x(a) | 965 | (g).x(a) |
| 967 | </PRE> | 966 | </pre> |
| 968 | Lua would read that as <code>a = f(g).x(a)</code>. | 967 | Lua would read that as <code>a = f(g).x(a)</code>. |
| 969 | So, if you want two statements, you must add a semi-colon between them. | 968 | So, if you want two statements, you must add a semi-colon between them. |
| 970 | If you actually want to call <code>f</code>, | 969 | If you actually want to call <code>f</code>, |
| @@ -985,13 +984,13 @@ where the <b>return</b> has one single function call as argument; · 14 unmodified lines |
| 985 | this syntax makes the calling function returns exactly | 984 | this syntax makes the calling function returns exactly |
| 986 | the returns of the called function. | 985 | the returns of the called function. |
| 987 | So, all the following examples are not tail calls: | 986 | So, all the following examples are not tail calls: |
| 988 | <PRE> | 987 | <pre> |
| 989 | return (f(x)) -- results adjusted to 1 | 988 | return (f(x)) -- results adjusted to 1 |
| 990 | return 2 * f(x) | 989 | return 2 * f(x) |
| 991 | return x, f(x) -- additional results | 990 | return x, f(x) -- additional results |
| 992 | f(x); return -- results discarded | 991 | f(x); return -- results discarded |
| 993 | return x or f(x) -- results adjusted to 1 | 992 | return x or f(x) -- results adjusted to 1 |
| 994 | </PRE> | 993 | </pre> |
| 995 | | 994 | |
| 996 | <p><a name="func-def"></a><a name="2.5.9"></a><h3>2.5.9 - Function Definitions</h3> | 995 | <p><a name="func-def"></a><a name="2.5.9"></a><h3>2.5.9 - Function Definitions</h3> |
| 997 | | 996 | |
| @@ -1008,29 +1007,29 @@ So, all the following examples are not tail calls: · 10 unmodified lines |
| 1008 | funcname ::= Name {`<b>.</b>´ Name} [`<b>:</b>´ Name] | 1007 | funcname ::= Name {`<b>.</b>´ Name} [`<b>:</b>´ Name] |
| 1009 | </pre> | 1008 | </pre> |
| 1010 | The statement | 1009 | The statement |
| 1011 | <PRE> | 1010 | <pre> |
| 1012 | function f () ... end | 1011 | function f () ... end |
| 1013 | </PRE> | 1012 | </pre> |
| 1014 | translates to | 1013 | translates to |
| 1015 | <PRE> | 1014 | <pre> |
| 1016 | f = function () ... end | 1015 | f = function () ... end |
| 1017 | </PRE> | 1016 | </pre> |
| 1018 | The statement | 1017 | The statement |
| 1019 | <PRE> | 1018 | <pre> |
| 1020 | function t.a.b.c.f () ... end | 1019 | function t.a.b.c.f () ... end |
| 1021 | </PRE> | 1020 | </pre> |
| 1022 | translates to | 1021 | translates to |
| 1023 | <PRE> | 1022 | <pre> |
| 1024 | t.a.b.c.f = function () ... end | 1023 | t.a.b.c.f = function () ... end |
| 1025 | </PRE> | 1024 | </pre> |
| 1026 | The statement | 1025 | The statement |
| 1027 | <PRE> | 1026 | <pre> |
| 1028 | local function f () ... end | 1027 | local function f () ... end |
| 1029 | </PRE> | 1028 | </pre> |
| 1030 | translates to | 1029 | translates to |
| 1031 | <PRE> | 1030 | <pre> |
| 1032 | local f; f = function () ... end | 1031 | local f; f = function () ... end |
| 1033 | </PRE> | 1032 | </pre> |
| 1034 | | 1033 | |
| 1035 | <p>A function definition is an executable expression, | 1034 | <p>A function definition is an executable expression, |
| 1036 | whose value has type <em>function</em>. | 1035 | whose value has type <em>function</em>. |
| @@ -1047,7 +1046,7 @@ and may have different environment tables. · 10 unmodified lines |
| 1047 | <p>Parameters act as local variables that are | 1046 | <p>Parameters act as local variables that are |
| 1048 | initialized with the argument values: | 1047 | initialized with the argument values: |
| 1049 | <pre> | 1048 | <pre> |
| 1050 | parlist1 ::= namelist [`<b>,</b>´ `<b>...</b>´] | `<b>...</b>´ | 1049 | parlist1 ::= namelist [`<b>,</b>´ `<b>...</b>´] | `<b>...</b>´ |
| 1051 | </pre> | 1050 | </pre> |
| 1052 | When a function is called, | 1051 | When a function is called, |
| 1053 | the list of arguments is adjusted to | 1052 | the list of arguments is adjusted to |
| @@ -1069,14 +1068,14 @@ then no adjustment is made · 15 unmodified lines |
| 1069 | (unless the call is enclosed in parentheses). | 1068 | (unless the call is enclosed in parentheses). |
| 1070 | | 1069 | |
| 1071 | <p>As an example, consider the following definitions: | 1070 | <p>As an example, consider the following definitions: |
| 1072 | <PRE> | 1071 | <pre> |
| 1073 | function f(a, b) end | 1072 | function f(a, b) end |
| 1074 | function g(a, b, ...) end | 1073 | function g(a, b, ...) end |
| 1075 | function r() return 1,2,3 end | 1074 | function r() return 1,2,3 end |
| 1076 | </PRE> | 1075 | </pre> |
| 1077 | Then, we have the following mapping from arguments to parameters and | 1076 | Then, we have the following mapping from arguments to parameters and |
| 1078 | to the vararg expression: | 1077 | to the vararg expression: |
| 1079 | <PRE> | 1078 | <pre> |
| 1080 | CALL PARAMETERS | 1079 | CALL PARAMETERS |
| 1081 | | 1080 | |
| 1082 | f(3) a=3, b=nil | 1081 | f(3) a=3, b=nil |
| @@ -1089,7 +1088,7 @@ to the vararg expression: · 6 unmodified lines |
| 1089 | g(3, 4) a=3, b=4, ... -> (nothing) | 1088 | g(3, 4) a=3, b=4, ... -> (nothing) |
| 1090 | g(3, 4, 5, 8) a=3, b=4, ... -> 5 8 | 1089 | g(3, 4, 5, 8) a=3, b=4, ... -> 5 8 |
| 1091 | g(5, r()) a=5, b=1, ... -> 2 3 | 1090 | g(5, r()) a=5, b=1, ... -> 2 3 |
| 1092 | </PRE> | 1091 | </pre> |
| 1093 | | 1092 | |
| 1094 | <p>Results are returned using the <b>return</b> statement (see <a href="#control">2.4.4</a>). | 1093 | <p>Results are returned using the <b>return</b> statement (see <a href="#control">2.4.4</a>). |
| 1095 | If control reaches the end of a function | 1094 | If control reaches the end of a function |
| @@ -1100,13 +1099,13 @@ then the function returns with no results. · 4 unmodified lines |
| 1100 | is used for defining <em>methods</em>, | 1099 | is used for defining <em>methods</em>, |
| 1101 | that is, functions that have an implicit extra parameter <code>self</code>. | 1100 | that is, functions that have an implicit extra parameter <code>self</code>. |
| 1102 | Thus, the statement | 1101 | Thus, the statement |
| 1103 | <PRE> | 1102 | <pre> |
| 1104 | function t.a.b.c:f (...) ... end | 1103 | function t.a.b.c:f (...) ... end |
| 1105 | </PRE> | 1104 | </pre> |
| 1106 | is syntactic sugar for | 1105 | is syntactic sugar for |
| 1107 | <PRE> | 1106 | <pre> |
| 1108 | t.a.b.c.f = function (self, ...) ... end | 1107 | t.a.b.c.f = function (self, ...) ... end |
| 1109 | </PRE> | 1108 | </pre> |
| 1110 | | 1109 | |
| 1111 | <p><a name="visibility"></a><a name="2.6"></a><h2>2.6 - Visibility Rules</h2> | 1110 | <p><a name="visibility"></a><a name="2.6"></a><h2>2.6 - Visibility Rules</h2> |
| 1112 | | 1111 | |
| @@ -1116,7 +1115,7 @@ The scope of variables begins at the first statement <em>after</em> · 3 unmodified lines |
| 1116 | their declaration and lasts until the end of the innermost block that | 1115 | their declaration and lasts until the end of the innermost block that |
| 1117 | includes the declaration. | 1116 | includes the declaration. |
| 1118 | For instance: | 1117 | For instance: |
| 1119 | <PRE> | 1118 | <pre> |
| 1120 | x = 10 -- global variable | 1119 | x = 10 -- global variable |
| 1121 | do -- new block | 1120 | do -- new block |
| 1122 | local x = x -- new `x', with value 10 | 1121 | local x = x -- new `x', with value 10 |
| @@ -1129,7 +1128,7 @@ For instance: · 6 unmodified lines |
| 1129 | print(x) --> 11 | 1128 | print(x) --> 11 |
| 1130 | end | 1129 | end |
| 1131 | print(x) --> 10 (the global one) | 1130 | print(x) --> 10 (the global one) |
| 1132 | </PRE> | 1131 | </pre> |
| 1133 | Notice that, in a declaration like <code>local x = x</code>, | 1132 | Notice that, in a declaration like <code>local x = x</code>, |
| 1134 | the new <code>x</code> being declared is not in scope yet, | 1133 | the new <code>x</code> being declared is not in scope yet, |
| 1135 | and so the second <code>x</code> refers to the outside variable. | 1134 | and so the second <code>x</code> refers to the outside variable. |
| @@ -1138,13 +1137,13 @@ and so the second <code>x</code> refers to the outside variable. · 2 unmodified lines |
| 1138 | local variables can be freely accessed by functions | 1137 | local variables can be freely accessed by functions |
| 1139 | defined inside their scope. | 1138 | defined inside their scope. |
| 1140 | For instance: | 1139 | For instance: |
| 1141 | <PRE> | 1140 | <pre> |
| 1142 | local counter = 0 | 1141 | local counter = 0 |
| 1143 | function inc (x) | 1142 | function inc (x) |
| 1144 | counter = counter + x | 1143 | counter = counter + x |
| 1145 | return counter | 1144 | return counter |
| 1146 | end | 1145 | end |
| 1147 | </PRE> | 1146 | </pre> |
| 1148 | A local variable used by an inner function is called | 1147 | A local variable used by an inner function is called |
| 1149 | an <em>upvalue</em>, or <em>external local variable</em>, | 1148 | an <em>upvalue</em>, or <em>external local variable</em>, |
| 1150 | inside the inner function. | 1149 | inside the inner function. |
| @@ -1152,14 +1151,14 @@ inside the inner function. · 1 unmodified line |
| 1152 | <p>Notice that each execution of a <b>local</b> statement | 1151 | <p>Notice that each execution of a <b>local</b> statement |
| 1153 | defines new local variables. | 1152 | defines new local variables. |
| 1154 | Consider the following example: | 1153 | Consider the following example: |
| 1155 | <PRE> | 1154 | <pre> |
| 1156 | a = {} | 1155 | a = {} |
| 1157 | local x = 20 | 1156 | local x = 20 |
| 1158 | for i=1,10 do | 1157 | for i=1,10 do |
| 1159 | local y = 0 | 1158 | local y = 0 |
| 1160 | a[i] = function () y=y+1; return x+y end | 1159 | a[i] = function () y=y+1; return x+y end |
| 1161 | end | 1160 | end |
| 1162 | </PRE> | 1161 | </pre> |
| 1163 | The loop creates ten closures | 1162 | The loop creates ten closures |
| 1164 | (that is, ten instances of the anonymous function). | 1163 | (that is, ten instances of the anonymous function). |
| 1165 | Each of these closures uses a different <code>y</code> variable, | 1164 | Each of these closures uses a different <code>y</code> variable, |
| @@ -1243,16 +1242,16 @@ All functions used in these descriptions · 77 unmodified lines |
| 1243 | are described in <a href="#predefined">5.1</a>. | 1242 | are described in <a href="#predefined">5.1</a>. |
| 1244 | In particular, to retrieve the metamethod of a given object, | 1243 | In particular, to retrieve the metamethod of a given object, |
| 1245 | we use the expression | 1244 | we use the expression |
| 1246 | <PRE> | 1245 | <pre> |
| 1247 | metatable(obj)[event] | 1246 | metatable(obj)[event] |
| 1248 | </PRE> | 1247 | </pre> |
| 1249 | This should be read as | 1248 | This should be read as |
| 1250 | <PRE> | 1249 | <pre> |
| 1251 | rawget(metatable(obj) or {}, event) | 1250 | rawget(metatable(obj) or {}, event) |
| 1252 | </PRE> | 1251 | </pre> |
| 1253 | That is, the access to a metamethod does not invoke other metamethods, | 1252 | That is, the access to a metamethod does not invoke other metamethods, |
| 1254 | and the access to objects with no metatables does not fail | 1253 | and the access to objects with no metatables does not fail |
| 1255 | (it simply results in <B>nil</B>). | 1254 | (it simply results in <b>nil</b>). |
| 1256 | | 1255 | |
| 1257 | <p><ul> | 1256 | <p><ul> |
| 1258 | <li><b>"add":</b> | 1257 | <li><b>"add":</b> |
| @@ -1263,14 +1262,14 @@ for a binary operation. · 4 unmodified lines |
| 1263 | First, Lua tries the first operand. | 1262 | First, Lua tries the first operand. |
| 1264 | If its type does not define a handler for the operation, | 1263 | If its type does not define a handler for the operation, |
| 1265 | then Lua tries the second operand. | 1264 | then Lua tries the second operand. |
| 1266 | <PRE> | 1265 | <pre> |
| 1267 | function getbinhandler (op1, op2, event) | 1266 | function getbinhandler (op1, op2, event) |
| 1268 | return metatable(op1)[event] or metatable(op2)[event] | 1267 | return metatable(op1)[event] or metatable(op2)[event] |
| 1269 | end | 1268 | end |
| 1270 | </PRE> | 1269 | </pre> |
| 1271 | Using that function, | 1270 | Using that function, |
| 1272 | the behavior of the <code>op1 + op2</code> is | 1271 | the behavior of the <code>op1 + op2</code> is |
| 1273 | <PRE> | 1272 | <pre> |
| 1274 | function add_event (op1, op2) | 1273 | function add_event (op1, op2) |
| 1275 | local o1, o2 = tonumber(op1), tonumber(op2) | 1274 | local o1, o2 = tonumber(op1), tonumber(op2) |
| 1276 | if o1 and o2 then -- both operands are numeric? | 1275 | if o1 and o2 then -- both operands are numeric? |
| @@ -1285,7 +1284,7 @@ the behavior of the <code>op1 + op2</code> is · 8 unmodified lines |
| 1285 | end | 1284 | end |
| 1286 | end | 1285 | end |
| 1287 | end | 1286 | end |
| 1288 | </PRE> | 1287 | </pre> |
| 1289 | | 1288 | |
| 1290 | <p><li><b>"sub":</b> | 1289 | <p><li><b>"sub":</b> |
| 1291 | the <code>-</code> operation. | 1290 | the <code>-</code> operation. |
| @@ -1313,7 +1312,7 @@ as the primitive operation. · 21 unmodified lines |
| 1313 | | 1312 | |
| 1314 | <p><li><b>"unm":</b> | 1313 | <p><li><b>"unm":</b> |
| 1315 | the unary <code>-</code> operation. | 1314 | the unary <code>-</code> operation. |
| 1316 | <PRE> | 1315 | <pre> |
| 1317 | function unm_event (op) | 1316 | function unm_event (op) |
| 1318 | local o = tonumber(op) | 1317 | local o = tonumber(op) |
| 1319 | if o then -- operand is numeric? | 1318 | if o then -- operand is numeric? |
| @@ -1329,11 +1328,11 @@ the unary <code>-</code> operation. · 9 unmodified lines |
| 1329 | end | 1328 | end |
| 1330 | end | 1329 | end |
| 1331 | end | 1330 | end |
| 1332 | </PRE> | 1331 | </pre> |
| 1333 | | 1332 | |
| 1334 | <p><li><b>"concat":</b> | 1333 | <p><li><b>"concat":</b> |
| 1335 | the <code>..</code> (concatenation) operation. | 1334 | the <code>..</code> (concatenation) operation. |
| 1336 | <PRE> | 1335 | <pre> |
| 1337 | function concat_event (op1, op2) | 1336 | function concat_event (op1, op2) |
| 1338 | if (type(op1) == "string" or type(op1) == "number") and | 1337 | if (type(op1) == "string" or type(op1) == "number") and |
| 1339 | (type(op2) == "string" or type(op2) == "number") then | 1338 | (type(op2) == "string" or type(op2) == "number") then |
| @@ -1347,11 +1346,11 @@ the <code>..</code> (concatenation) operation. · 7 unmodified lines |
| 1347 | end | 1346 | end |
| 1348 | end | 1347 | end |
| 1349 | end | 1348 | end |
| 1350 | </PRE> | 1349 | </pre> |
| 1351 | | 1350 | |
| 1352 | <p><li><b>"len":</b> | 1351 | <p><li><b>"len":</b> |
| 1353 | the <code>#</code> operation. | 1352 | the <code>#</code> operation. |
| 1354 | <PRE> | 1353 | <pre> |
| 1355 | function len_event (op) | 1354 | function len_event (op) |
| 1356 | if type(op) == "string" then | 1355 | if type(op) == "string" then |
| 1357 | return strlen(op) -- primitive string length | 1356 | return strlen(op) -- primitive string length |
| @@ -1367,7 +1366,7 @@ the <code>#</code> operation. · 9 unmodified lines |
| 1367 | end | 1366 | end |
| 1368 | end | 1367 | end |
| 1369 | end | 1368 | end |
| 1370 | </PRE> | 1369 | </pre> |
| 1371 | See <a href="#len-op">2.5.5</a> for a description of the length of a table. | 1370 | See <a href="#len-op">2.5.5</a> for a description of the length of a table. |
| 1372 | | 1371 | |
| 1373 | <p><li><b>"eq":</b> | 1372 | <p><li><b>"eq":</b> |
| @@ -1377,16 +1376,16 @@ for comparison operators. · 3 unmodified lines |
| 1377 | A metamethod only is selected when both objects | 1376 | A metamethod only is selected when both objects |
| 1378 | being compared have the same type | 1377 | being compared have the same type |
| 1379 | and the same metamethod for the selected operation. | 1378 | and the same metamethod for the selected operation. |
| 1380 | <PRE> | 1379 | <pre> |
| 1381 | function getcomphandler (op1, op2, event) | 1380 | function getcomphandler (op1, op2, event) |
| 1382 | if type(op1) ~= type(op2) then return nil end | 1381 | if type(op1) ~= type(op2) then return nil end |
| 1383 | local mm1 = metatable(op1)[event] | 1382 | local mm1 = metatable(op1)[event] |
| 1384 | local mm2 = metatable(op2)[event] | 1383 | local mm2 = metatable(op2)[event] |
| 1385 | if mm1 == mm2 then return mm1 else return nil end | 1384 | if mm1 == mm2 then return mm1 else return nil end |
| 1386 | end | 1385 | end |
| 1387 | </PRE> | 1386 | </pre> |
| 1388 | The "eq" event is defined as follows: | 1387 | The "eq" event is defined as follows: |
| 1389 | <PRE> | 1388 | <pre> |
| 1390 | function eq_event (op1, op2) | 1389 | function eq_event (op1, op2) |
| 1391 | if type(op1) ~= type(op2) then -- different types? | 1390 | if type(op1) ~= type(op2) then -- different types? |
| 1392 | return false -- different objects | 1391 | return false -- different objects |
| @@ -1402,12 +1401,12 @@ The "eq" event is defined as follows: · 9 unmodified lines |
| 1402 | return false | 1401 | return false |
| 1403 | end | 1402 | end |
| 1404 | end | 1403 | end |
| 1405 | </PRE> | 1404 | </pre> |
| 1406 | <code>a ~= b</code> is equivalent to <code>not (a == b)</code>. | 1405 | <code>a ~= b</code> is equivalent to <code>not (a == b)</code>. |
| 1407 | | 1406 | |
| 1408 | <p><li><b>"lt":</b> | 1407 | <p><li><b>"lt":</b> |
| 1409 | the <code><</code> operation. | 1408 | the <code><</code> operation. |
| 1410 | <PRE> | 1409 | <pre> |
| 1411 | function lt_event (op1, op2) | 1410 | function lt_event (op1, op2) |
| 1412 | if type(op1) == "number" and type(op2) == "number" then | 1411 | if type(op1) == "number" and type(op2) == "number" then |
| 1413 | return op1 < op2 -- numeric comparison | 1412 | return op1 < op2 -- numeric comparison |
| @@ -1422,12 +1421,12 @@ the <code><</code> operation. · 8 unmodified lines |
| 1422 | end | 1421 | end |
| 1423 | end | 1422 | end |
| 1424 | end | 1423 | end |
| 1425 | </PRE> | 1424 | </pre> |
| 1426 | <code>a > b</code> is equivalent to <code>b < a</code>. | 1425 | <code>a > b</code> is equivalent to <code>b < a</code>. |
| 1427 | | 1426 | |
| 1428 | <p><li><b>"le":</b> | 1427 | <p><li><b>"le":</b> |
| 1429 | the <code><=</code> operation. | 1428 | the <code><=</code> operation. |
| 1430 | <PRE> | 1429 | <pre> |
| 1431 | function le_event (op1, op2) | 1430 | function le_event (op1, op2) |
| 1432 | if type(op1) == "number" and type(op2) == "number" then | 1431 | if type(op1) == "number" and type(op2) == "number" then |
| 1433 | return op1 <= op2 -- numeric comparison | 1432 | return op1 <= op2 -- numeric comparison |
| @@ -1447,7 +1446,7 @@ the <code><=</code> operation. · 13 unmodified lines |
| 1447 | end | 1446 | end |
| 1448 | end | 1447 | end |
| 1449 | end | 1448 | end |
| 1450 | </PRE> | 1449 | </pre> |
| 1451 | <code>a >= b</code> is equivalent to <code>b <= a</code>. | 1450 | <code>a >= b</code> is equivalent to <code>b <= a</code>. |
| 1452 | Note that, in the absence of a "le" metamethod, | 1451 | Note that, in the absence of a "le" metamethod, |
| 1453 | Lua tries the "lt", assuming that <code>a <= b</code> is | 1452 | Lua tries the "lt", assuming that <code>a <= b</code> is |
| @@ -1455,7 +1454,7 @@ equivalent to <code>not (b < a)</code>. · 1 unmodified line |
| 1455 | | 1454 | |
| 1456 | <p><li><b>"index":</b> | 1455 | <p><li><b>"index":</b> |
| 1457 | The indexing access <code>table[key]</code>. | 1456 | The indexing access <code>table[key]</code>. |
| 1458 | <PRE> | 1457 | <pre> |
| 1459 | function gettable_event (table, key) | 1458 | function gettable_event (table, key) |
| 1460 | local h | 1459 | local h |
| 1461 | if type(table) == "table" then | 1460 | if type(table) == "table" then |
| @@ -1474,11 +1473,11 @@ The indexing access <code>table[key]</code>. · 12 unmodified lines |
| 1474 | else return h[key] -- or repeat operation on it | 1473 | else return h[key] -- or repeat operation on it |
| 1475 | end | 1474 | end |
| 1476 | end | 1475 | end |
| 1477 | </PRE> | 1476 | </pre> |
| 1478 | | 1477 | |
| 1479 | <p><li><b>"newindex":</b> | 1478 | <p><li><b>"newindex":</b> |
| 1480 | The indexing assignment <code>table[key] = value</code>. | 1479 | The indexing assignment <code>table[key] = value</code>. |
| 1481 | <PRE> | 1480 | <pre> |
| 1482 | function settable_event (table, key, value) | 1481 | function settable_event (table, key, value) |
| 1483 | local h | 1482 | local h |
| 1484 | if type(table) == "table" then | 1483 | if type(table) == "table" then |
| @@ -1497,11 +1496,11 @@ The indexing assignment <code>table[key] = value</code>. · 12 unmodified lines |
| 1497 | else h[key] = value -- or repeat operation on it | 1496 | else h[key] = value -- or repeat operation on it |
| 1498 | end | 1497 | end |
| 1499 | end | 1498 | end |
| 1500 | </PRE> | 1499 | </pre> |
| 1501 | | 1500 | |
| 1502 | <p><li><b>"call":</b> | 1501 | <p><li><b>"call":</b> |
| 1503 | called when Lua calls a value. | 1502 | called when Lua calls a value. |
| 1504 | <PRE> | 1503 | <pre> |
| 1505 | function function_event (func, ...) | 1504 | function function_event (func, ...) |
| 1506 | if type(func) == "function" then | 1505 | if type(func) == "function" then |
| 1507 | return func(unpack(arg)) -- primitive call | 1506 | return func(unpack(arg)) -- primitive call |
| @@ -1514,7 +1513,7 @@ called when Lua calls a value. · 6 unmodified lines |
| 1514 | end | 1513 | end |
| 1515 | end | 1514 | end |
| 1516 | end | 1515 | end |
| 1517 | </PRE> | 1516 | </pre> |
| 1518 | | 1517 | |
| 1519 | <p></ul> | 1518 | <p></ul> |
| 1520 | | 1519 | |
| @@ -1612,14 +1611,14 @@ Instead, Lua puts them in a list. · 91 unmodified lines |
| 1612 | After the collection, | 1611 | After the collection, |
| 1613 | Lua does the equivalent of the following function | 1612 | Lua does the equivalent of the following function |
| 1614 | for each userdata in that list: | 1613 | for each userdata in that list: |
| 1615 | <PRE> | 1614 | <pre> |
| 1616 | function gc_event (udata) | 1615 | function gc_event (udata) |
| 1617 | local h = metatable(udata).__gc | 1616 | local h = metatable(udata).__gc |
| 1618 | if h then | 1617 | if h then |
| 1619 | h(udata) | 1618 | h(udata) |
| 1620 | end | 1619 | end |
| 1621 | end | 1620 | end |
| 1622 | </PRE> | 1621 | </pre> |
| 1623 | | 1622 | |
| 1624 | <p>At the end of each garbage-collection cycle, | 1623 | <p>At the end of each garbage-collection cycle, |
| 1625 | the finalizers for userdata are called in <em>reverse</em> | 1624 | the finalizers for userdata are called in <em>reverse</em> |
| @@ -1686,9 +1685,9 @@ it runs until it terminates or <em>yields</em>. · 60 unmodified lines |
| 1686 | Normally, when its main function returns | 1685 | Normally, when its main function returns |
| 1687 | (explicitly or implicitly, after the last instruction); | 1686 | (explicitly or implicitly, after the last instruction); |
| 1688 | and abnormally, if there is an unprotected error. | 1687 | and abnormally, if there is an unprotected error. |
| 1689 | In the first case, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <B>true</B>, | 1688 | In the first case, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>true</b>, |
| 1690 | plus any values returned by the coroutine main function. | 1689 | plus any values returned by the coroutine main function. |
| 1691 | In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <B>false</B> | 1690 | In case of errors, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> returns <b>false</b> |
| 1692 | plus an error message. | 1691 | plus an error message. |
| 1693 | | 1692 | |
| 1694 | <p>A coroutine yields by calling <code>coroutine.yield</code>. | 1693 | <p>A coroutine yields by calling <code>coroutine.yield</code>. |
| @@ -1697,7 +1696,7 @@ the corresponding <a href="#pdf-coroutine.resume"><code>coroutine.resume</code>< · 2 unmodified lines |
| 1697 | even if the yield happens inside nested function calls | 1696 | even if the yield happens inside nested function calls |
| 1698 | (that is, not in the main function, | 1697 | (that is, not in the main function, |
| 1699 | but in a function directly or indirectly called by the main function). | 1698 | but in a function directly or indirectly called by the main function). |
| 1700 | In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also returns <B>true</B>, | 1699 | In the case of a yield, <a href="#pdf-coroutine.resume"><code>coroutine.resume</code></a> also returns <b>true</b>, |
| 1701 | plus any values passed to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>. | 1700 | plus any values passed to <a href="#pdf-coroutine.yield"><code>coroutine.yield</code></a>. |
| 1702 | The next time you resume the same coroutine, | 1701 | The next time you resume the same coroutine, |
| 1703 | it continues its execution from the point where it yielded, | 1702 | it continues its execution from the point where it yielded, |
| @@ -1718,7 +1717,7 @@ any error is propagated to the caller. · 14 unmodified lines |
| 1718 | | 1717 | |
| 1719 | <p>As an example, | 1718 | <p>As an example, |
| 1720 | consider the next code: | 1719 | consider the next code: |
| 1721 | <PRE> | 1720 | <pre> |
| 1722 | function foo1 (a) | 1721 | function foo1 (a) |
| 1723 | print("foo", a) | 1722 | print("foo", a) |
| 1724 | return coroutine.yield(2*a) | 1723 | return coroutine.yield(2*a) |
| @@ -1741,9 +1740,9 @@ a, b, c = coroutine.resume(co, "x", "y") · 16 unmodified lines |
| 1741 | print("main", a, b, c) | 1740 | print("main", a, b, c) |
| 1742 | a, b = coroutine.resume(co, "x", "y") | 1741 | a, b = coroutine.resume(co, "x", "y") |
| 1743 | print("main", a, b) | 1742 | print("main", a, b) |
| 1744 | </PRE> | 1743 | </pre> |
| 1745 | When you run it, it produces the following output: | 1744 | When you run it, it produces the following output: |
| 1746 | <PRE> | 1745 | <pre> |
| 1747 | co-body 1 10 | 1746 | co-body 1 10 |
| 1748 | foo 2 | 1747 | foo 2 |
| 1749 | main true 4 | 1748 | main true 4 |
| @@ -1752,7 +1751,7 @@ main true 11 -9 · 2 unmodified lines |
| 1752 | co-body x y | 1751 | co-body x y |
| 1753 | main true 10 end | 1752 | main true 10 end |
| 1754 | main false cannot resume dead coroutine | 1753 | main false cannot resume dead coroutine |
| 1755 | </PRE> | 1754 | </pre> |
| 1756 | | 1755 | |
| 1757 | <p> | 1756 | <p> |
| 1758 | <a name="API"></a><a name="3"></a><h1>3 - The Application Program Interface</h1> | 1757 | <a name="API"></a><a name="3"></a><h1>3 - The Application Program Interface</h1> |
| @@ -1780,7 +1779,7 @@ in file <code>luaconf.h</code>. · 21 unmodified lines |
| 1780 | | 1779 | |
| 1781 | <p>Lua uses a <em>virtual stack</em> to pass values to and from C. | 1780 | <p>Lua uses a <em>virtual stack</em> to pass values to and from C. |
| 1782 | Each element in this stack represents a Lua value | 1781 | Each element in this stack represents a Lua value |
| 1783 | (<B>nil</B>, number, string, etc.). | 1782 | (<b>nil</b>, number, string, etc.). |
| 1784 | | 1783 | |
| 1785 | <p>Whenever Lua calls C, the called function gets a new stack, | 1784 | <p>Whenever Lua calls C, the called function gets a new stack, |
| 1786 | which is independent of previous stacks and of stacks of | 1785 | which is independent of previous stacks and of stacks of |
| @@ -1828,9 +1827,9 @@ you have set through <a href="#lua_checkstack"><code>lua_checkstack</code></a>. · 41 unmodified lines |
| 1828 | Such indices are called <em>acceptable indices</em>. | 1827 | Such indices are called <em>acceptable indices</em>. |
| 1829 | More formally, we define an <em>acceptable index</em> | 1828 | More formally, we define an <em>acceptable index</em> |
| 1830 | as follows: | 1829 | as follows: |
| 1831 | <PRE> | 1830 | <pre> |
| 1832 | (index < 0 && abs(index) <= top) || (index > 0 && index <= stackspace) | 1831 | (index < 0 && abs(index) <= top) || (index > 0 && index <= stackspace) |
| 1833 | </PRE> | 1832 | </pre> |
| 1834 | Note that 0 is never an acceptable index. | 1833 | Note that 0 is never an acceptable index. |
| 1835 | | 1834 | |
| 1836 | <p><a name="pseudo-index"></a><a name="3.3"></a><h2>3.3 - Pseudo-Indices</h2> | 1835 | <p><a name="pseudo-index"></a><a name="3.3"></a><h2>3.3 - Pseudo-Indices</h2> |
| @@ -1853,9 +1852,9 @@ at pseudo-index <code>LUA_ENVIRONINDEX</code>. · 16 unmodified lines |
| 1853 | <p>To access and change the value of global variables, | 1852 | <p>To access and change the value of global variables, |
| 1854 | you can use regular table operations over an environment table. | 1853 | you can use regular table operations over an environment table. |
| 1855 | For instance, to access the value of a global variable, do | 1854 | For instance, to access the value of a global variable, do |
| 1856 | <PRE> | 1855 | <pre> |
| 1857 | lua_getfield(L, LUA_GLOBALSINDEX, varname); | 1856 | lua_getfield(L, LUA_GLOBALSINDEX, varname); |
| 1858 | </PRE> | 1857 | </pre> |
| 1859 | | 1858 | |
| 1860 | <p><a name="c-closure"></a><a name="3.4"></a><h2>3.4 - C Closures</h2> | 1859 | <p><a name="c-closure"></a><a name="3.4"></a><h2>3.4 - C Closures</h2> |
| 1861 | | 1860 | |
| @@ -1918,7 +1917,7 @@ so they never raise an error: · 56 unmodified lines |
| 1918 | alphabetical order. | 1917 | alphabetical order. |
| 1919 | | 1918 | |
| 1920 | <p><a name="lua_Alloc"></a> | 1919 | <p><a name="lua_Alloc"></a> |
| 1921 | <hr><h3><code>lua_Alloc</code></h3> | 1920 | <hr/><h3><code>lua_Alloc</code></h3> |
| 1922 | <pre> | 1921 | <pre> |
| 1923 | typedef void * (*lua_Alloc) (void *ud, | 1922 | typedef void * (*lua_Alloc) (void *ud, |
| 1924 | void *ptr, | 1923 | void *ptr, |
| @@ -1950,8 +1949,9 @@ the allocator behaves like <code>realloc</code>. · 25 unmodified lines |
| 1950 | Lua assumes that the allocator never fails when | 1949 | Lua assumes that the allocator never fails when |
| 1951 | <code>osize >= nsize</code>. | 1950 | <code>osize >= nsize</code>. |
| 1952 | | 1951 | |
| 1953 | <p>A simple implementation for the allocator function could be like this: | 1952 | <p>A simple implementation for the allocator function |
| 1954 | <PRE> | 1953 | could be like this: |
| | 1954 | <pre> |
| 1955 | static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { | 1955 | static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { |
| 1956 | (void)ud; /* not used */ | 1956 | (void)ud; /* not used */ |
| 1957 | (void)osize; /* not used */ | 1957 | (void)osize; /* not used */ |
| @@ -1963,10 +1963,10 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { · 5 unmodified lines |
| 1963 | /* ANSI ensures that realloc(NULL, size) == malloc(size) */ | 1963 | /* ANSI ensures that realloc(NULL, size) == malloc(size) */ |
| 1964 | return realloc(ptr, nsize); | 1964 | return realloc(ptr, nsize); |
| 1965 | } | 1965 | } |
| 1966 | </PRE> | 1966 | </pre> |
| 1967 | | 1967 | |
| 1968 | <p><a name="lua_atpanic"></a> | 1968 | <p><a name="lua_atpanic"></a> |
| 1969 | <hr><h3><code>lua_atpanic</code></h3> | 1969 | <hr/><h3><code>lua_atpanic</code></h3> |
| 1970 | <pre> | 1970 | <pre> |
| 1971 | lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf); | 1971 | lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf); |
| 1972 | </pre> | 1972 | </pre> |
| @@ -1983,7 +1983,7 @@ never returning (e.g., doing a long jump). · 10 unmodified lines |
| 1983 | <p>The panic function can access the error message at the top of the stack. | 1983 | <p>The panic function can access the error message at the top of the stack. |
| 1984 | | 1984 | |
| 1985 | <p><a name="lua_call"></a> | 1985 | <p><a name="lua_call"></a> |
| 1986 | <hr><h3><code>lua_call</code></h3> | 1986 | <hr/><h3><code>lua_call</code></h3> |
| 1987 | <pre> | 1987 | <pre> |
| 1988 | void lua_call (lua_State *L, int nargs, int nresults); | 1988 | void lua_call (lua_State *L, int nargs, int nresults); |
| 1989 | </pre> | 1989 | </pre> |
| @@ -2012,11 +2012,11 @@ so that after the call the last result is on the top. · 22 unmodified lines |
| 2012 | | 2012 | |
| 2013 | <p>The following example shows how the host program may do the | 2013 | <p>The following example shows how the host program may do the |
| 2014 | equivalent to this Lua code: | 2014 | equivalent to this Lua code: |
| 2015 | <PRE> | 2015 | <pre> |
| 2016 | a = f("how", t.x, 14) | 2016 | a = f("how", t.x, 14) |
| 2017 | </PRE> | 2017 | </pre> |
| 2018 | Here it is in C: | 2018 | Here it is in C: |
| 2019 | <PRE> | 2019 | <pre> |
| 2020 | lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* global `t' (for later use) */ | 2020 | lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* global `t' (for later use) */ |
| 2021 | lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */ | 2021 | lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */ |
| 2022 | lua_pushstring(L, "how"); /* 1st argument */ | 2022 | lua_pushstring(L, "how"); /* 1st argument */ |
| @@ -2025,13 +2025,13 @@ Here it is in C: · 2 unmodified lines |
| 2025 | lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */ | 2025 | lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */ |
| 2026 | lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable `a' */ | 2026 | lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable `a' */ |
| 2027 | lua_pop(L, 1); /* remove `t' from the stack */ | 2027 | lua_pop(L, 1); /* remove `t' from the stack */ |
| 2028 | </PRE> | 2028 | </pre> |
| 2029 | Note that the code above is "balanced": | 2029 | Note that the code above is "balanced": |
| 2030 | at its end, the stack is back to its original configuration. | 2030 | at its end, the stack is back to its original configuration. |
| 2031 | This is considered good programming practice. | 2031 | This is considered good programming practice. |
| 2032 | | 2032 | |
| 2033 | <p><a name="lua_CFunction"></a> | 2033 | <p><a name="lua_CFunction"></a> |
| 2034 | <hr><h3><code>lua_CFunction</code></h3> | 2034 | <hr/><h3><code>lua_CFunction</code></h3> |
| 2035 | <pre> | 2035 | <pre> |
| 2036 | typedef int (*lua_CFunction) (lua_State *L); | 2036 | typedef int (*lua_CFunction) (lua_State *L); |
| 2037 | </pre> | 2037 | </pre> |
| @@ -2056,7 +2056,7 @@ many results. · 18 unmodified lines |
| 2056 | | 2056 | |
| 2057 | <p>As an example, the following function receives a variable number | 2057 | <p>As an example, the following function receives a variable number |
| 2058 | of numerical arguments and returns their average and sum: | 2058 | of numerical arguments and returns their average and sum: |
| 2059 | <PRE> | 2059 | <pre> |
| 2060 | static int foo (lua_State *L) { | 2060 | static int foo (lua_State *L) { |
| 2061 | int n = lua_gettop(L); /* number of arguments */ | 2061 | int n = lua_gettop(L); /* number of arguments */ |
| 2062 | lua_Number sum = 0; | 2062 | lua_Number sum = 0; |
| @@ -2072,10 +2072,10 @@ of numerical arguments and returns their average and sum: · 9 unmodified lines |
| 2072 | lua_pushnumber(L, sum); /* second result */ | 2072 | lua_pushnumber(L, sum); /* second result */ |
| 2073 | return 2; /* number of results */ | 2073 | return 2; /* number of results */ |
| 2074 | } | 2074 | } |
| 2075 | </PRE> | 2075 | </pre> |
| 2076 | | 2076 | |
| 2077 | <p><a name="lua_checkstack"></a> | 2077 | <p><a name="lua_checkstack"></a> |
| 2078 | <hr><h3><code>lua_checkstack</code></h3> | 2078 | <hr/><h3><code>lua_checkstack</code></h3> |
| 2079 | <pre> | 2079 | <pre> |
| 2080 | int lua_checkstack (lua_State *L, int extra); | 2080 | int lua_checkstack (lua_State *L, int extra); |
| 2081 | </pre> | 2081 | </pre> |
| @@ -2088,7 +2088,7 @@ if the stack is already larger than the new size, · 6 unmodified lines |
| 2088 | it is left unchanged. | 2088 | it is left unchanged. |
| 2089 | | 2089 | |
| 2090 | <p><a name="lua_close"></a> | 2090 | <p><a name="lua_close"></a> |
| 2091 | <hr><h3><code>lua_close</code></h3> | 2091 | <hr/><h3><code>lua_close</code></h3> |
| 2092 | <pre> | 2092 | <pre> |
| 2093 | void lua_close (lua_State *L); | 2093 | void lua_close (lua_State *L); |
| 2094 | </pre> | 2094 | </pre> |
| @@ -2105,7 +2105,7 @@ might need to release states as soon as they are not needed, · 10 unmodified lines |
| 2105 | to avoid growing too large. | 2105 | to avoid growing too large. |
| 2106 | | 2106 | |
| 2107 | <p><a name="lua_concat"></a> | 2107 | <p><a name="lua_concat"></a> |
| 2108 | <hr><h3><code>lua_concat</code></h3> | 2108 | <hr/><h3><code>lua_concat</code></h3> |
| 2109 | <pre> | 2109 | <pre> |
| 2110 | void lua_concat (lua_State *L, int n); | 2110 | void lua_concat (lua_State *L, int n); |
| 2111 | </pre> | 2111 | </pre> |
| @@ -2120,7 +2120,7 @@ Concatenation is done following the usual semantics of Lua · 8 unmodified lines |
| 2120 | (see <a href="#concat">2.5.4</a>). | 2120 | (see <a href="#concat">2.5.4</a>). |
| 2121 | | 2121 | |
| 2122 | <p><a name="lua_cpcall"></a> | 2122 | <p><a name="lua_cpcall"></a> |
| 2123 | <hr><h3><code>lua_cpcall</code></h3> | 2123 | <hr/><h3><code>lua_cpcall</code></h3> |
| 2124 | <pre> | 2124 | <pre> |
| 2125 | int lua_cpcall (lua_State *L, lua_CFunction func, void *ud); | 2125 | int lua_cpcall (lua_State *L, lua_CFunction func, void *ud); |
| 2126 | </pre> | 2126 | </pre> |
| @@ -2136,7 +2136,7 @@ otherwise, it returns zero, and does not change the stack. · 9 unmodified lines |
| 2136 | Any value returned by <code>func</code> is discarded. | 2136 | Any value returned by <code>func</code> is discarded. |
| 2137 | | 2137 | |
| 2138 | <p><a name="lua_createtable"></a> | 2138 | <p><a name="lua_createtable"></a> |
| 2139 | <hr><h3><code>lua_createtable</code></h3> | 2139 | <hr/><h3><code>lua_createtable</code></h3> |
| 2140 | <pre> | 2140 | <pre> |
| 2141 | void lua_createtable (lua_State *L, int narr, int nrec); | 2141 | void lua_createtable (lua_State *L, int narr, int nrec); |
| 2142 | </pre> | 2142 | </pre> |
| @@ -2150,7 +2150,7 @@ the table will have. · 7 unmodified lines |
| 2150 | Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>. | 2150 | Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</code></a>. |
| 2151 | | 2151 | |
| 2152 | <p><a name="lua_dump"></a> | 2152 | <p><a name="lua_dump"></a> |
| 2153 | <hr><h3><code>lua_dump</code></h3> | 2153 | <hr/><h3><code>lua_dump</code></h3> |
| 2154 | <pre> | 2154 | <pre> |
| 2155 | int lua_dump (lua_State *L, lua_Writer writer, void *data); | 2155 | int lua_dump (lua_State *L, lua_Writer writer, void *data); |
| 2156 | </pre> | 2156 | </pre> |
| @@ -2172,7 +2172,7 @@ call to the writer; · 15 unmodified lines |
| 2172 | <p>This function does not pop the function from the stack. | 2172 | <p>This function does not pop the function from the stack. |
| 2173 | | 2173 | |
| 2174 | <p><a name="lua_equal"></a> | 2174 | <p><a name="lua_equal"></a> |
| 2175 | <hr><h3><code>lua_equal</code></h3> | 2175 | <hr/><h3><code>lua_equal</code></h3> |
| 2176 | <pre> | 2176 | <pre> |
| 2177 | int lua_equal (lua_State *L, int index1, int index2); | 2177 | int lua_equal (lua_State *L, int index1, int index2); |
| 2178 | </pre> | 2178 | </pre> |
| @@ -2180,13 +2180,13 @@ call to the writer; · 1 unmodified line |
| 2180 | | 2180 | |
| 2181 | <p>Returns 1 if the two values in acceptable indices <code>index1</code> and | 2181 | <p>Returns 1 if the two values in acceptable indices <code>index1</code> and |
| 2182 | <code>index2</code> are equal, | 2182 | <code>index2</code> are equal, |
| 2183 | following the semantics of the Lua <code>=</code> operator | 2183 | following the semantics of the Lua <code>==</code> operator |
| 2184 | (that is, may call metamethods). | 2184 | (that is, may call metamethods). |
| 2185 | Otherwise returns 0. | 2185 | Otherwise returns 0. |
| 2186 | Also returns 0 if any of the indices are non valid. | 2186 | Also returns 0 if any of the indices are non valid. |
| 2187 | | 2187 | |
| 2188 | <p><a name="lua_error"></a> | 2188 | <p><a name="lua_error"></a> |
| 2189 | <hr><h3><code>lua_error</code></h3> | 2189 | <hr/><h3><code>lua_error</code></h3> |
| 2190 | <pre> | 2190 | <pre> |
| 2191 | int lua_error (lua_State *L); | 2191 | int lua_error (lua_State *L); |
| 2192 | </pre> | 2192 | </pre> |
| @@ -2199,7 +2199,7 @@ This function does a long jump, · 6 unmodified lines |
| 2199 | and therefore never returns. | 2199 | and therefore never returns. |
| 2200 | | 2200 | |
| 2201 | <p><a name="lua_gc"></a> | 2201 | <p><a name="lua_gc"></a> |
| 2202 | <hr><h3><code>lua_gc</code></h3> | 2202 | <hr/><h3><code>lua_gc</code></h3> |
| 2203 | <pre> | 2203 | <pre> |
| 2204 | int lua_gc (lua_State *L, int what, int data); | 2204 | int lua_gc (lua_State *L, int what, int data); |
| 2205 | </pre> | 2205 | </pre> |
| @@ -2210,12 +2210,15 @@ and therefore never returns. · 4 unmodified lines |
| 2210 | <p>This function performs several tasks, | 2210 | <p>This function performs several tasks, |
| 2211 | according to the value of the parameter <code>what</code>: | 2211 | according to the value of the parameter <code>what</code>: |
| 2212 | <ul> | 2212 | <ul> |
| 2213 | <li> <code>LUA_GCSTOP</code>— stops the garbage collector. | 2213 | <li> <code>LUA_GCSTOP</code>--- stops the garbage collector. |
| 2214 | <li> <code>LUA_GCRESTART</code>— restarts the garbage collector. | 2214 | <li> <code>LUA_GCRESTART</code>--- restarts the garbage collector. |
| 2215 | <li> <code>LUA_GCCOLLECT</code>— performs a full garbage-collection cycle. | 2215 | <li> <code>LUA_GCCOLLECT</code>--- performs a full garbage-collection cycle. |
| 2216 | <li> <code>LUA_GCCOUNT</code>— returns the current | 2216 | <li> <code>LUA_GCCOUNT</code>--- returns the current |
| 2217 | amount of memory (in Kbytes) in use by Lua. | 2217 | amount of memory (in Kbytes) in use by Lua. |
| 2218 | <li> <code>LUA_GCSTEP</code>— performs an incremental step of | 2218 | <li> <code>LUA_GCCOUNTB</code>--- returns the remainder of |
| | 2219 | dividing the current amount of bytes of memory in use by Lua |
| | 2220 | by 1024. |
| | 2221 | <li> <code>LUA_GCSTEP</code>--- performs an incremental step of |
| 2219 | garbage collection. | 2222 | garbage collection. |
| 2220 | The step "size" is controlled by <code>data</code> | 2223 | The step "size" is controlled by <code>data</code> |
| 2221 | (larger values mean more steps) in a non-specified way. | 2224 | (larger values mean more steps) in a non-specified way. |
| @@ -2223,16 +2226,18 @@ If you want to control the step size · 1 unmodified line |
| 2223 | you must tune experimentally the value of <code>data</code>. | 2226 | you must tune experimentally the value of <code>data</code>. |
| 2224 | The function returns 1 if that step finished a | 2227 | The function returns 1 if that step finished a |
| 2225 | garbage-collection cycle. | 2228 | garbage-collection cycle. |
| 2226 | <li> <code>LUA_GCSETPAUSE</code>— | 2229 | <li> <code>LUA_GCSETPAUSE</code>--- |
| 2227 | sets <em><code>data</code>/100</em> as the new value | 2230 | sets <em><code>data</code>/100</em> as the new value |
| 2228 | for the <em>pause</em> of the collector (see <a href="#GC">2.10</a>). | 2231 | for the <em>pause</em> of the collector (see <a href="#GC">2.10</a>). |
| 2229 | <li> <code>LUA_GCSETSTEPMUL</code>— | 2232 | The function returns the previous value of the pause. |
| | 2233 | <li> <code>LUA_GCSETSTEPMUL</code>--- |
| 2230 | sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier</em> of | 2234 | sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier</em> of |
| 2231 | the collector (see <a href="#GC">2.10</a>). | 2235 | the collector (see <a href="#GC">2.10</a>). |
| | 2236 | The function returns the previous value of the step multiplier. |
| 2232 | </ul> | 2237 | </ul> |
| 2233 | | 2238 | |
| 2234 | <p><a name="lua_getallocf"></a> | 2239 | <p><a name="lua_getallocf"></a> |
| 2235 | <hr><h3><code>lua_getallocf</code></h3> | 2240 | <hr/><h3><code>lua_getallocf</code></h3> |
| 2236 | <pre> | 2241 | <pre> |
| 2237 | lua_Alloc lua_getallocf (lua_State *L, void **ud); | 2242 | lua_Alloc lua_getallocf (lua_State *L, void **ud); |
| 2238 | </pre> | 2243 | </pre> |
| @@ -2243,7 +2248,7 @@ If <code>ud</code> is not <code>NULL</code> Lua stores in <code>*ud</code> the · 4 unmodified lines |
| 2243 | opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. | 2248 | opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. |
| 2244 | | 2249 | |
| 2245 | <p><a name="lua_getfenv"></a> | 2250 | <p><a name="lua_getfenv"></a> |
| 2246 | <hr><h3><code>lua_getfenv</code></h3> | 2251 | <hr/><h3><code>lua_getfenv</code></h3> |
| 2247 | <pre> | 2252 | <pre> |
| 2248 | void lua_getfenv (lua_State *L, int index); | 2253 | void lua_getfenv (lua_State *L, int index); |
| 2249 | </pre> | 2254 | </pre> |
| @@ -2253,7 +2258,7 @@ opaque pointer passed to <a href="#lua_newstate"><code>lua_newstate</code></a>. · 3 unmodified lines |
| 2253 | the value at the given index. | 2258 | the value at the given index. |
| 2254 | | 2259 | |
| 2255 | <p><a name="lua_getfield"></a> | 2260 | <p><a name="lua_getfield"></a> |
| 2256 | <hr><h3><code>lua_getfield</code></h3> | 2261 | <hr/><h3><code>lua_getfield</code></h3> |
| 2257 | <pre> | 2262 | <pre> |
| 2258 | void lua_getfield (lua_State *L, int index, const char *k); | 2263 | void lua_getfield (lua_State *L, int index, const char *k); |
| 2259 | </pre> | 2264 | </pre> |
| @@ -2265,7 +2270,7 @@ As in Lua, this function may trigger a metamethod · 5 unmodified lines |
| 2265 | for the "index" event (see <a href="#metatable">2.8</a>). | 2270 | for the "index" event (see <a href="#metatable">2.8</a>). |
| 2266 | | 2271 | |
| 2267 | <p><a name="lua_getmetatable"></a> | 2272 | <p><a name="lua_getmetatable"></a> |
| 2268 | <hr><h3><code>lua_getmetatable</code></h3> | 2273 | <hr/><h3><code>lua_getmetatable</code></h3> |
| 2269 | <pre> | 2274 | <pre> |
| 2270 | int lua_getmetatable (lua_State *L, int index); | 2275 | int lua_getmetatable (lua_State *L, int index); |
| 2271 | </pre> | 2276 | </pre> |
| @@ -2278,7 +2283,7 @@ or if the value does not have a metatable, · 6 unmodified lines |
| 2278 | returns 0 and pushes nothing on the stack. | 2283 | returns 0 and pushes nothing on the stack. |
| 2279 | | 2284 | |
| 2280 | <p><a name="lua_gettable"></a> | 2285 | <p><a name="lua_gettable"></a> |
| 2281 | <hr><h3><code>lua_gettable</code></h3> | 2286 | <hr/><h3><code>lua_gettable</code></h3> |
| 2282 | <pre> | 2287 | <pre> |
| 2283 | void lua_gettable (lua_State *L, int index); | 2288 | void lua_gettable (lua_State *L, int index); |
| 2284 | </pre> | 2289 | </pre> |
| @@ -2294,7 +2299,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines |
| 2294 | for the "index" event (see <a href="#metatable">2.8</a>). | 2299 | for the "index" event (see <a href="#metatable">2.8</a>). |
| 2295 | | 2300 | |
| 2296 | <p><a name="lua_gettop"></a> | 2301 | <p><a name="lua_gettop"></a> |
| 2297 | <hr><h3><code>lua_gettop</code></h3> | 2302 | <hr/><h3><code>lua_gettop</code></h3> |
| 2298 | <pre> | 2303 | <pre> |
| 2299 | int lua_gettop (lua_State *L); | 2304 | int lua_gettop (lua_State *L); |
| 2300 | </pre> | 2305 | </pre> |
| @@ -2306,7 +2311,7 @@ that result is equal to the number of elements in the stack · 5 unmodified lines |
| 2306 | (and so 0 means an empty stack). | 2311 | (and so 0 means an empty stack). |
| 2307 | | 2312 | |
| 2308 | <p><a name="lua_insert"></a> | 2313 | <p><a name="lua_insert"></a> |
| 2309 | <hr><h3><code>lua_insert</code></h3> | 2314 | <hr/><h3><code>lua_insert</code></h3> |
| 2310 | <pre> | 2315 | <pre> |
| 2311 | void lua_insert (lua_State *L, int index); | 2316 | void lua_insert (lua_State *L, int index); |
| 2312 | </pre> | 2317 | </pre> |
| @@ -2318,7 +2323,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines |
| 2318 | because a pseudo-index is not an actual stack position. | 2323 | because a pseudo-index is not an actual stack position. |
| 2319 | | 2324 | |
| 2320 | <p><a name="lua_Integer"></a> | 2325 | <p><a name="lua_Integer"></a> |
| 2321 | <hr><h3><code>lua_Integer</code></h3> | 2326 | <hr/><h3><code>lua_Integer</code></h3> |
| 2322 | <pre> | 2327 | <pre> |
| 2323 | typedef ptrdiff_t lua_Integer; | 2328 | typedef ptrdiff_t lua_Integer; |
| 2324 | </pre> | 2329 | </pre> |
| @@ -2331,7 +2336,7 @@ which is usually the largest type the machine handles · 6 unmodified lines |
| 2331 | "comfortably". | 2336 | "comfortably". |
| 2332 | | 2337 | |
| 2333 | <p><a name="lua_isboolean"></a> | 2338 | <p><a name="lua_isboolean"></a> |
| 2334 | <hr><h3><code>lua_isboolean</code></h3> | 2339 | <hr/><h3><code>lua_isboolean</code></h3> |
| 2335 | <pre> | 2340 | <pre> |
| 2336 | int lua_isboolean (lua_State *L, int index); | 2341 | int lua_isboolean (lua_State *L, int index); |
| 2337 | </pre> | 2342 | </pre> |
| @@ -2341,7 +2346,7 @@ which is usually the largest type the machine handles · 3 unmodified lines |
| 2341 | and 0 otherwise. | 2346 | and 0 otherwise. |
| 2342 | | 2347 | |
| 2343 | <p><a name="lua_iscfunction"></a> | 2348 | <p><a name="lua_iscfunction"></a> |
| 2344 | <hr><h3><code>lua_iscfunction</code></h3> | 2349 | <hr/><h3><code>lua_iscfunction</code></h3> |
| 2345 | <pre> | 2350 | <pre> |
| 2346 | int lua_iscfunction (lua_State *L, int index); | 2351 | int lua_iscfunction (lua_State *L, int index); |
| 2347 | </pre> | 2352 | </pre> |
| @@ -2351,7 +2356,7 @@ and 0 otherwise. · 3 unmodified lines |
| 2351 | and 0 otherwise. | 2356 | and 0 otherwise. |
| 2352 | | 2357 | |
| 2353 | <p><a name="lua_isfunction"></a> | 2358 | <p><a name="lua_isfunction"></a> |
| 2354 | <hr><h3><code>lua_isfunction</code></h3> | 2359 | <hr/><h3><code>lua_isfunction</code></h3> |
| 2355 | <pre> | 2360 | <pre> |
| 2356 | int lua_isfunction (lua_State *L, int index); | 2361 | int lua_isfunction (lua_State *L, int index); |
| 2357 | </pre> | 2362 | </pre> |
| @@ -2361,7 +2366,7 @@ and 0 otherwise. · 3 unmodified lines |
| 2361 | (either C or Lua), and 0 otherwise. | 2366 | (either C or Lua), and 0 otherwise. |
| 2362 | | 2367 | |
| 2363 | <p><a name="lua_islightuserdata"></a> | 2368 | <p><a name="lua_islightuserdata"></a> |
| 2364 | <hr><h3><code>lua_islightuserdata</code></h3> | 2369 | <hr/><h3><code>lua_islightuserdata</code></h3> |
| 2365 | <pre> | 2370 | <pre> |
| 2366 | int lua_islightuserdata (lua_State *L, int index); | 2371 | int lua_islightuserdata (lua_State *L, int index); |
| 2367 | </pre> | 2372 | </pre> |
| @@ -2371,17 +2376,17 @@ and 0 otherwise. · 3 unmodified lines |
| 2371 | and 0 otherwise. | 2376 | and 0 otherwise. |
| 2372 | | 2377 | |
| 2373 | <p><a name="lua_isnil"></a> | 2378 | <p><a name="lua_isnil"></a> |
| 2374 | <hr><h3><code>lua_isnil</code></h3> | 2379 | <hr/><h3><code>lua_isnil</code></h3> |
| 2375 | <pre> | 2380 | <pre> |
| 2376 | int lua_isnil (lua_State *L, int index); | 2381 | int lua_isnil (lua_State *L, int index); |
| 2377 | </pre> | 2382 | </pre> |
| 2378 | | 2383 | |
| 2379 | | 2384 | |
| 2380 | <p>Returns 1 if the value at the given acceptable index is <B>nil</B>, | 2385 | <p>Returns 1 if the value at the given acceptable index is <b>nil</b>, |
| 2381 | and 0 otherwise. | 2386 | and 0 otherwise. |
| 2382 | | 2387 | |
| 2383 | <p><a name="lua_isnumber"></a> | 2388 | <p><a name="lua_isnumber"></a> |
| 2384 | <hr><h3><code>lua_isnumber</code></h3> | 2389 | <hr/><h3><code>lua_isnumber</code></h3> |
| 2385 | <pre> | 2390 | <pre> |
| 2386 | int lua_isnumber (lua_State *L, int index); | 2391 | int lua_isnumber (lua_State *L, int index); |
| 2387 | </pre> | 2392 | </pre> |
| @@ -2392,7 +2397,7 @@ or a string convertible to a number, · 4 unmodified lines |
| 2392 | and 0 otherwise. | 2397 | and 0 otherwise. |
| 2393 | | 2398 | |
| 2394 | <p><a name="lua_isstring"></a> | 2399 | <p><a name="lua_isstring"></a> |
| 2395 | <hr><h3><code>lua_isstring</code></h3> | 2400 | <hr/><h3><code>lua_isstring</code></h3> |
| 2396 | <pre> | 2401 | <pre> |
| 2397 | int lua_isstring (lua_State *L, int index); | 2402 | int lua_isstring (lua_State *L, int index); |
| 2398 | </pre> | 2403 | </pre> |
| @@ -2403,7 +2408,7 @@ or a number (which is always convertible to a string), · 4 unmodified lines |
| 2403 | and 0 otherwise. | 2408 | and 0 otherwise. |
| 2404 | | 2409 | |
| 2405 | <p><a name="lua_istable"></a> | 2410 | <p><a name="lua_istable"></a> |
| 2406 | <hr><h3><code>lua_istable</code></h3> | 2411 | <hr/><h3><code>lua_istable</code></h3> |
| 2407 | <pre> | 2412 | <pre> |
| 2408 | int lua_istable (lua_State *L, int index); | 2413 | int lua_istable (lua_State *L, int index); |
| 2409 | </pre> | 2414 | </pre> |
| @@ -2413,7 +2418,7 @@ and 0 otherwise. · 3 unmodified lines |
| 2413 | and 0 otherwise. | 2418 | and 0 otherwise. |
| 2414 | | 2419 | |
| 2415 | <p><a name="lua_isthread"></a> | 2420 | <p><a name="lua_isthread"></a> |
| 2416 | <hr><h3><code>lua_isthread</code></h3> | 2421 | <hr/><h3><code>lua_isthread</code></h3> |
| 2417 | <pre> | 2422 | <pre> |
| 2418 | int lua_isthread (lua_State *L, int index); | 2423 | int lua_isthread (lua_State *L, int index); |
| 2419 | </pre> | 2424 | </pre> |
| @@ -2423,7 +2428,7 @@ and 0 otherwise. · 3 unmodified lines |
| 2423 | and 0 otherwise. | 2428 | and 0 otherwise. |
| 2424 | | 2429 | |
| 2425 | <p><a name="lua_isuserdata"></a> | 2430 | <p><a name="lua_isuserdata"></a> |
| 2426 | <hr><h3><code>lua_isuserdata</code></h3> | 2431 | <hr/><h3><code>lua_isuserdata</code></h3> |
| 2427 | <pre> | 2432 | <pre> |
| 2428 | int lua_isuserdata (lua_State *L, int index); | 2433 | int lua_isuserdata (lua_State *L, int index); |
| 2429 | </pre> | 2434 | </pre> |
| @@ -2433,7 +2438,7 @@ and 0 otherwise. · 3 unmodified lines |
| 2433 | (either full or light), and 0 otherwise. | 2438 | (either full or light), and 0 otherwise. |
| 2434 | | 2439 | |
| 2435 | <p><a name="lua_lessthan"></a> | 2440 | <p><a name="lua_lessthan"></a> |
| 2436 | <hr><h3><code>lua_lessthan</code></h3> | 2441 | <hr/><h3><code>lua_lessthan</code></h3> |
| 2437 | <pre> | 2442 | <pre> |
| 2438 | int lua_lessthan (lua_State *L, int index1, int index2); | 2443 | int lua_lessthan (lua_State *L, int index1, int index2); |
| 2439 | </pre> | 2444 | </pre> |
| @@ -2447,7 +2452,7 @@ Otherwise returns 0. · 7 unmodified lines |
| 2447 | Also returns 0 if any of the indices are non valid. | 2452 | Also returns 0 if any of the indices are non valid. |
| 2448 | | 2453 | |
| 2449 | <p><a name="lua_load"></a> | 2454 | <p><a name="lua_load"></a> |
| 2450 | <hr><h3><code>lua_load</code></h3> | 2455 | <hr/><h3><code>lua_load</code></h3> |
| 2451 | <pre> | 2456 | <pre> |
| 2452 | int lua_load (lua_State *L, lua_Reader reader, void *data, | 2457 | int lua_load (lua_State *L, lua_Reader reader, void *data, |
| 2453 | const char *chunkname); | 2458 | const char *chunkname); |
| @@ -2462,10 +2467,10 @@ function on top of the stack. · 8 unmodified lines |
| 2462 | Otherwise, it pushes an error message. | 2467 | Otherwise, it pushes an error message. |
| 2463 | The return values of <a href="#lua_load"><code>lua_load</code></a> are: | 2468 | The return values of <a href="#lua_load"><code>lua_load</code></a> are: |
| 2464 | <ul> | 2469 | <ul> |
| 2465 | <li> 0 — no errors; | 2470 | <li> 0 --- no errors; |
| 2466 | <li> <code>LUA_ERRSYNTAX</code> — | 2471 | <li> <code>LUA_ERRSYNTAX</code> --- |
| 2467 | syntax error during pre-compilation. | 2472 | syntax error during pre-compilation. |
| 2468 | <li> <code>LUA_ERRMEM</code> — | 2473 | <li> <code>LUA_ERRMEM</code> --- |
| 2469 | memory allocation error. | 2474 | memory allocation error. |
| 2470 | </ul> | 2475 | </ul> |
| 2471 | | 2476 | |
| @@ -2480,7 +2485,7 @@ The <code>data</code> argument is an opaque value passed to the reader function. · 8 unmodified lines |
| 2480 | It is used for error messages and debug information (see <a href="#debugI">3.8</a>). | 2485 | It is used for error messages and debug information (see <a href="#debugI">3.8</a>). |
| 2481 | | 2486 | |
| 2482 | <p><a name="lua_newstate"></a> | 2487 | <p><a name="lua_newstate"></a> |
| 2483 | <hr><h3><code>lua_newstate</code></h3> | 2488 | <hr/><h3><code>lua_newstate</code></h3> |
| 2484 | <pre> | 2489 | <pre> |
| 2485 | lua_State *lua_newstate (lua_Alloc f, void *ud); | 2490 | lua_State *lua_newstate (lua_Alloc f, void *ud); |
| 2486 | </pre> | 2491 | </pre> |
| @@ -2495,7 +2500,7 @@ The second argument, <code>ud</code>, is an opaque pointer that Lua · 8 unmodified lines |
| 2495 | simply passes to the allocator in every call. | 2500 | simply passes to the allocator in every call. |
| 2496 | | 2501 | |
| 2497 | <p><a name="lua_newtable"></a> | 2502 | <p><a name="lua_newtable"></a> |
| 2498 | <hr><h3><code>lua_newtable</code></h3> | 2503 | <hr/><h3><code>lua_newtable</code></h3> |
| 2499 | <pre> | 2504 | <pre> |
| 2500 | void lua_newtable (lua_State *L); | 2505 | void lua_newtable (lua_State *L); |
| 2501 | </pre> | 2506 | </pre> |
| @@ -2505,7 +2510,7 @@ simply passes to the allocator in every call. · 3 unmodified lines |
| 2505 | Equivalent to <code>lua_createtable(L, 0, 0)</code>. | 2510 | Equivalent to <code>lua_createtable(L, 0, 0)</code>. |
| 2506 | | 2511 | |
| 2507 | <p><a name="lua_newthread"></a> | 2512 | <p><a name="lua_newthread"></a> |
| 2508 | <hr><h3><code>lua_newthread</code></h3> | 2513 | <hr/><h3><code>lua_newthread</code></h3> |
| 2509 | <pre> | 2514 | <pre> |
| 2510 | lua_State *lua_newthread (lua_State *L); | 2515 | lua_State *lua_newthread (lua_State *L); |
| 2511 | </pre> | 2516 | </pre> |
| @@ -2522,7 +2527,7 @@ Threads are subject to garbage collection, · 10 unmodified lines |
| 2522 | like any Lua object. | 2527 | like any Lua object. |
| 2523 | | 2528 | |
| 2524 | <p><a name="lua_newuserdata"></a> | 2529 | <p><a name="lua_newuserdata"></a> |
| 2525 | <hr><h3><code>lua_newuserdata</code></h3> | 2530 | <hr/><h3><code>lua_newuserdata</code></h3> |
| 2526 | <pre> | 2531 | <pre> |
| 2527 | void *lua_newuserdata (lua_State *L, size_t size); | 2532 | void *lua_newuserdata (lua_State *L, size_t size); |
| 2528 | </pre> | 2533 | </pre> |
| @@ -2544,7 +2549,7 @@ it calls the userdata's <code>gc</code> metamethod, if any, · 15 unmodified lines |
| 2544 | and then it frees the userdata's corresponding memory. | 2549 | and then it frees the userdata's corresponding memory. |
| 2545 | | 2550 | |
| 2546 | <p><a name="lua_next"></a> | 2551 | <p><a name="lua_next"></a> |
| 2547 | <hr><h3><code>lua_next</code></h3> | 2552 | <hr/><h3><code>lua_next</code></h3> |
| 2548 | <pre> | 2553 | <pre> |
| 2549 | int lua_next (lua_State *L, int index); | 2554 | int lua_next (lua_State *L, int index); |
| 2550 | </pre> | 2555 | </pre> |
| @@ -2557,7 +2562,7 @@ If there are no more elements, · 6 unmodified lines |
| 2557 | then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing). | 2562 | then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing). |
| 2558 | | 2563 | |
| 2559 | <p>A typical traversal looks like this: | 2564 | <p>A typical traversal looks like this: |
| 2560 | <PRE> | 2565 | <pre> |
| 2561 | /* table is in the stack at index `t' */ | 2566 | /* table is in the stack at index `t' */ |
| 2562 | lua_pushnil(L); /* first key */ | 2567 | lua_pushnil(L); /* first key */ |
| 2563 | while (lua_next(L, t) != 0) { | 2568 | while (lua_next(L, t) != 0) { |
| @@ -2566,7 +2571,7 @@ then <a href="#lua_next"><code>lua_next</code></a> returns 0 (and pushes nothing · 2 unmodified lines |
| 2566 | lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1))); | 2571 | lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1))); |
| 2567 | lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */ | 2572 | lua_pop(L, 1); /* removes `value'; keeps `key' for next iteration */ |
| 2568 | } | 2573 | } |
| 2569 | </PRE> | 2574 | </pre> |
| 2570 | | 2575 | |
| 2571 | <p>While traversing a table, | 2576 | <p>While traversing a table, |
| 2572 | do not call <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key, | 2577 | do not call <a href="#lua_tolstring"><code>lua_tolstring</code></a> directly on a key, |
| @@ -2576,7 +2581,7 @@ the value at the given index; · 3 unmodified lines |
| 2576 | this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>. | 2581 | this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>. |
| 2577 | | 2582 | |
| 2578 | <p><a name="lua_Number"></a> | 2583 | <p><a name="lua_Number"></a> |
| 2579 | <hr><h3><code>lua_Number</code></h3> | 2584 | <hr/><h3><code>lua_Number</code></h3> |
| 2580 | <pre> | 2585 | <pre> |
| 2581 | typedef double lua_Number; | 2586 | typedef double lua_Number; |
| 2582 | </pre> | 2587 | </pre> |
| @@ -2588,7 +2593,7 @@ this confuses the next call to <a href="#lua_next"><code>lua_next</code></a>. · 5 unmodified lines |
| 2588 | Lua to operate with other type for numbers (e.g., float or long). | 2593 | Lua to operate with other type for numbers (e.g., float or long). |
| 2589 | | 2594 | |
| 2590 | <p><a name="lua_objlen"></a> | 2595 | <p><a name="lua_objlen"></a> |
| 2591 | <hr><h3><code>lua_objlen</code></h3> | 2596 | <hr/><h3><code>lua_objlen</code></h3> |
| 2592 | <pre> | 2597 | <pre> |
| 2593 | size_t lua_objlen (lua_State *L, int index); | 2598 | size_t lua_objlen (lua_State *L, int index); |
| 2594 | </pre> | 2599 | </pre> |
| @@ -2602,7 +2607,7 @@ for the userdatum. · 7 unmodified lines |
| 2602 | For other values, returns 0. | 2607 | For other values, returns 0. |
| 2603 | | 2608 | |
| 2604 | <p><a name="lua_pcall"></a> | 2609 | <p><a name="lua_pcall"></a> |
| 2605 | <hr><h3><code>lua_pcall</code></h3> | 2610 | <hr/><h3><code>lua_pcall</code></h3> |
| 2606 | <pre> | 2611 | <pre> |
| 2607 | lua_pcall (lua_State *L, int nargs, int nresults, int errfunc); | 2612 | lua_pcall (lua_State *L, int nargs, int nresults, int errfunc); |
| 2608 | </pre> | 2613 | </pre> |
| @@ -2640,15 +2645,15 @@ since by then the stack has unwound. · 31 unmodified lines |
| 2640 | or one of the following error codes | 2645 | or one of the following error codes |
| 2641 | (defined in <code>lua.h</code>): | 2646 | (defined in <code>lua.h</code>): |
| 2642 | <ul> | 2647 | <ul> |
| 2643 | <li> <code>LUA_ERRRUN</code> — a runtime error. | 2648 | <li> <code>LUA_ERRRUN</code> --- a runtime error. |
| 2644 | <li> <code>LUA_ERRMEM</code> — memory allocation error. | 2649 | <li> <code>LUA_ERRMEM</code> --- memory allocation error. |
| 2645 | For such errors, Lua does not call the error handler function. | 2650 | For such errors, Lua does not call the error handler function. |
| 2646 | <li> <code>LUA_ERRERR</code> — | 2651 | <li> <code>LUA_ERRERR</code> --- |
| 2647 | error while running the error handler function. | 2652 | error while running the error handler function. |
| 2648 | </ul> | 2653 | </ul> |
| 2649 | | 2654 | |
| 2650 | <p><a name="lua_pop"></a> | 2655 | <p><a name="lua_pop"></a> |
| 2651 | <hr><h3><code>lua_pop</code></h3> | 2656 | <hr/><h3><code>lua_pop</code></h3> |
| 2652 | <pre> | 2657 | <pre> |
| 2653 | void lua_pop (lua_State *L, int n); | 2658 | void lua_pop (lua_State *L, int n); |
| 2654 | </pre> | 2659 | </pre> |
| @@ -2657,7 +2662,7 @@ error while running the error handler function. · 2 unmodified lines |
| 2657 | <p>Pops <code>n</code> elements from the stack. | 2662 | <p>Pops <code>n</code> elements from the stack. |
| 2658 | | 2663 | |
| 2659 | <p><a name="lua_pushboolean"></a> | 2664 | <p><a name="lua_pushboolean"></a> |
| 2660 | <hr><h3><code>lua_pushboolean</code></h3> | 2665 | <hr/><h3><code>lua_pushboolean</code></h3> |
| 2661 | <pre> | 2666 | <pre> |
| 2662 | void lua_pushboolean (lua_State *L, int b); | 2667 | void lua_pushboolean (lua_State *L, int b); |
| 2663 | </pre> | 2668 | </pre> |
| @@ -2666,7 +2671,7 @@ error while running the error handler function. · 2 unmodified lines |
| 2666 | <p>Pushes a boolean value with value <code>b</code> onto the stack. | 2671 | <p>Pushes a boolean value with value <code>b</code> onto the stack. |
| 2667 | | 2672 | |
| 2668 | <p><a name="lua_pushcclosure"></a> | 2673 | <p><a name="lua_pushcclosure"></a> |
| 2669 | <hr><h3><code>lua_pushcclosure</code></h3> | 2674 | <hr/><h3><code>lua_pushcclosure</code></h3> |
| 2670 | <pre> | 2675 | <pre> |
| 2671 | void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); | 2676 | void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); |
| 2672 | </pre> | 2677 | </pre> |
| @@ -2688,7 +2693,7 @@ associated with the function. · 15 unmodified lines |
| 2688 | <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack. | 2693 | <a href="#lua_pushcclosure"><code>lua_pushcclosure</code></a> also pops these values from the stack. |
| 2689 | | 2694 | |
| 2690 | <p><a name="lua_pushcfunction"></a> | 2695 | <p><a name="lua_pushcfunction"></a> |
| 2691 | <hr><h3><code>lua_pushcfunction</code></h3> | 2696 | <hr/><h3><code>lua_pushcfunction</code></h3> |
| 2692 | <pre> | 2697 | <pre> |
| 2693 | void lua_pushcfunction (lua_State *L, lua_CFunction f); | 2698 | void lua_pushcfunction (lua_State *L, lua_CFunction f); |
| 2694 | </pre> | 2699 | </pre> |
| @@ -2698,7 +2703,7 @@ associated with the function. · 3 unmodified lines |
| 2698 | This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>. | 2703 | This function is equivalent to <code>lua_pushcclosure(L, f, 0);</code>. |
| 2699 | | 2704 | |
| 2700 | <p><a name="lua_pushfstring"></a> | 2705 | <p><a name="lua_pushfstring"></a> |
| 2701 | <hr><h3><code>lua_pushfstring</code></h3> | 2706 | <hr/><h3><code>lua_pushfstring</code></h3> |
| 2702 | <pre> | 2707 | <pre> |
| 2703 | const char *lua_pushfstring (lua_State *L, const char *fmt, ...); | 2708 | const char *lua_pushfstring (lua_State *L, const char *fmt, ...); |
| 2704 | </pre> | 2709 | </pre> |
| @@ -2724,7 +2729,7 @@ The conversion specifiers can be simply · 19 unmodified lines |
| 2724 | </ul> | 2729 | </ul> |
| 2725 | | 2730 | |
| 2726 | <p><a name="lua_pushinteger"></a> | 2731 | <p><a name="lua_pushinteger"></a> |
| 2727 | <hr><h3><code>lua_pushinteger</code></h3> | 2732 | <hr/><h3><code>lua_pushinteger</code></h3> |
| 2728 | <pre> | 2733 | <pre> |
| 2729 | void lua_pushinteger (lua_State *L, lua_Integer n); | 2734 | void lua_pushinteger (lua_State *L, lua_Integer n); |
| 2730 | </pre> | 2735 | </pre> |
| @@ -2733,7 +2738,7 @@ The conversion specifiers can be simply · 2 unmodified lines |
| 2733 | <p>Pushes a number with value <code>n</code> onto the stack. | 2738 | <p>Pushes a number with value <code>n</code> onto the stack. |
| 2734 | | 2739 | |
| 2735 | <p><a name="lua_pushlightuserdata"></a> | 2740 | <p><a name="lua_pushlightuserdata"></a> |
| 2736 | <hr><h3><code>lua_pushlightuserdata</code></h3> | 2741 | <hr/><h3><code>lua_pushlightuserdata</code></h3> |
| 2737 | <pre> | 2742 | <pre> |
| 2738 | void lua_pushlightuserdata (lua_State *L, void *p); | 2743 | void lua_pushlightuserdata (lua_State *L, void *p); |
| 2739 | </pre> | 2744 | </pre> |
| @@ -2750,7 +2755,7 @@ A light userdata is equal to "any" · 10 unmodified lines |
| 2750 | light userdata with the same C address. | 2755 | light userdata with the same C address. |
| 2751 | | 2756 | |
| 2752 | <p><a name="lua_pushlstring"></a> | 2757 | <p><a name="lua_pushlstring"></a> |
| 2753 | <hr><h3><code>lua_pushlstring</code></h3> | 2758 | <hr/><h3><code>lua_pushlstring</code></h3> |
| 2754 | <pre> | 2759 | <pre> |
| 2755 | void lua_pushlstring (lua_State *L, const char *s, size_t len); | 2760 | void lua_pushlstring (lua_State *L, const char *s, size_t len); |
| 2756 | </pre> | 2761 | </pre> |
| @@ -2763,7 +2768,7 @@ so the memory at <code>s</code> can be freed or reused immediately after · 6 unmodified lines |
| 2763 | the function returns. | 2768 | the function returns. |
| 2764 | | 2769 | |
| 2765 | <p><a name="lua_pushnil"></a> | 2770 | <p><a name="lua_pushnil"></a> |
| 2766 | <hr><h3><code>lua_pushnil</code></h3> | 2771 | <hr/><h3><code>lua_pushnil</code></h3> |
| 2767 | <pre> | 2772 | <pre> |
| 2768 | void lua_pushnil (lua_State *L); | 2773 | void lua_pushnil (lua_State *L); |
| 2769 | </pre> | 2774 | </pre> |
| @@ -2772,7 +2777,7 @@ the function returns. · 2 unmodified lines |
| 2772 | <p>Pushes a nil value onto the stack. | 2777 | <p>Pushes a nil value onto the stack. |
| 2773 | | 2778 | |
| 2774 | <p><a name="lua_pushnumber"></a> | 2779 | <p><a name="lua_pushnumber"></a> |
| 2775 | <hr><h3><code>lua_pushnumber</code></h3> | 2780 | <hr/><h3><code>lua_pushnumber</code></h3> |
| 2776 | <pre> | 2781 | <pre> |
| 2777 | void lua_pushnumber (lua_State *L, lua_Number n); | 2782 | void lua_pushnumber (lua_State *L, lua_Number n); |
| 2778 | </pre> | 2783 | </pre> |
| @@ -2781,7 +2786,7 @@ the function returns. · 2 unmodified lines |
| 2781 | <p>Pushes a number with value <code>n</code> onto the stack. | 2786 | <p>Pushes a number with value <code>n</code> onto the stack. |
| 2782 | | 2787 | |
| 2783 | <p><a name="lua_pushstring"></a> | 2788 | <p><a name="lua_pushstring"></a> |
| 2784 | <hr><h3><code>lua_pushstring</code></h3> | 2789 | <hr/><h3><code>lua_pushstring</code></h3> |
| 2785 | <pre> | 2790 | <pre> |
| 2786 | void lua_pushstring (lua_State *L, const char *s); | 2791 | void lua_pushstring (lua_State *L, const char *s); |
| 2787 | </pre> | 2792 | </pre> |
| @@ -2794,7 +2799,7 @@ so the memory at <code>s</code> can be freed or reused immediately after · 6 unmodified lines |
| 2794 | the function returns. | 2799 | the function returns. |
| 2795 | | 2800 | |
| 2796 | <p><a name="lua_pushvalue"></a> | 2801 | <p><a name="lua_pushvalue"></a> |
| 2797 | <hr><h3><code>lua_pushvalue</code></h3> | 2802 | <hr/><h3><code>lua_pushvalue</code></h3> |
| 2798 | <pre> | 2803 | <pre> |
| 2799 | void lua_pushvalue (lua_State *L, int index); | 2804 | void lua_pushvalue (lua_State *L, int index); |
| 2800 | </pre> | 2805 | </pre> |
| @@ -2804,7 +2809,7 @@ the function returns. · 3 unmodified lines |
| 2804 | onto the stack. | 2809 | onto the stack. |
| 2805 | | 2810 | |
| 2806 | <p><a name="lua_pushvfstring"></a> | 2811 | <p><a name="lua_pushvfstring"></a> |
| 2807 | <hr><h3><code>lua_pushvfstring</code></h3> | 2812 | <hr/><h3><code>lua_pushvfstring</code></h3> |
| 2808 | <pre> | 2813 | <pre> |
| 2809 | const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp); | 2814 | const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp); |
| 2810 | </pre> | 2815 | </pre> |
| @@ -2814,7 +2819,7 @@ onto the stack. · 3 unmodified lines |
| 2814 | instead of a variable number of arguments. | 2819 | instead of a variable number of arguments. |
| 2815 | | 2820 | |
| 2816 | <p><a name="lua_rawequal"></a> | 2821 | <p><a name="lua_rawequal"></a> |
| 2817 | <hr><h3><code>lua_rawequal</code></h3> | 2822 | <hr/><h3><code>lua_rawequal</code></h3> |
| 2818 | <pre> | 2823 | <pre> |
| 2819 | int lua_rawequal (lua_State *L, int index1, int index2); | 2824 | int lua_rawequal (lua_State *L, int index1, int index2); |
| 2820 | </pre> | 2825 | </pre> |
| @@ -2827,7 +2832,7 @@ Otherwise returns 0. · 6 unmodified lines |
| 2827 | Also returns 0 if any of the indices are non valid. | 2832 | Also returns 0 if any of the indices are non valid. |
| 2828 | | 2833 | |
| 2829 | <p><a name="lua_rawget"></a> | 2834 | <p><a name="lua_rawget"></a> |
| 2830 | <hr><h3><code>lua_rawget</code></h3> | 2835 | <hr/><h3><code>lua_rawget</code></h3> |
| 2831 | <pre> | 2836 | <pre> |
| 2832 | void lua_rawget (lua_State *L, int index); | 2837 | void lua_rawget (lua_State *L, int index); |
| 2833 | </pre> | 2838 | </pre> |
| @@ -2837,7 +2842,7 @@ Also returns 0 if any of the indices are non valid. · 3 unmodified lines |
| 2837 | (i.e., without metamethods). | 2842 | (i.e., without metamethods). |
| 2838 | | 2843 | |
| 2839 | <p><a name="lua_rawgeti"></a> | 2844 | <p><a name="lua_rawgeti"></a> |
| 2840 | <hr><h3><code>lua_rawgeti</code></h3> | 2845 | <hr/><h3><code>lua_rawgeti</code></h3> |
| 2841 | <pre> | 2846 | <pre> |
| 2842 | void lua_rawgeti (lua_State *L, int index, int n); | 2847 | void lua_rawgeti (lua_State *L, int index, int n); |
| 2843 | </pre> | 2848 | </pre> |
| @@ -2849,7 +2854,7 @@ The access is raw, · 5 unmodified lines |
| 2849 | that is, it does not invoke metamethods. | 2854 | that is, it does not invoke metamethods. |
| 2850 | | 2855 | |
| 2851 | <p><a name="lua_rawset"></a> | 2856 | <p><a name="lua_rawset"></a> |
| 2852 | <hr><h3><code>lua_rawset</code></h3> | 2857 | <hr/><h3><code>lua_rawset</code></h3> |
| 2853 | <pre> | 2858 | <pre> |
| 2854 | void lua_rawset (lua_State *L, int index); | 2859 | void lua_rawset (lua_State *L, int index); |
| 2855 | </pre> | 2860 | </pre> |
| @@ -2859,7 +2864,7 @@ that is, it does not invoke metamethods. · 3 unmodified lines |
| 2859 | (i.e., without metamethods). | 2864 | (i.e., without metamethods). |
| 2860 | | 2865 | |
| 2861 | <p><a name="lua_rawseti"></a> | 2866 | <p><a name="lua_rawseti"></a> |
| 2862 | <hr><h3><code>lua_rawseti</code></h3> | 2867 | <hr/><h3><code>lua_rawseti</code></h3> |
| 2863 | <pre> | 2868 | <pre> |
| 2864 | void lua_rawseti (lua_State *L, int index, int n); | 2869 | void lua_rawseti (lua_State *L, int index, int n); |
| 2865 | </pre> | 2870 | </pre> |
| @@ -2874,7 +2879,7 @@ The assignment is raw, · 8 unmodified lines |
| 2874 | that is, it does not invoke metamethods. | 2879 | that is, it does not invoke metamethods. |
| 2875 | | 2880 | |
| 2876 | <p><a name="lua_Reader"></a> | 2881 | <p><a name="lua_Reader"></a> |
| 2877 | <hr><h3><code>lua_Reader</code></h3> | 2882 | <hr/><h3><code>lua_Reader</code></h3> |
| 2878 | <pre> | 2883 | <pre> |
| 2879 | typedef const char * (*lua_Reader) | 2884 | typedef const char * (*lua_Reader) |
| 2880 | (lua_State *L, void *data, size_t *size); | 2885 | (lua_State *L, void *data, size_t *size); |
| @@ -2893,7 +2898,7 @@ To signal the end of the chunk, the reader returns <code>NULL</code>. · 12 unmodified lines |
| 2893 | The reader function may return pieces of any size greater than zero. | 2898 | The reader function may return pieces of any size greater than zero. |
| 2894 | | 2899 | |
| 2895 | <p><a name="lua_remove"></a> | 2900 | <p><a name="lua_remove"></a> |
| 2896 | <hr><h3><code>lua_remove</code></h3> | 2901 | <hr/><h3><code>lua_remove</code></h3> |
| 2897 | <pre> | 2902 | <pre> |
| 2898 | void lua_remove (lua_State *L, int index); | 2903 | void lua_remove (lua_State *L, int index); |
| 2899 | </pre> | 2904 | </pre> |
| @@ -2905,7 +2910,7 @@ Cannot be called with a pseudo-index, · 5 unmodified lines |
| 2905 | because a pseudo-index is not an actual stack position. | 2910 | because a pseudo-index is not an actual stack position. |
| 2906 | | 2911 | |
| 2907 | <p><a name="lua_replace"></a> | 2912 | <p><a name="lua_replace"></a> |
| 2908 | <hr><h3><code>lua_replace</code></h3> | 2913 | <hr/><h3><code>lua_replace</code></h3> |
| 2909 | <pre> | 2914 | <pre> |
| 2910 | void lua_replace (lua_State *L, int index); | 2915 | void lua_replace (lua_State *L, int index); |
| 2911 | </pre> | 2916 | </pre> |
| @@ -2916,7 +2921,7 @@ without shifting any element · 4 unmodified lines |
| 2916 | (therefore replacing the value at the given position). | 2921 | (therefore replacing the value at the given position). |
| 2917 | | 2922 | |
| 2918 | <p><a name="lua_resume"></a> | 2923 | <p><a name="lua_resume"></a> |
| 2919 | <hr><h3><code>lua_resume</code></h3> | 2924 | <hr/><h3><code>lua_resume</code></h3> |
| 2920 | <pre> | 2925 | <pre> |
| 2921 | int lua_resume (lua_State *L, int narg); | 2926 | int lua_resume (lua_State *L, int narg); |
| 2922 | </pre> | 2927 | </pre> |
| @@ -2932,8 +2937,11 @@ with <code>narg</code> being the number of arguments. · 9 unmodified lines |
| 2932 | This call returns when the coroutine suspends or finishes its execution. | 2937 | This call returns when the coroutine suspends or finishes its execution. |
| 2933 | When it returns, the stack contains all values passed to <a href="#lua_yield"><code>lua_yield</code></a>, | 2938 | When it returns, the stack contains all values passed to <a href="#lua_yield"><code>lua_yield</code></a>, |
| 2934 | or all values returned by the body function. | 2939 | or all values returned by the body function. |
| 2935 | <a href="#lua_resume"><code>lua_resume</code></a> returns 0 if there are no errors running the coroutine, | 2940 | <a href="#lua_resume"><code>lua_resume</code></a> returns |
| 2936 | or an error code (see <a href="#lua_pcall"><code>lua_pcall</code></a>). | 2941 | <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> if the coroutine yields, |
| | 2942 | 0 if the coroutine finishes its execution |
| | 2943 | without errors, |
| | 2944 | or an error code in case of errors (see <a href="#lua_pcall"><code>lua_pcall</code></a>). |
| 2937 | In case of errors, | 2945 | In case of errors, |
| 2938 | the stack is not unwound, | 2946 | the stack is not unwound, |
| 2939 | so you can use the debug API over it; | 2947 | so you can use the debug API over it; |
| @@ -2942,8 +2950,18 @@ To restart a coroutine, you put on its stack only the values to · 2 unmodified lines |
| 2942 | be passed as results from <code>yield</code>, | 2950 | be passed as results from <code>yield</code>, |
| 2943 | and then call <a href="#lua_resume"><code>lua_resume</code></a>. | 2951 | and then call <a href="#lua_resume"><code>lua_resume</code></a>. |
| 2944 | | 2952 | |
| | 2953 | <p><a name="lua_setallocf"></a> |
| | 2954 | <hr/><h3><code>lua_setallocf</code></h3> |
| | 2955 | <pre> |
| | 2956 | void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); |
| | 2957 | </pre> |
| | 2958 | |
| | 2959 | |
| | 2960 | <p>Changes the allocator function of a given state to <code>f</code> |
| | 2961 | with user data <code>ud</code>. |
| | 2962 | |
| 2945 | <p><a name="lua_setfenv"></a> | 2963 | <p><a name="lua_setfenv"></a> |
| 2946 | <hr><h3><code>lua_setfenv</code></h3> | 2964 | <hr/><h3><code>lua_setfenv</code></h3> |
| 2947 | <pre> | 2965 | <pre> |
| 2948 | int lua_setfenv (lua_State *L, int index); | 2966 | int lua_setfenv (lua_State *L, int index); |
| 2949 | </pre> | 2967 | </pre> |
| @@ -2956,7 +2974,7 @@ neither a function nor a thread nor a userdata, · 6 unmodified lines |
| 2956 | <a href="#lua_setfenv"><code>lua_setfenv</code></a> returns 0 (false). | 2974 | <a href="#lua_setfenv"><code>lua_setfenv</code></a> returns 0 (false). |
| 2957 | | 2975 | |
| 2958 | <p><a name="lua_setfield"></a> | 2976 | <p><a name="lua_setfield"></a> |
| 2959 | <hr><h3><code>lua_setfield</code></h3> | 2977 | <hr/><h3><code>lua_setfield</code></h3> |
| 2960 | <pre> | 2978 | <pre> |
| 2961 | void lua_setfield (lua_State *L, int index, const char *k); | 2979 | void lua_setfield (lua_State *L, int index, const char *k); |
| 2962 | </pre> | 2980 | </pre> |
| @@ -2971,7 +2989,7 @@ As in Lua, this function may trigger a metamethod · 8 unmodified lines |
| 2971 | for the "newindex" event (see <a href="#metatable">2.8</a>). | 2989 | for the "newindex" event (see <a href="#metatable">2.8</a>). |
| 2972 | | 2990 | |
| 2973 | <p><a name="lua_setmetatable"></a> | 2991 | <p><a name="lua_setmetatable"></a> |
| 2974 | <hr><h3><code>lua_setmetatable</code></h3> | 2992 | <hr/><h3><code>lua_setmetatable</code></h3> |
| 2975 | <pre> | 2993 | <pre> |
| 2976 | int lua_setmetatable (lua_State *L, int index); | 2994 | int lua_setmetatable (lua_State *L, int index); |
| 2977 | </pre> | 2995 | </pre> |
| @@ -2982,7 +3000,7 @@ sets it as the new metatable for the value at the given · 4 unmodified lines |
| 2982 | acceptable index. | 3000 | acceptable index. |
| 2983 | | 3001 | |
| 2984 | <p><a name="lua_settable"></a> | 3002 | <p><a name="lua_settable"></a> |
| 2985 | <hr><h3><code>lua_settable</code></h3> | 3003 | <hr/><h3><code>lua_settable</code></h3> |
| 2986 | <pre> | 3004 | <pre> |
| 2987 | void lua_settable (lua_State *L, int index); | 3005 | void lua_settable (lua_State *L, int index); |
| 2988 | </pre> | 3006 | </pre> |
| @@ -2998,7 +3016,7 @@ As in Lua, this function may trigger a metamethod · 9 unmodified lines |
| 2998 | for the "newindex" event (see <a href="#metatable">2.8</a>). | 3016 | for the "newindex" event (see <a href="#metatable">2.8</a>). |
| 2999 | | 3017 | |
| 3000 | <p><a name="lua_settop"></a> | 3018 | <p><a name="lua_settop"></a> |
| 3001 | <hr><h3><code>lua_settop</code></h3> | 3019 | <hr/><h3><code>lua_settop</code></h3> |
| 3002 | <pre> | 3020 | <pre> |
| 3003 | void lua_settop (lua_State *L, int index); | 3021 | void lua_settop (lua_State *L, int index); |
| 3004 | </pre> | 3022 | </pre> |
| @@ -3007,11 +3025,11 @@ for the "newindex" event (see <a href="#metatable">2.8</a>). · 2 unmodified lines |
| 3007 | <p>Accepts any acceptable index, or 0, | 3025 | <p>Accepts any acceptable index, or 0, |
| 3008 | and sets the stack top to that index. | 3026 | and sets the stack top to that index. |
| 3009 | If the new top is larger than the old one, | 3027 | If the new top is larger than the old one, |
| 3010 | then the new elements are filled with <B>nil</B>. | 3028 | then the new elements are filled with <b>nil</b>. |
| 3011 | If <code>index</code> is 0, then all stack elements are removed. | 3029 | If <code>index</code> is 0, then all stack elements are removed. |
| 3012 | | 3030 | |
| 3013 | <p><a name="lua_State"></a> | 3031 | <p><a name="lua_State"></a> |
| 3014 | <hr><h3><code>lua_State</code></h3> | 3032 | <hr/><h3><code>lua_State</code></h3> |
| 3015 | <pre> | 3033 | <pre> |
| 3016 | typedef struct lua_State lua_State; | 3034 | typedef struct lua_State lua_State; |
| 3017 | </pre> | 3035 | </pre> |
| @@ -3027,7 +3045,7 @@ every function in the library, except to <a href="#lua_newstate"><code>lua_newst · 9 unmodified lines |
| 3027 | which creates a Lua state from scratch. | 3045 | which creates a Lua state from scratch. |
| 3028 | | 3046 | |
| 3029 | <p><a name="lua_toboolean"></a> | 3047 | <p><a name="lua_toboolean"></a> |
| 3030 | <hr><h3><code>lua_toboolean</code></h3> | 3048 | <hr/><h3><code>lua_toboolean</code></h3> |
| 3031 | <pre> | 3049 | <pre> |
| 3032 | int lua_toboolean (lua_State *L, int index); | 3050 | int lua_toboolean (lua_State *L, int index); |
| 3033 | </pre> | 3051 | </pre> |
| @@ -3037,14 +3055,14 @@ which creates a Lua state from scratch. · 3 unmodified lines |
| 3037 | value ((0 or 1). | 3055 | value ((0 or 1). |
| 3038 | Like all tests in Lua, | 3056 | Like all tests in Lua, |
| 3039 | <a href="#lua_toboolean"><code>lua_toboolean</code></a> returns 1 for any Lua value | 3057 | <a href="#lua_toboolean"><code>lua_toboolean</code></a> returns 1 for any Lua value |
| 3040 | different from <B>false</B> and <B>nil</B>; | 3058 | different from <b>false</b> and <b>nil</b>; |
| 3041 | otherwise it returns 0. | 3059 | otherwise it returns 0. |
| 3042 | It also returns 0 when called with a non-valid index. | 3060 | It also returns 0 when called with a non-valid index. |
| 3043 | (If you want to accept only real boolean values, | 3061 | (If you want to accept only real boolean values, |
| 3044 | use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.) | 3062 | use <a href="#lua_isboolean"><code>lua_isboolean</code></a> to test the value's type.) |
| 3045 | | 3063 | |
| 3046 | <p><a name="lua_tocfunction"></a> | 3064 | <p><a name="lua_tocfunction"></a> |
| 3047 | <hr><h3><code>lua_tocfunction</code></h3> | 3065 | <hr/><h3><code>lua_tocfunction</code></h3> |
| 3048 | <pre> | 3066 | <pre> |
| 3049 | lua_CFunction lua_tocfunction (lua_State *L, int index); | 3067 | lua_CFunction lua_tocfunction (lua_State *L, int index); |
| 3050 | </pre> | 3068 | </pre> |
| @@ -3055,7 +3073,7 @@ That value must be a C function; · 4 unmodified lines |
| 3055 | otherwise, returns <code>NULL</code>. | 3073 | otherwise, returns <code>NULL</code>. |
| 3056 | | 3074 | |
| 3057 | <p><a name="lua_tointeger"></a> | 3075 | <p><a name="lua_tointeger"></a> |
| 3058 | <hr><h3><code>lua_tointeger</code></h3> | 3076 | <hr/><h3><code>lua_tointeger</code></h3> |
| 3059 | <pre> | 3077 | <pre> |
| 3060 | lua_Integer lua_tointeger (lua_State *L, int idx); | 3078 | lua_Integer lua_tointeger (lua_State *L, int idx); |
| 3061 | </pre> | 3079 | </pre> |
| @@ -3071,7 +3089,7 @@ otherwise, <a href="#lua_tointeger"><code>lua_tointeger</code></a> returns 0. · 9 unmodified lines |
| 3071 | it is truncated in some non-specified way. | 3089 | it is truncated in some non-specified way. |
| 3072 | | 3090 | |
| 3073 | <p><a name="lua_tolstring"></a> | 3091 | <p><a name="lua_tolstring"></a> |
| 3074 | <hr><h3><code>lua_tolstring</code></h3> | 3092 | <hr/><h3><code>lua_tolstring</code></h3> |
| 3075 | <pre> | 3093 | <pre> |
| 3076 | const char *lua_tolstring (lua_State *L, int index, size_t *len); | 3094 | const char *lua_tolstring (lua_State *L, int index, size_t *len); |
| 3077 | </pre> | 3095 | </pre> |
| @@ -3099,7 +3117,7 @@ there is no guarantee that the pointer returned by <a href="#lua_tolstring"><cod · 21 unmodified lines |
| 3099 | will be valid after the corresponding value is removed from the stack. | 3117 | will be valid after the corresponding value is removed from the stack. |
| 3100 | | 3118 | |
| 3101 | <p><a name="lua_tonumber"></a> | 3119 | <p><a name="lua_tonumber"></a> |
| 3102 | <hr><h3><code>lua_tonumber</code></h3> | 3120 | <hr/><h3><code>lua_tonumber</code></h3> |
| 3103 | <pre> | 3121 | <pre> |
| 3104 | lua_Number lua_tonumber (lua_State *L, int index); | 3122 | lua_Number lua_tonumber (lua_State *L, int index); |
| 3105 | </pre> | 3123 | </pre> |
| @@ -3112,7 +3130,7 @@ The Lua value must be a number or a string convertible to number · 6 unmodified lines |
| 3112 | otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0. | 3130 | otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0. |
| 3113 | | 3131 | |
| 3114 | <p><a name="lua_topointer"></a> | 3132 | <p><a name="lua_topointer"></a> |
| 3115 | <hr><h3><code>lua_topointer</code></h3> | 3133 | <hr/><h3><code>lua_topointer</code></h3> |
| 3116 | <pre> | 3134 | <pre> |
| 3117 | const void *lua_topointer (lua_State *L, int index); | 3135 | const void *lua_topointer (lua_State *L, int index); |
| 3118 | </pre> | 3136 | </pre> |
| @@ -3128,7 +3146,7 @@ There is no direct way to convert the pointer back to its original value. · 9 unmodified lines |
| 3128 | <p>Typically this function is used for debug information. | 3146 | <p>Typically this function is used for debug information. |
| 3129 | | 3147 | |
| 3130 | <p><a name="lua_tostring"></a> | 3148 | <p><a name="lua_tostring"></a> |
| 3131 | <hr><h3><code>lua_tostring</code></h3> | 3149 | <hr/><h3><code>lua_tostring</code></h3> |
| 3132 | <pre> | 3150 | <pre> |
| 3133 | const char *lua_tostring (lua_State *L, int index); | 3151 | const char *lua_tostring (lua_State *L, int index); |
| 3134 | </pre> | 3152 | </pre> |
| @@ -3137,7 +3155,7 @@ There is no direct way to convert the pointer back to its original value. · 2 unmodified lines |
| 3137 | <p>Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>. | 3155 | <p>Equivalent to <a href="#lua_tolstring"><code>lua_tolstring</code></a> with <code>len</code> equal to <code>NULL</code>. |
| 3138 | | 3156 | |
| 3139 | <p><a name="lua_tothread"></a> | 3157 | <p><a name="lua_tothread"></a> |
| 3140 | <hr><h3><code>lua_tothread</code></h3> | 3158 | <hr/><h3><code>lua_tothread</code></h3> |
| 3141 | <pre> | 3159 | <pre> |
| 3142 | lua_State *lua_tothread (lua_State *L, int index); | 3160 | lua_State *lua_tothread (lua_State *L, int index); |
| 3143 | </pre> | 3161 | </pre> |
| @@ -3149,7 +3167,7 @@ This value must be a thread; · 5 unmodified lines |
| 3149 | otherwise, the function returns <code>NULL</code>. | 3167 | otherwise, the function returns <code>NULL</code>. |
| 3150 | | 3168 | |
| 3151 | <p><a name="lua_touserdata"></a> | 3169 | <p><a name="lua_touserdata"></a> |
| 3152 | <hr><h3><code>lua_touserdata</code></h3> | 3170 | <hr/><h3><code>lua_touserdata</code></h3> |
| 3153 | <pre> | 3171 | <pre> |
| 3154 | void *lua_touserdata (lua_State *L, int index); | 3172 | void *lua_touserdata (lua_State *L, int index); |
| 3155 | </pre> | 3173 | </pre> |
| @@ -3162,7 +3180,7 @@ returns its pointer. · 6 unmodified lines |
| 3162 | Otherwise, returns <code>NULL</code>. | 3180 | Otherwise, returns <code>NULL</code>. |
| 3163 | | 3181 | |
| 3164 | <p><a name="lua_type"></a> | 3182 | <p><a name="lua_type"></a> |
| 3165 | <hr><h3><code>lua_type</code></h3> | 3183 | <hr/><h3><code>lua_type</code></h3> |
| 3166 | <pre> | 3184 | <pre> |
| 3167 | int lua_type (lua_State *L, int index); | 3185 | int lua_type (lua_State *L, int index); |
| 3168 | </pre> | 3186 | </pre> |
| @@ -3184,7 +3202,7 @@ defined in <code>lua.h</code>: · 15 unmodified lines |
| 3184 | <code>LUA_TLIGHTUSERDATA</code>. | 3202 | <code>LUA_TLIGHTUSERDATA</code>. |
| 3185 | | 3203 | |
| 3186 | <p><a name="lua_Writer"></a> | 3204 | <p><a name="lua_Writer"></a> |
| 3187 | <hr><h3><code>lua_Writer</code></h3> | 3205 | <hr/><h3><code>lua_Writer</code></h3> |
| 3188 | <pre> | 3206 | <pre> |
| 3189 | typedef int (*lua_Writer) | 3207 | typedef int (*lua_Writer) |
| 3190 | (lua_State *L, const void* p, size_t sz, void* ud); | 3208 | (lua_State *L, const void* p, size_t sz, void* ud); |
| @@ -3205,7 +3223,7 @@ any other value means an error and stops <a href="#lua_dump"><code>lua_dump</cod · 14 unmodified lines |
| 3205 | calling the writer again. | 3223 | calling the writer again. |
| 3206 | | 3224 | |
| 3207 | <p><a name="lua_xmove"></a> | 3225 | <p><a name="lua_xmove"></a> |
| 3208 | <hr><h3><code>lua_xmove</code></h3> | 3226 | <hr/><h3><code>lua_xmove</code></h3> |
| 3209 | <pre> | 3227 | <pre> |
| 3210 | void lua_xmove (lua_State *from, lua_State *to, int n); | 3228 | void lua_xmove (lua_State *from, lua_State *to, int n); |
| 3211 | </pre> | 3229 | </pre> |
| @@ -3217,7 +3235,7 @@ calling the writer again. · 5 unmodified lines |
| 3217 | and pushes them into the stack <code>to</code>. | 3235 | and pushes them into the stack <code>to</code>. |
| 3218 | | 3236 | |
| 3219 | <p><a name="lua_yield"></a> | 3237 | <p><a name="lua_yield"></a> |
| 3220 | <hr><h3><code>lua_yield</code></h3> | 3238 | <hr/><h3><code>lua_yield</code></h3> |
| 3221 | <pre> | 3239 | <pre> |
| 3222 | int lua_yield (lua_State *L, int nresults); | 3240 | int lua_yield (lua_State *L, int nresults); |
| 3223 | </pre> | 3241 | </pre> |
| @@ -3227,9 +3245,9 @@ and pushes them into the stack <code>to</code>. · 3 unmodified lines |
| 3227 | | 3245 | |
| 3228 | <p>This function can only be called as the | 3246 | <p>This function can only be called as the |
| 3229 | return expression of a C function, as follows: | 3247 | return expression of a C function, as follows: |
| 3230 | <PRE> | 3248 | <pre> |
| 3231 | return lua_yield (L, nresults); | 3249 | return lua_yield (L, nresults); |
| 3232 | </PRE> | 3250 | </pre> |
| 3233 | When a C function calls <a href="#lua_yield"><code>lua_yield</code></a> in that way, | 3251 | When a C function calls <a href="#lua_yield"><code>lua_yield</code></a> in that way, |
| 3234 | the running coroutine suspends its execution, | 3252 | the running coroutine suspends its execution, |
| 3235 | and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine returns. | 3253 | and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine returns. |
| @@ -3247,7 +3265,7 @@ kinds of debuggers, profilers, and other tools · 11 unmodified lines |
| 3247 | that need "inside information" from the interpreter. | 3265 | that need "inside information" from the interpreter. |
| 3248 | | 3266 | |
| 3249 | <p><a name="lua_Debug"></a> | 3267 | <p><a name="lua_Debug"></a> |
| 3250 | <hr><h3><code>lua_Debug</code></h3> | 3268 | <hr/><h3><code>lua_Debug</code></h3> |
| 3251 | <pre> | 3269 | <pre> |
| 3252 | typedef struct lua_Debug { | 3270 | typedef struct lua_Debug { |
| 3253 | int event; | 3271 | int event; |
| @@ -3260,8 +3278,8 @@ that need "inside information" from the interpreter. · 6 unmodified lines |
| 3260 | int linedefined; /* (S) */ | 3278 | int linedefined; /* (S) */ |
| 3261 | int lastlinedefined; /* (S) */ | 3279 | int lastlinedefined; /* (S) */ |
| 3262 | char short_src[LUA_IDSIZE]; /* (S) */ | 3280 | char short_src[LUA_IDSIZE]; /* (S) */ |
| 3263 | | 3281 | |
| 3264 | <p> /* private part */ | 3282 | /* private part */ |
| 3265 | ... | 3283 | ... |
| 3266 | } lua_Debug; | 3284 | } lua_Debug; |
| 3267 | | 3285 | |
| @@ -3329,7 +3347,7 @@ The number of upvalues of the function. · 61 unmodified lines |
| 3329 | <p></ul> | 3347 | <p></ul> |
| 3330 | | 3348 | |
| 3331 | <p><a name="lua_gethook"></a> | 3349 | <p><a name="lua_gethook"></a> |
| 3332 | <hr><h3><code>lua_gethook</code></h3> | 3350 | <hr/><h3><code>lua_gethook</code></h3> |
| 3333 | <pre> | 3351 | <pre> |
| 3334 | lua_Hook lua_gethook (lua_State *L); | 3352 | lua_Hook lua_gethook (lua_State *L); |
| 3335 | </pre> | 3353 | </pre> |
| @@ -3338,7 +3356,7 @@ The number of upvalues of the function. · 2 unmodified lines |
| 3338 | <p>Returns the current hook function. | 3356 | <p>Returns the current hook function. |
| 3339 | | 3357 | |
| 3340 | <p><a name="lua_gethookcount"></a> | 3358 | <p><a name="lua_gethookcount"></a> |
| 3341 | <hr><h3><code>lua_gethookcount</code></h3> | 3359 | <hr/><h3><code>lua_gethookcount</code></h3> |
| 3342 | <pre> | 3360 | <pre> |
| 3343 | int lua_gethookcount (lua_State *L); | 3361 | int lua_gethookcount (lua_State *L); |
| 3344 | </pre> | 3362 | </pre> |
| @@ -3347,7 +3365,7 @@ The number of upvalues of the function. · 2 unmodified lines |
| 3347 | <p>Returns the current hook count. | 3365 | <p>Returns the current hook count. |
| 3348 | | 3366 | |
| 3349 | <p><a name="lua_gethookmask"></a> | 3367 | <p><a name="lua_gethookmask"></a> |
| 3350 | <hr><h3><code>lua_gethookmask</code></h3> | 3368 | <hr/><h3><code>lua_gethookmask</code></h3> |
| 3351 | <pre> | 3369 | <pre> |
| 3352 | int lua_gethookmask (lua_State *L); | 3370 | int lua_gethookmask (lua_State *L); |
| 3353 | </pre> | 3371 | </pre> |
| @@ -3356,7 +3374,7 @@ The number of upvalues of the function. · 2 unmodified lines |
| 3356 | <p>Returns the current hook mask. | 3374 | <p>Returns the current hook mask. |
| 3357 | | 3375 | |
| 3358 | <p><a name="lua_getinfo"></a> | 3376 | <p><a name="lua_getinfo"></a> |
| 3359 | <hr><h3><code>lua_getinfo</code></h3> | 3377 | <hr/><h3><code>lua_getinfo</code></h3> |
| 3360 | <pre> | 3378 | <pre> |
| 3361 | int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); | 3379 | int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); |
| 3362 | </pre> | 3380 | </pre> |
| @@ -3382,15 +3400,15 @@ you push it onto the stack · 19 unmodified lines |
| 3382 | and start the <code>what</code> string with the character `<code>></code>´. | 3400 | and start the <code>what</code> string with the character `<code>></code>´. |
| 3383 | For instance, to know in which line a function <code>f</code> was defined, | 3401 | For instance, to know in which line a function <code>f</code> was defined, |
| 3384 | you can write the following code: | 3402 | you can write the following code: |
| 3385 | <PRE> | 3403 | <pre> |
| 3386 | lua_Debug ar; | 3404 | lua_Debug ar; |
| 3387 | lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* get global `f' */ | 3405 | lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* get global `f' */ |
| 3388 | lua_getinfo(L, ">S", &ar); | 3406 | lua_getinfo(L, ">S", &ar); |
| 3389 | printf("%d\n", ar.linedefined); | 3407 | printf("%d\n", ar.linedefined); |
| 3390 | </PRE> | 3408 | </pre> |
| 3391 | | 3409 | |
| 3392 | <p><a name="lua_getlocal"></a> | 3410 | <p><a name="lua_getlocal"></a> |
| 3393 | <hr><h3><code>lua_getlocal</code></h3> | 3411 | <hr/><h3><code>lua_getlocal</code></h3> |
| 3394 | <pre> | 3412 | <pre> |
| 3395 | const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); | 3413 | const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); |
| 3396 | </pre> | 3414 | </pre> |
| @@ -3406,12 +3424,16 @@ until the last active local variable). · 9 unmodified lines |
| 3406 | <a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack, | 3424 | <a href="#lua_getlocal"><code>lua_getlocal</code></a> pushes the variable's value onto the stack, |
| 3407 | and returns its name. | 3425 | and returns its name. |
| 3408 | | 3426 | |
| | 3427 | <p>Variable names starting with `<code>(</code>´ (open parentheses) |
| | 3428 | represent internal variables |
| | 3429 | (loop control variables, temporaries, and C function locals). |
| | 3430 | |
| 3409 | <p>Returns <code>NULL</code> (and pushes nothing) | 3431 | <p>Returns <code>NULL</code> (and pushes nothing) |
| 3410 | when the index is greater than | 3432 | when the index is greater than |
| 3411 | the number of active local variables. | 3433 | the number of active local variables. |
| 3412 | | 3434 | |
| 3413 | <p><a name="lua_getstack"></a> | 3435 | <p><a name="lua_getstack"></a> |
| 3414 | <hr><h3><code>lua_getstack</code></h3> | 3436 | <hr/><h3><code>lua_getstack</code></h3> |
| 3415 | <pre> | 3437 | <pre> |
| 3416 | int lua_getstack (lua_State *L, int level, lua_Debug *ar); | 3438 | int lua_getstack (lua_State *L, int level, lua_Debug *ar); |
| 3417 | </pre> | 3439 | </pre> |
| @@ -3429,7 +3451,7 @@ when called with a level greater than the stack depth, · 11 unmodified lines |
| 3429 | it returns 0. | 3451 | it returns 0. |
| 3430 | | 3452 | |
| 3431 | <p><a name="lua_getupvalue"></a> | 3453 | <p><a name="lua_getupvalue"></a> |
| 3432 | <hr><h3><code>lua_getupvalue</code></h3> | 3454 | <hr/><h3><code>lua_getupvalue</code></h3> |
| 3433 | <pre> | 3455 | <pre> |
| 3434 | const char *lua_getupvalue (lua_State *L, int funcindex, int n); | 3456 | const char *lua_getupvalue (lua_State *L, int funcindex, int n); |
| 3435 | </pre> | 3457 | </pre> |
| @@ -3452,7 +3474,7 @@ For C functions, this function uses the empty string <code>""</code> · 16 unmodified lines |
| 3452 | as a name for all upvalues. | 3474 | as a name for all upvalues. |
| 3453 | | 3475 | |
| 3454 | <p><a name="lua_Hook"></a> | 3476 | <p><a name="lua_Hook"></a> |
| 3455 | <hr><h3><code>lua_Hook</code></h3> | 3477 | <hr/><h3><code>lua_Hook</code></h3> |
| 3456 | <pre> | 3478 | <pre> |
| 3457 | typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); | 3479 | typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); |
| 3458 | </pre> | 3480 | </pre> |
| @@ -3480,7 +3502,7 @@ Therefore, if a hook calls back Lua to execute a function or a chunk, · 21 unmodified lines |
| 3480 | that execution occurs without any calls to hooks. | 3502 | that execution occurs without any calls to hooks. |
| 3481 | | 3503 | |
| 3482 | <p><a name="lua_sethook"></a> | 3504 | <p><a name="lua_sethook"></a> |
| 3483 | <hr><h3><code>lua_sethook</code></h3> | 3505 | <hr/><h3><code>lua_sethook</code></h3> |
| 3484 | <pre> | 3506 | <pre> |
| 3485 | int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); | 3507 | int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); |
| 3486 | </pre> | 3508 | </pre> |
| @@ -3515,7 +3537,7 @@ or when it jumps back in the code (even to the same line). · 28 unmodified lines |
| 3515 | <p>A hook is disabled by setting <code>mask</code> to zero. | 3537 | <p>A hook is disabled by setting <code>mask</code> to zero. |
| 3516 | | 3538 | |
| 3517 | <p><a name="lua_setlocal"></a> | 3539 | <p><a name="lua_setlocal"></a> |
| 3518 | <hr><h3><code>lua_setlocal</code></h3> | 3540 | <hr/><h3><code>lua_setlocal</code></h3> |
| 3519 | <pre> | 3541 | <pre> |
| 3520 | const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); | 3542 | const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); |
| 3521 | </pre> | 3543 | </pre> |
| @@ -3533,7 +3555,7 @@ when the index is greater than · 11 unmodified lines |
| 3533 | the number of active local variables. | 3555 | the number of active local variables. |
| 3534 | | 3556 | |
| 3535 | <p><a name="lua_setupvalue"></a> | 3557 | <p><a name="lua_setupvalue"></a> |
| 3536 | <hr><h3><code>lua_setupvalue</code></h3> | 3558 | <hr/><h3><code>lua_setupvalue</code></h3> |
| 3537 | <pre> | 3559 | <pre> |
| 3538 | const char *lua_setupvalue (lua_State *L, int funcindex, int n); | 3560 | const char *lua_setupvalue (lua_State *L, int funcindex, int n); |
| 3539 | </pre> | 3561 | </pre> |
| @@ -3582,7 +3604,7 @@ you should not use those functions for other stack values. · 42 unmodified lines |
| 3582 | in alphabetical order. | 3604 | in alphabetical order. |
| 3583 | | 3605 | |
| 3584 | <p><a name="luaL_addchar"></a> | 3606 | <p><a name="luaL_addchar"></a> |
| 3585 | <hr><h3><code>luaL_addchar</code></h3> | 3607 | <hr/><h3><code>luaL_addchar</code></h3> |
| 3586 | <pre> | 3608 | <pre> |
| 3587 | void luaL_addchar (luaL_Buffer B, char c); | 3609 | void luaL_addchar (luaL_Buffer B, char c); |
| 3588 | </pre> | 3610 | </pre> |
| @@ -3592,7 +3614,7 @@ in alphabetical order. · 3 unmodified lines |
| 3592 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). | 3614 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
| 3593 | | 3615 | |
| 3594 | <p><a name="luaL_addlstring"></a> | 3616 | <p><a name="luaL_addlstring"></a> |
| 3595 | <hr><h3><code>luaL_addlstring</code></h3> | 3617 | <hr/><h3><code>luaL_addlstring</code></h3> |
| 3596 | <pre> | 3618 | <pre> |
| 3597 | void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l); | 3619 | void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l); |
| 3598 | </pre> | 3620 | </pre> |
| @@ -3603,7 +3625,7 @@ the buffer <code>B</code> · 4 unmodified lines |
| 3603 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). | 3625 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
| 3604 | | 3626 | |
| 3605 | <p><a name="luaL_addsize"></a> | 3627 | <p><a name="luaL_addsize"></a> |
| 3606 | <hr><h3><code>luaL_addsize</code></h3> | 3628 | <hr/><h3><code>luaL_addsize</code></h3> |
| 3607 | <pre> | 3629 | <pre> |
| 3608 | void luaL_addsize (luaL_Buffer B, size_t n); | 3630 | void luaL_addsize (luaL_Buffer B, size_t n); |
| 3609 | </pre> | 3631 | </pre> |
| @@ -3614,7 +3636,7 @@ buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to · 4 unmodified lines |
| 3614 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). | 3636 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
| 3615 | | 3637 | |
| 3616 | <p><a name="luaL_addstring"></a> | 3638 | <p><a name="luaL_addstring"></a> |
| 3617 | <hr><h3><code>luaL_addstring</code></h3> | 3639 | <hr/><h3><code>luaL_addstring</code></h3> |
| 3618 | <pre> | 3640 | <pre> |
| 3619 | void luaL_addstring (luaL_Buffer *B, const char *s); | 3641 | void luaL_addstring (luaL_Buffer *B, const char *s); |
| 3620 | </pre> | 3642 | </pre> |
| @@ -3625,7 +3647,7 @@ to the buffer <code>B</code> · 4 unmodified lines |
| 3625 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). | 3647 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
| 3626 | | 3648 | |
| 3627 | <p><a name="luaL_addvalue"></a> | 3649 | <p><a name="luaL_addvalue"></a> |
| 3628 | <hr><h3><code>luaL_addvalue</code></h3> | 3650 | <hr/><h3><code>luaL_addvalue</code></h3> |
| 3629 | <pre> | 3651 | <pre> |
| 3630 | void luaL_addvalue (luaL_Buffer *B); | 3652 | void luaL_addvalue (luaL_Buffer *B); |
| 3631 | </pre> | 3653 | </pre> |
| @@ -3641,7 +3663,7 @@ be called with an extra element on the stack, · 9 unmodified lines |
| 3641 | which is the value to be added to the buffer. | 3663 | which is the value to be added to the buffer. |
| 3642 | | 3664 | |
| 3643 | <p><a name="luaL_argcheck"></a> | 3665 | <p><a name="luaL_argcheck"></a> |
| 3644 | <hr><h3><code>luaL_argcheck</code></h3> | 3666 | <hr/><h3><code>luaL_argcheck</code></h3> |
| 3645 | <pre> | 3667 | <pre> |
| 3646 | void luaL_argcheck (lua_State *L, int cond, int numarg, | 3668 | void luaL_argcheck (lua_State *L, int cond, int numarg, |
| 3647 | const char *extramsg); | 3669 | const char *extramsg); |
| @@ -3654,7 +3676,7 @@ If not, raise an error with message · 6 unmodified lines |
| 3654 | where <code>func</code> is retrieved from the call stack. | 3676 | where <code>func</code> is retrieved from the call stack. |
| 3655 | | 3677 | |
| 3656 | <p><a name="luaL_argerror"></a> | 3678 | <p><a name="luaL_argerror"></a> |
| 3657 | <hr><h3><code>luaL_argerror</code></h3> | 3679 | <hr/><h3><code>luaL_argerror</code></h3> |
| 3658 | <pre> | 3680 | <pre> |
| 3659 | int luaL_argerror (lua_State *L, int numarg, const char *extramsg); | 3681 | int luaL_argerror (lua_State *L, int numarg, const char *extramsg); |
| 3660 | </pre> | 3682 | </pre> |
| @@ -3667,7 +3689,7 @@ where <code>func</code> is retrieved from the call stack. · 6 unmodified lines |
| 3667 | <p>This function never returns. | 3689 | <p>This function never returns. |
| 3668 | | 3690 | |
| 3669 | <p><a name="luaL_Buffer"></a> | 3691 | <p><a name="luaL_Buffer"></a> |
| 3670 | <hr><h3><code>luaL_Buffer</code></h3> | 3692 | <hr/><h3><code>luaL_Buffer</code></h3> |
| 3671 | <pre> | 3693 | <pre> |
| 3672 | typedef struct luaL_Buffer luaL_Buffer; | 3694 | typedef struct luaL_Buffer luaL_Buffer; |
| 3673 | </pre> | 3695 | </pre> |
| @@ -3700,7 +3722,7 @@ level when the buffer was initialized, · 26 unmodified lines |
| 3700 | plus the final string on its top. | 3722 | plus the final string on its top. |
| 3701 | | 3723 | |
| 3702 | <p><a name="luaL_buffinit"></a> | 3724 | <p><a name="luaL_buffinit"></a> |
| 3703 | <hr><h3><code>luaL_buffinit</code></h3> | 3725 | <hr/><h3><code>luaL_buffinit</code></h3> |
| 3704 | <pre> | 3726 | <pre> |
| 3705 | void luaL_buffinit (lua_State *L, luaL_Buffer *B); | 3727 | void luaL_buffinit (lua_State *L, luaL_Buffer *B); |
| 3706 | </pre> | 3728 | </pre> |
| @@ -3712,7 +3734,7 @@ the buffer must be declared as a variable · 5 unmodified lines |
| 3712 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). | 3734 | (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
| 3713 | | 3735 | |
| 3714 | <p><a name="luaL_callmeta"></a> | 3736 | <p><a name="luaL_callmeta"></a> |
| 3715 | <hr><h3><code>luaL_callmeta</code></h3> | 3737 | <hr/><h3><code>luaL_callmeta</code></h3> |
| 3716 | <pre> | 3738 | <pre> |
| 3717 | int luaL_callmeta (lua_State *L, int obj, const char *e); | 3739 | int luaL_callmeta (lua_State *L, int obj, const char *e); |
| 3718 | </pre> | 3740 | </pre> |
| @@ -3729,7 +3751,7 @@ If there is no metatable or no metamethod returns 0 · 10 unmodified lines |
| 3729 | (without pushing any value on the stack). | 3751 | (without pushing any value on the stack). |
| 3730 | | 3752 | |
| 3731 | <p><a name="luaL_checkany"></a> | 3753 | <p><a name="luaL_checkany"></a> |
| 3732 | <hr><h3><code>luaL_checkany</code></h3> | 3754 | <hr/><h3><code>luaL_checkany</code></h3> |
| 3733 | <pre> | 3755 | <pre> |
| 3734 | void luaL_checkany (lua_State *L, int narg); | 3756 | void luaL_checkany (lua_State *L, int narg); |
| 3735 | </pre> | 3757 | </pre> |
| @@ -3738,7 +3760,7 @@ If there is no metatable or no metamethod returns 0 · 2 unmodified lines |
| 3738 | <p>Checks whether the function has an argument <code>narg</code>. | 3760 | <p>Checks whether the function has an argument <code>narg</code>. |
| 3739 | | 3761 | |
| 3740 | <p><a name="luaL_checkint"></a> | 3762 | <p><a name="luaL_checkint"></a> |
| 3741 | <hr><h3><code>luaL_checkint</code></h3> | 3763 | <hr/><h3><code>luaL_checkint</code></h3> |
| 3742 | <pre> | 3764 | <pre> |
| 3743 | int luaL_checkint (lua_State *L, int narg); | 3765 | int luaL_checkint (lua_State *L, int narg); |
| 3744 | </pre> | 3766 | </pre> |
| @@ -3748,7 +3770,7 @@ If there is no metatable or no metamethod returns 0 · 3 unmodified lines |
| 3748 | and returns that number casted to an <code>int</code>. | 3770 | and returns that number casted to an <code>int</code>. |
| 3749 | | 3771 | |
| 3750 | <p><a name="luaL_checkinteger"></a> | 3772 | <p><a name="luaL_checkinteger"></a> |
| 3751 | <hr><h3><code>luaL_checkinteger</code></h3> | 3773 | <hr/><h3><code>luaL_checkinteger</code></h3> |
| 3752 | <pre> | 3774 | <pre> |
| 3753 | lua_Integer luaL_checkinteger (lua_State *L, int numArg); | 3775 | lua_Integer luaL_checkinteger (lua_State *L, int numArg); |
| 3754 | </pre> | 3776 | </pre> |
| @@ -3758,7 +3780,7 @@ and returns that number casted to an <code>int</code>. · 3 unmodified lines |
| 3758 | and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>. | 3780 | and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>. |
| 3759 | | 3781 | |
| 3760 | <p><a name="luaL_checklong"></a> | 3782 | <p><a name="luaL_checklong"></a> |
| 3761 | <hr><h3><code>luaL_checklong</code></h3> | 3783 | <hr/><h3><code>luaL_checklong</code></h3> |
| 3762 | <pre> | 3784 | <pre> |
| 3763 | long luaL_checklong (lua_State *L, int narg); | 3785 | long luaL_checklong (lua_State *L, int narg); |
| 3764 | </pre> | 3786 | </pre> |
| @@ -3768,7 +3790,7 @@ and returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</co · 3 unmodified lines |
| 3768 | and returns that number casted to a <code>long</code>. | 3790 | and returns that number casted to a <code>long</code>. |
| 3769 | | 3791 | |
| 3770 | <p><a name="luaL_checklstring"></a> | 3792 | <p><a name="luaL_checklstring"></a> |
| 3771 | <hr><h3><code>luaL_checklstring</code></h3> | 3793 | <hr/><h3><code>luaL_checklstring</code></h3> |
| 3772 | <pre> | 3794 | <pre> |
| 3773 | const char *luaL_checklstring (lua_State *L, int numArg, size_t *l); | 3795 | const char *luaL_checklstring (lua_State *L, int numArg, size_t *l); |
| 3774 | </pre> | 3796 | </pre> |
| @@ -3780,7 +3802,7 @@ if <code>l</code> is not <code>NULL</code> fills the position <code>*l</code> · 5 unmodified lines |
| 3780 | with the string's length. | 3802 | with the string's length. |
| 3781 | | 3803 | |
| 3782 | <p><a name="luaL_checknumber"></a> | 3804 | <p><a name="luaL_checknumber"></a> |
| 3783 | <hr><h3><code>luaL_checknumber</code></h3> | 3805 | <hr/><h3><code>luaL_checknumber</code></h3> |
| 3784 | <pre> | 3806 | <pre> |
| 3785 | lua_Number luaL_checknumber (lua_State *L, int numArg); | 3807 | lua_Number luaL_checknumber (lua_State *L, int numArg); |
| 3786 | </pre> | 3808 | </pre> |
| @@ -3790,7 +3812,7 @@ with the string's length. · 3 unmodified lines |
| 3790 | and returns that number. | 3812 | and returns that number. |
| 3791 | | 3813 | |
| 3792 | <p><a name="luaL_checkoption"></a> | 3814 | <p><a name="luaL_checkoption"></a> |
| 3793 | <hr><h3><code>luaL_checkoption</code></h3> | 3815 | <hr/><h3><code>luaL_checkoption</code></h3> |
| 3794 | <pre> | 3816 | <pre> |
| 3795 | int luaL_checkoption (lua_State *L, int narg, const char *def, | 3817 | int luaL_checkoption (lua_State *L, int narg, const char *def, |
| 3796 | const char *const lst[]); | 3818 | const char *const lst[]); |
| @@ -3802,14 +3824,14 @@ searches for that string into the array <code>lst</code> · 5 unmodified lines |
| 3802 | (which must be NULL-terminated). | 3824 | (which must be NULL-terminated). |
| 3803 | If <code>def</code> is not <code>NULL</code>, | 3825 | If <code>def</code> is not <code>NULL</code>, |
| 3804 | uses <code>def</code> as a default value when | 3826 | uses <code>def</code> as a default value when |
| 3805 | the function has no argument <code>narg</code> or if that argument is <B>nil</B>. | 3827 | the function has no argument <code>narg</code> or if that argument is <b>nil</b>. |
| 3806 | | 3828 | |
| 3807 | <p>Returns the index in the array where the string was found. | 3829 | <p>Returns the index in the array where the string was found. |
| 3808 | Raises an error if the argument is not a string or | 3830 | Raises an error if the argument is not a string or |
| 3809 | if the string cannot be found. | 3831 | if the string cannot be found. |
| 3810 | | 3832 | |
| 3811 | <p><a name="luaL_checkstack"></a> | 3833 | <p><a name="luaL_checkstack"></a> |
| 3812 | <hr><h3><code>luaL_checkstack</code></h3> | 3834 | <hr/><h3><code>luaL_checkstack</code></h3> |
| 3813 | <pre> | 3835 | <pre> |
| 3814 | void luaL_checkstack (lua_State *L, int sz, const char *msg); | 3836 | void luaL_checkstack (lua_State *L, int sz, const char *msg); |
| 3815 | </pre> | 3837 | </pre> |
| @@ -3820,7 +3842,7 @@ raising an error if the stack cannot grow to that size. · 4 unmodified lines |
| 3820 | <code>msg</code> is an additional text to go into the error message. | 3842 | <code>msg</code> is an additional text to go into the error message. |
| 3821 | | 3843 | |
| 3822 | <p><a name="luaL_checkstring"></a> | 3844 | <p><a name="luaL_checkstring"></a> |
| 3823 | <hr><h3><code>luaL_checkstring</code></h3> | 3845 | <hr/><h3><code>luaL_checkstring</code></h3> |
| 3824 | <pre> | 3846 | <pre> |
| 3825 | const char *luaL_checkstring (lua_State *L, int narg); | 3847 | const char *luaL_checkstring (lua_State *L, int narg); |
| 3826 | </pre> | 3848 | </pre> |
| @@ -3830,7 +3852,7 @@ raising an error if the stack cannot grow to that size. · 3 unmodified lines |
| 3830 | and returns that string. | 3852 | and returns that string. |
| 3831 | | 3853 | |
| 3832 | <p><a name="luaL_checktype"></a> | 3854 | <p><a name="luaL_checktype"></a> |
| 3833 | <hr><h3><code>luaL_checktype</code></h3> | 3855 | <hr/><h3><code>luaL_checktype</code></h3> |
| 3834 | <pre> | 3856 | <pre> |
| 3835 | void luaL_checktype (lua_State *L, int narg, int t); | 3857 | void luaL_checktype (lua_State *L, int narg, int t); |
| 3836 | </pre> | 3858 | </pre> |
| @@ -3839,7 +3861,7 @@ and returns that string. · 2 unmodified lines |
| 3839 | <p>Checks whether the function argument <code>narg</code> has type <code>t</code>. | 3861 | <p>Checks whether the function argument <code>narg</code> has type <code>t</code>. |
| 3840 | | 3862 | |
| 3841 | <p><a name="luaL_checkudata"></a> | 3863 | <p><a name="luaL_checkudata"></a> |
| 3842 | <hr><h3><code>luaL_checkudata</code></h3> | 3864 | <hr/><h3><code>luaL_checkudata</code></h3> |
| 3843 | <pre> | 3865 | <pre> |
| 3844 | void *luaL_checkudata (lua_State *L, int ud, const char *tname); | 3866 | void *luaL_checkudata (lua_State *L, int ud, const char *tname); |
| 3845 | </pre> | 3867 | </pre> |
| @@ -3849,7 +3871,7 @@ and returns that string. · 3 unmodified lines |
| 3849 | of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>). | 3871 | of the type <code>tname</code> (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>). |
| 3850 | | 3872 | |
| 3851 | <p><a name="luaL_error"></a> | 3873 | <p><a name="luaL_error"></a> |
| 3852 | <hr><h3><code>luaL_error</code></h3> | 3874 | <hr/><h3><code>luaL_error</code></h3> |
| 3853 | <pre> | 3875 | <pre> |
| 3854 | int luaL_error (lua_State *L, const char *fmt, ...); | 3876 | int luaL_error (lua_State *L, const char *fmt, ...); |
| 3855 | </pre> | 3877 | </pre> |
| @@ -3866,7 +3888,7 @@ if that information is available. · 10 unmodified lines |
| 3866 | <p>This function never returns. | 3888 | <p>This function never returns. |
| 3867 | | 3889 | |
| 3868 | <p><a name="luaL_getmetafield"></a> | 3890 | <p><a name="luaL_getmetafield"></a> |
| 3869 | <hr><h3><code>luaL_getmetafield</code></h3> | 3891 | <hr/><h3><code>luaL_getmetafield</code></h3> |
| 3870 | <pre> | 3892 | <pre> |
| 3871 | int luaL_getmetafield (lua_State *L, int obj, const char *e); | 3893 | int luaL_getmetafield (lua_State *L, int obj, const char *e); |
| 3872 | </pre> | 3894 | </pre> |
| @@ -3879,7 +3901,7 @@ or if the metatable does not have that field, · 6 unmodified lines |
| 3879 | returns 0 (false) and pushes nothing. | 3901 | returns 0 (false) and pushes nothing. |
| 3880 | | 3902 | |
| 3881 | <p><a name="luaL_getmetatable"></a> | 3903 | <p><a name="luaL_getmetatable"></a> |
| 3882 | <hr><h3><code>luaL_getmetatable</code></h3> | 3904 | <hr/><h3><code>luaL_getmetatable</code></h3> |
| 3883 | <pre> | 3905 | <pre> |
| 3884 | void luaL_getmetatable (lua_State *L, const char *tname); | 3906 | void luaL_getmetatable (lua_State *L, const char *tname); |
| 3885 | </pre> | 3907 | </pre> |
| @@ -3889,7 +3911,7 @@ returns 0 (false) and pushes nothing. · 3 unmodified lines |
| 3889 | in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>). | 3911 | in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>). |
| 3890 | | 3912 | |
| 3891 | <p><a name="luaL_gsub"></a> | 3913 | <p><a name="luaL_gsub"></a> |
| 3892 | <hr><h3><code>luaL_gsub</code></h3> | 3914 | <hr/><h3><code>luaL_gsub</code></h3> |
| 3893 | <pre> | 3915 | <pre> |
| 3894 | const char *luaL_gsub (lua_State *L, const char *s, | 3916 | const char *luaL_gsub (lua_State *L, const char *s, |
| 3895 | const char *p, const char *r); | 3917 | const char *p, const char *r); |
| @@ -3901,7 +3923,7 @@ by the string <code>r</code>. · 5 unmodified lines |
| 3901 | Pushes the resulting string on the stack and returns it. | 3923 | Pushes the resulting string on the stack and returns it. |
| 3902 | | 3924 | |
| 3903 | <p><a name="luaL_loadbuffer"></a> | 3925 | <p><a name="luaL_loadbuffer"></a> |
| 3904 | <hr><h3><code>luaL_loadbuffer</code></h3> | 3926 | <hr/><h3><code>luaL_loadbuffer</code></h3> |
| 3905 | <pre> | 3927 | <pre> |
| 3906 | int luaL_loadbuffer (lua_State *L, const char *buff, | 3928 | int luaL_loadbuffer (lua_State *L, const char *buff, |
| 3907 | size_t sz, const char *name); | 3929 | size_t sz, const char *name); |
| @@ -3917,7 +3939,7 @@ buffer pointed by <code>buff</code> with size <code>sz</code>. · 9 unmodified lines |
| 3917 | used for debug information and error messages. | 3939 | used for debug information and error messages. |
| 3918 | | 3940 | |
| 3919 | <p><a name="luaL_loadfile"></a> | 3941 | <p><a name="luaL_loadfile"></a> |
| 3920 | <hr><h3><code>luaL_loadfile</code></h3> | 3942 | <hr/><h3><code>luaL_loadfile</code></h3> |
| 3921 | <pre> | 3943 | <pre> |
| 3922 | int luaL_loadfile (lua_State *L, const char *filename); | 3944 | int luaL_loadfile (lua_State *L, const char *filename); |
| 3923 | </pre> | 3945 | </pre> |
| @@ -3933,7 +3955,7 @@ but it has an extra error code <code>LUA_ERRFILE</code> · 9 unmodified lines |
| 3933 | if it cannot open the file. | 3955 | if it cannot open the file. |
| 3934 | | 3956 | |
| 3935 | <p><a name="luaL_loadstring"></a> | 3957 | <p><a name="luaL_loadstring"></a> |
| 3936 | <hr><h3><code>luaL_loadstring</code></h3> | 3958 | <hr/><h3><code>luaL_loadstring</code></h3> |
| 3937 | <pre> | 3959 | <pre> |
| 3938 | int luaL_loadstring (lua_State *L, const char *s); | 3960 | int luaL_loadstring (lua_State *L, const char *s); |
| 3939 | </pre> | 3961 | </pre> |
| @@ -3946,7 +3968,7 @@ the zero-terminated string <code>s</code>. · 6 unmodified lines |
| 3946 | <p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>. | 3968 | <p>This function returns the same results as <a href="#lua_load"><code>lua_load</code></a>. |
| 3947 | | 3969 | |
| 3948 | <p><a name="luaL_newmetatable"></a> | 3970 | <p><a name="luaL_newmetatable"></a> |
| 3949 | <hr><h3><code>luaL_newmetatable</code></h3> | 3971 | <hr/><h3><code>luaL_newmetatable</code></h3> |
| 3950 | <pre> | 3972 | <pre> |
| 3951 | int luaL_newmetatable (lua_State *L, const char *tname); | 3973 | int luaL_newmetatable (lua_State *L, const char *tname); |
| 3952 | </pre> | 3974 | </pre> |
| @@ -3963,7 +3985,7 @@ and returns 1. · 10 unmodified lines |
| 3963 | with <code>"tname"</code> in the registry. | 3985 | with <code>"tname"</code> in the registry. |
| 3964 | | 3986 | |
| 3965 | <p><a name="luaL_newstate"></a> | 3987 | <p><a name="luaL_newstate"></a> |
| 3966 | <hr><h3><code>luaL_newstate</code></h3> | 3988 | <hr/><h3><code>luaL_newstate</code></h3> |
| 3967 | <pre> | 3989 | <pre> |
| 3968 | lua_State *luaL_newstate (void); | 3990 | lua_State *luaL_newstate (void); |
| 3969 | </pre> | 3991 | </pre> |
| @@ -3979,7 +4001,7 @@ errors. · 9 unmodified lines |
| 3979 | or <code>NULL</code> if there is a memory allocation error. | 4001 | or <code>NULL</code> if there is a memory allocation error. |
| 3980 | | 4002 | |
| 3981 | <p><a name="luaL_optint"></a> | 4003 | <p><a name="luaL_optint"></a> |
| 3982 | <hr><h3><code>luaL_optint</code></h3> | 4004 | <hr/><h3><code>luaL_optint</code></h3> |
| 3983 | <pre> | 4005 | <pre> |
| 3984 | int luaL_optint (lua_State *L, int narg, int d); | 4006 | int luaL_optint (lua_State *L, int narg, int d); |
| 3985 | </pre> | 4007 | </pre> |
| @@ -3987,12 +4009,12 @@ or <code>NULL</code> if there is a memory allocation error. · 1 unmodified line |
| 3987 | | 4009 | |
| 3988 | <p>If the function argument <code>narg</code> is a number, | 4010 | <p>If the function argument <code>narg</code> is a number, |
| 3989 | returns that number casted to an <code>int</code>. | 4011 | returns that number casted to an <code>int</code>. |
| 3990 | If that argument is absent or is <B>nil</B>, | 4012 | If that argument is absent or is <b>nil</b>, |
| 3991 | returns <code>d</code>. | 4013 | returns <code>d</code>. |
| 3992 | Otherwise, raise an error. | 4014 | Otherwise, raise an error. |
| 3993 | | 4015 | |
| 3994 | <p><a name="luaL_optinteger"></a> | 4016 | <p><a name="luaL_optinteger"></a> |
| 3995 | <hr><h3><code>luaL_optinteger</code></h3> | 4017 | <hr/><h3><code>luaL_optinteger</code></h3> |
| 3996 | <pre> | 4018 | <pre> |
| 3997 | lua_Integer luaL_optinteger (lua_State *L, int nArg, lua_Integer d); | 4019 | lua_Integer luaL_optinteger (lua_State *L, int nArg, lua_Integer d); |
| 3998 | </pre> | 4020 | </pre> |
| @@ -4000,12 +4022,12 @@ Otherwise, raise an error. · 1 unmodified line |
| 4000 | | 4022 | |
| 4001 | <p>If the function argument <code>narg</code> is a number, | 4023 | <p>If the function argument <code>narg</code> is a number, |
| 4002 | returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>. | 4024 | returns that number casted to a <a href="#lua_Integer"><code>lua_Integer</code></a>. |
| 4003 | If that argument is absent or is <B>nil</B>, | 4025 | If that argument is absent or is <b>nil</b>, |
| 4004 | returns <code>d</code>. | 4026 | returns <code>d</code>. |
| 4005 | Otherwise, raise an error. | 4027 | Otherwise, raise an error. |
| 4006 | | 4028 | |
| 4007 | <p><a name="luaL_optlong"></a> | 4029 | <p><a name="luaL_optlong"></a> |
| 4008 | <hr><h3><code>luaL_optlong</code></h3> | 4030 | <hr/><h3><code>luaL_optlong</code></h3> |
| 4009 | <pre> | 4031 | <pre> |
| 4010 | long luaL_optlong (lua_State *L, int narg, long d); | 4032 | long luaL_optlong (lua_State *L, int narg, long d); |
| 4011 | </pre> | 4033 | </pre> |
| @@ -4013,12 +4035,12 @@ Otherwise, raise an error. · 1 unmodified line |
| 4013 | | 4035 | |
| 4014 | <p>If the function argument <code>narg</code> is a number, | 4036 | <p>If the function argument <code>narg</code> is a number, |
| 4015 | returns that number casted to a <code>long</code>. | 4037 | returns that number casted to a <code>long</code>. |
| 4016 | If that argument is absent or is <B>nil</B>, | 4038 | If that argument is absent or is <b>nil</b>, |
| 4017 | returns <code>d</code>. | 4039 | returns <code>d</code>. |
| 4018 | Otherwise, raise an error. | 4040 | Otherwise, raise an error. |
| 4019 | | 4041 | |
| 4020 | <p><a name="luaL_optlstring"></a> | 4042 | <p><a name="luaL_optlstring"></a> |
| 4021 | <hr><h3><code>luaL_optlstring</code></h3> | 4043 | <hr/><h3><code>luaL_optlstring</code></h3> |
| 4022 | <pre> | 4044 | <pre> |
| 4023 | const char *luaL_optlstring (lua_State *L, int numArg, | 4045 | const char *luaL_optlstring (lua_State *L, int numArg, |
| 4024 | const char *d, size_t *l); | 4046 | const char *d, size_t *l); |
| @@ -4027,7 +4049,7 @@ Otherwise, raise an error. · 2 unmodified lines |
| 4027 | | 4049 | |
| 4028 | <p>If the function argument <code>narg</code> is a string, | 4050 | <p>If the function argument <code>narg</code> is a string, |
| 4029 | returns that string. | 4051 | returns that string. |
| 4030 | If that argument is absent or is <B>nil</B>, | 4052 | If that argument is absent or is <b>nil</b>, |
| 4031 | returns <code>d</code>. | 4053 | returns <code>d</code>. |
| 4032 | Otherwise, raise an error. | 4054 | Otherwise, raise an error. |
| 4033 | | 4055 | |
| @@ -4035,7 +4057,7 @@ Otherwise, raise an error. · 1 unmodified line |
| 4035 | with the results's length. | 4057 | with the results's length. |
| 4036 | | 4058 | |
| 4037 | <p><a name="luaL_optnumber"></a> | 4059 | <p><a name="luaL_optnumber"></a> |
| 4038 | <hr><h3><code>luaL_optnumber</code></h3> | 4060 | <hr/><h3><code>luaL_optnumber</code></h3> |
| 4039 | <pre> | 4061 | <pre> |
| 4040 | lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number d); | 4062 | lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number d); |
| 4041 | </pre> | 4063 | </pre> |
| @@ -4043,12 +4065,12 @@ with the results's length. · 1 unmodified line |
| 4043 | | 4065 | |
| 4044 | <p>If the function argument <code>narg</code> is a number, | 4066 | <p>If the function argument <code>narg</code> is a number, |
| 4045 | returns that number. | 4067 | returns that number. |
| 4046 | If that argument is absent or is <B>nil</B>, | 4068 | If that argument is absent or is <b>nil</b>, |
| 4047 | returns <code>d</code>. | 4069 | returns <code>d</code>. |
| 4048 | Otherwise, raise an error. | 4070 | Otherwise, raise an error. |
| 4049 | | 4071 | |
| 4050 | <p><a name="luaL_optstring"></a> | 4072 | <p><a name="luaL_optstring"></a> |
| 4051 | <hr><h3><code>luaL_optstring</code></h3> | 4073 | <hr/><h3><code>luaL_optstring</code></h3> |
| 4052 | <pre> | 4074 | <pre> |
| 4053 | const char *luaL_optstring (lua_State *L, int narg, const char *d); | 4075 | const char *luaL_optstring (lua_State *L, int narg, const char *d); |
| 4054 | </pre> | 4076 | </pre> |
| @@ -4056,12 +4078,12 @@ Otherwise, raise an error. · 1 unmodified line |
| 4056 | | 4078 | |
| 4057 | <p>If the function argument <code>narg</code> is a string, | 4079 | <p>If the function argument <code>narg</code> is a string, |
| 4058 | returns that string. | 4080 | returns that string. |
| 4059 | If that argument is absent or is <B>nil</B>, | 4081 | If that argument is absent or is <b>nil</b>, |
| 4060 | returns <code>d</code>. | 4082 | returns <code>d</code>. |
| 4061 | Otherwise, raise an error. | 4083 | Otherwise, raise an error. |
| 4062 | | 4084 | |
| 4063 | <p><a name="luaL_prepbuffer"></a> | 4085 | <p><a name="luaL_prepbuffer"></a> |
| 4064 | <hr><h3><code>luaL_prepbuffer</code></h3> | 4086 | <hr/><h3><code>luaL_prepbuffer</code></h3> |
| 4065 | <pre> | 4087 | <pre> |
| 4066 | char *luaL_prepbuffer (luaL_Buffer *B); | 4088 | char *luaL_prepbuffer (luaL_Buffer *B); |
| 4067 | </pre> | 4089 | </pre> |
| @@ -4075,7 +4097,7 @@ After copying the string into that space you must call · 7 unmodified lines |
| 4075 | it to the buffer. | 4097 | it to the buffer. |
| 4076 | | 4098 | |
| 4077 | <p><a name="luaL_pushresult"></a> | 4099 | <p><a name="luaL_pushresult"></a> |
| 4078 | <hr><h3><code>luaL_pushresult</code></h3> | 4100 | <hr/><h3><code>luaL_pushresult</code></h3> |
| 4079 | <pre> | 4101 | <pre> |
| 4080 | void luaL_pushresult (luaL_Buffer *B); | 4102 | void luaL_pushresult (luaL_Buffer *B); |
| 4081 | </pre> | 4103 | </pre> |
| @@ -4085,7 +4107,7 @@ it to the buffer. · 3 unmodified lines |
| 4085 | the top of the stack. | 4107 | the top of the stack. |
| 4086 | | 4108 | |
| 4087 | <p><a name="luaL_ref"></a> | 4109 | <p><a name="luaL_ref"></a> |
| 4088 | <hr><h3><code>luaL_ref</code></h3> | 4110 | <hr/><h3><code>luaL_ref</code></h3> |
| 4089 | <pre> | 4111 | <pre> |
| 4090 | int luaL_ref (lua_State *L, int t); | 4112 | int luaL_ref (lua_State *L, int t); |
| 4091 | </pre> | 4113 | </pre> |
| @@ -4102,13 +4124,13 @@ You can retrieve an object referred by reference <code>r</code> · 10 unmodified lines |
| 4102 | calling <code>lua_rawgeti(L, t, r)</code>. | 4124 | calling <code>lua_rawgeti(L, t, r)</code>. |
| 4103 | Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object. | 4125 | Function <a href="#luaL_unref"><code>luaL_unref</code></a> frees a reference and its associated object. |
| 4104 | | 4126 | |
| 4105 | <p>Whenever the object at the top of the stack is <B>nil</B>, | 4127 | <p>Whenever the object at the top of the stack is <b>nil</b>, |
| 4106 | <a href="#luaL_ref"><code>luaL_ref</code></a> returns the same reference <code>LUA_REFNIL</code>. | 4128 | <a href="#luaL_ref"><code>luaL_ref</code></a> returns the same reference <code>LUA_REFNIL</code>. |
| 4107 | The constant <code>LUA_NOREF</code> is garanteed to be different | 4129 | The constant <code>LUA_NOREF</code> is garanteed to be different |
| 4108 | from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>. | 4130 | from any reference returned by <a href="#luaL_ref"><code>luaL_ref</code></a>. |
| 4109 | | 4131 | |
| 4110 | <p><a name="luaL_Reg"></a> | 4132 | <p><a name="luaL_Reg"></a> |
| 4111 | <hr><h3><code>luaL_Reg</code></h3> | 4133 | <hr/><h3><code>luaL_Reg</code></h3> |
| 4112 | <pre> | 4134 | <pre> |
| 4113 | typedef struct luaL_Reg { | 4135 | typedef struct luaL_Reg { |
| 4114 | const char *name; | 4136 | const char *name; |
| @@ -4126,7 +4148,7 @@ Any array of <a href="#luaL_Reg"><code>luaL_Reg</code></a> must end with an sent · 11 unmodified lines |
| 4126 | wherein both <code>name</code> and <code>func</code> are <code>NULL</code>. | 4148 | wherein both <code>name</code> and <code>func</code> are <code>NULL</code>. |
| 4127 | | 4149 | |
| 4128 | <p><a name="luaL_register"></a> | 4150 | <p><a name="luaL_register"></a> |
| 4129 | <hr><h3><code>luaL_register</code></h3> | 4151 | <hr/><h3><code>luaL_register</code></h3> |
| 4130 | <pre> | 4152 | <pre> |
| 4131 | void luaL_register (lua_State *L, const char *libname, | 4153 | void luaL_register (lua_State *L, const char *libname, |
| 4132 | const luaL_Reg *l); | 4154 | const luaL_Reg *l); |
| @@ -4152,7 +4174,7 @@ reuses that table instead of creating a new one. · 19 unmodified lines |
| 4152 | on the top of the stack. | 4174 | on the top of the stack. |
| 4153 | | 4175 | |
| 4154 | <p><a name="luaL_typename"></a> | 4176 | <p><a name="luaL_typename"></a> |
| 4155 | <hr><h3><code>luaL_typename</code></h3> | 4177 | <hr/><h3><code>luaL_typename</code></h3> |
| 4156 | <pre> | 4178 | <pre> |
| 4157 | const char *luaL_typename (lua_State *L, int idx); | 4179 | const char *luaL_typename (lua_State *L, int idx); |
| 4158 | </pre> | 4180 | </pre> |
| @@ -4161,22 +4183,22 @@ on the top of the stack. · 2 unmodified lines |
| 4161 | <p>Returns the name of the type of the value at index <code>idx</code>. | 4183 | <p>Returns the name of the type of the value at index <code>idx</code>. |
| 4162 | | 4184 | |
| 4163 | <p><a name="luaL_typerror"></a> | 4185 | <p><a name="luaL_typerror"></a> |
| 4164 | <hr><h3><code>luaL_typerror</code></h3> | 4186 | <hr/><h3><code>luaL_typerror</code></h3> |
| 4165 | <pre> | 4187 | <pre> |
| 4166 | int luaL_typerror (lua_State *L, int narg, const char *tname); | 4188 | int luaL_typerror (lua_State *L, int narg, const char *tname); |
| 4167 | </pre> | 4189 | </pre> |
| 4168 | | 4190 | |
| 4169 | | 4191 | |
| 4170 | <p>Generates an error with a message like | 4192 | <p>Generates an error with a message like |
| 4171 | <PRE> | 4193 | <pre> |
| 4172 | <location>: bad argument <narg> to <function> (<tname> expected, got <realt>) | 4194 | <location>: bad argument <narg> to <function> (<tname> expected, got <realt>) |
| 4173 | </PRE> | 4195 | </pre> |
| 4174 | where <code><location></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>, | 4196 | where <code><location></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>, |
| 4175 | <code><function></code> is the name of the current function, | 4197 | <code><function></code> is the name of the current function, |
| 4176 | and <code><realt></code> is the type name of the actual argument. | 4198 | and <code><realt></code> is the type name of the actual argument. |
| 4177 | | 4199 | |
| 4178 | <p><a name="luaL_unref"></a> | 4200 | <p><a name="luaL_unref"></a> |
| 4179 | <hr><h3><code>luaL_unref</code></h3> | 4201 | <hr/><h3><code>luaL_unref</code></h3> |
| 4180 | <pre> | 4202 | <pre> |
| 4181 | void luaL_unref (lua_State *L, int t, int ref); | 4203 | void luaL_unref (lua_State *L, int t, int ref); |
| 4182 | </pre> | 4204 | </pre> |
| @@ -4192,7 +4214,7 @@ The reference <code>ref</code> is also freed to be used again. · 9 unmodified lines |
| 4192 | <a href="#luaL_unref"><code>luaL_unref</code></a> does nothing. | 4214 | <a href="#luaL_unref"><code>luaL_unref</code></a> does nothing. |
| 4193 | | 4215 | |
| 4194 | <p><a name="luaL_where"></a> | 4216 | <p><a name="luaL_where"></a> |
| 4195 | <hr><h3><code>luaL_where</code></h3> | 4217 | <hr/><h3><code>luaL_where</code></h3> |
| 4196 | <pre> | 4218 | <pre> |
| 4197 | void luaL_where (lua_State *L, int lvl); | 4219 | void luaL_where (lua_State *L, int lvl); |
| 4198 | </pre> | 4220 | </pre> |
| @@ -4255,14 +4277,14 @@ If you do not include this library in your application, · 56 unmodified lines |
| 4255 | you should check carefully whether you need to provide some alternative | 4277 | you should check carefully whether you need to provide some alternative |
| 4256 | implementation for some of its facilities. | 4278 | implementation for some of its facilities. |
| 4257 | | 4279 | |
| 4258 | <p><a name="pdf-assert"></a><hr><h3><code>assert (v [, message])</code></h3> | 4280 | <p><a name="pdf-assert"></a><hr/><h3><code>assert (v [, message])</code></h3> |
| 4259 | Issues an error when | 4281 | Issues an error when |
| 4260 | the value of its argument <code>v</code> is <B>nil</B> or <B>false</B>; | 4282 | the value of its argument <code>v</code> is <b>nil</b> or <b>false</b>; |
| 4261 | otherwise, returns all its arguments. | 4283 | otherwise, returns all its arguments. |
| 4262 | <code>message</code> is an error message; | 4284 | <code>message</code> is an error message; |
| 4263 | when absent, it defaults to "assertion failed!" | 4285 | when absent, it defaults to "assertion failed!" |
| 4264 | | 4286 | |
| 4265 | <p><a name="pdf-collectgarbage"></a><hr><h3><code>collectgarbage (opt [, arg])</code></h3> | 4287 | <p><a name="pdf-collectgarbage"></a><hr/><h3><code>collectgarbage (opt [, arg])</code></h3> |
| 4266 | | 4288 | |
| 4267 | <p>This function is a generic interface to the garbage collector. | 4289 | <p>This function is a generic interface to the garbage collector. |
| 4268 | It performs different functions according to its first argument, <code>opt</code>: | 4290 | It performs different functions according to its first argument, <code>opt</code>: |
| @@ -4276,6 +4298,7 @@ The step "size" is controlled by <code>arg</code> · 7 unmodified lines |
| 4276 | (larger values mean more steps) in a non-specified way. | 4298 | (larger values mean more steps) in a non-specified way. |
| 4277 | If you want to control the step size | 4299 | If you want to control the step size |
| 4278 | you must tune experimentally the value of <code>arg</code>. | 4300 | you must tune experimentally the value of <code>arg</code>. |
| | 4301 | Returns <b>true</b> if that step finished a collection cycle. |
| 4279 | <li><b>"steppause"</b> | 4302 | <li><b>"steppause"</b> |
| 4280 | sets <em><code>arg</code>/100</em> as the new value for the <em>pause</em> of | 4303 | sets <em><code>arg</code>/100</em> as the new value for the <em>pause</em> of |
| 4281 | the collector (see <a href="#GC">2.10</a>). | 4304 | the collector (see <a href="#GC">2.10</a>). |
| @@ -4284,7 +4307,7 @@ sets <em><code>arg</code>/100</em> as the new value for the <em>step multiplier< · 2 unmodified lines |
| 4284 | the collector (see <a href="#GC">2.10</a>). | 4307 | the collector (see <a href="#GC">2.10</a>). |
| 4285 | </ul> | 4308 | </ul> |
| 4286 | | 4309 | |
| 4287 | <p><a name="pdf-dofile"></a><hr><h3><code>dofile (filename)</code></h3> | 4310 | <p><a name="pdf-dofile"></a><hr/><h3><code>dofile (filename)</code></h3> |
| 4288 | Opens the named file and executes its contents as a Lua chunk. | 4311 | Opens the named file and executes its contents as a Lua chunk. |
| 4289 | When called without arguments, | 4312 | When called without arguments, |
| 4290 | <a href="#pdf-dofile"><code>dofile</code></a> executes the contents of the standard input (<code>stdin</code>). | 4313 | <a href="#pdf-dofile"><code>dofile</code></a> executes the contents of the standard input (<code>stdin</code>). |
| @@ -4292,7 +4315,7 @@ Returns any value returned by the chunk. · 1 unmodified line |
| 4292 | In case of errors, <a href="#pdf-dofile"><code>dofile</code></a> propagates the error | 4315 | In case of errors, <a href="#pdf-dofile"><code>dofile</code></a> propagates the error |
| 4293 | to its caller (that is, it does not run in protected mode). | 4316 | to its caller (that is, it does not run in protected mode). |
| 4294 | | 4317 | |
| 4295 | <p><a name="pdf-error"></a><hr><h3><code>error (message [, level])</code></h3> | 4318 | <p><a name="pdf-error"></a><hr/><h3><code>error (message [, level])</code></h3> |
| 4296 | Terminates the last protected function called | 4319 | Terminates the last protected function called |
| 4297 | and returns <code>message</code> as the error message. | 4320 | and returns <code>message</code> as the error message. |
| 4298 | Function <a href="#pdf-error"><code>error</code></a> never returns. | 4321 | Function <a href="#pdf-error"><code>error</code></a> never returns. |
| @@ -4307,14 +4330,14 @@ that called <a href="#pdf-error"><code>error</code></a> was called; and so on. · 8 unmodified lines |
| 4307 | Passing a level 0 avoids the addition of error position information | 4330 | Passing a level 0 avoids the addition of error position information |
| 4308 | to the message. | 4331 | to the message. |
| 4309 | | 4332 | |
| 4310 | <p><a name="pdf-_G"></a><hr><h3><code>_G</code></h3> | 4333 | <p><a name="pdf-_G"></a><hr/><h3><code>_G</code></h3> |
| 4311 | A global variable (not a function) that | 4334 | A global variable (not a function) that |
| 4312 | holds the global environment (that is, <code>_G._G = _G</code>). | 4335 | holds the global environment (that is, <code>_G._G = _G</code>). |
| 4313 | Lua itself does not use this variable; | 4336 | Lua itself does not use this variable; |
| 4314 | changing its value does not affect any environment. | 4337 | changing its value does not affect any environment. |
| 4315 | (Use <a href="#pdf-setfenv"><code>setfenv</code></a> to change environments.) | 4338 | (Use <a href="#pdf-setfenv"><code>setfenv</code></a> to change environments.) |
| 4316 | | 4339 | |
| 4317 | <p><a name="pdf-getfenv"></a><hr><h3><code>getfenv (f)</code></h3> | 4340 | <p><a name="pdf-getfenv"></a><hr/><h3><code>getfenv (f)</code></h3> |
| 4318 | Returns the current environment in use by the function. | 4341 | Returns the current environment in use by the function. |
| 4319 | <code>f</code> can be a Lua function or a number, | 4342 | <code>f</code> can be a Lua function or a number, |
| 4320 | which specifies the function at that stack level: | 4343 | which specifies the function at that stack level: |
| @@ -4324,73 +4347,73 @@ or if <code>f</code> is 0, · 3 unmodified lines |
| 4324 | <a href="#pdf-getfenv"><code>getfenv</code></a> returns the global environment. | 4347 | <a href="#pdf-getfenv"><code>getfenv</code></a> returns the global environment. |
| 4325 | The default for <code>f</code> is 1. | 4348 | The default for <code>f</code> is 1. |
| 4326 | | 4349 | |
| 4327 | <p><a name="pdf-getmetatable"></a><hr><h3><code>getmetatable (object)</code></h3> | 4350 | <p><a name="pdf-getmetatable"></a><hr/><h3><code>getmetatable (object)</code></h3> |
| 4328 | | 4351 | |
| 4329 | <p>If <code>object</code> does not have a metatable, returns <B>nil</B>. | 4352 | <p>If <code>object</code> does not have a metatable, returns <b>nil</b>. |
| 4330 | Otherwise, | 4353 | Otherwise, |
| 4331 | if the object's metatable has a <code>"__metatable"</code> field, | 4354 | if the object's metatable has a <code>"__metatable"</code> field, |
| 4332 | returns the associated value. | 4355 | returns the associated value. |
| 4333 | Otherwise, returns the metatable of the given object. | 4356 | Otherwise, returns the metatable of the given object. |
| 4334 | | 4357 | |
| 4335 | <p><a name="pdf-ipairs"></a><hr><h3><code>ipairs (t)</code></h3> | 4358 | <p><a name="pdf-ipairs"></a><hr/><h3><code>ipairs (t)</code></h3> |
| 4336 | | 4359 | |
| 4337 | <p>Returns an iterator function, the table <code>t</code>, and 0, | 4360 | <p>Returns an iterator function, the table <code>t</code>, and 0, |
| 4338 | so that the construction | 4361 | so that the construction |
| 4339 | <PRE> | 4362 | <pre> |
| 4340 | for i,v in ipairs(t) do ... end | 4363 | for i,v in ipairs(t) do ... end |
| 4341 | </PRE> | 4364 | </pre> |
| 4342 | will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ..., | 4365 | will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ..., |
| 4343 | up to the first integer key with a nil value in the table. | 4366 | up to the first integer key with a nil value in the table. |
| 4344 | | 4367 | |
| 4345 | <p><a name="pdf-load"></a><hr><h3><code>load (func [, chunkname])</code></h3> | 4368 | <p><a name="pdf-load"></a><hr/><h3><code>load (func [, chunkname])</code></h3> |
| 4346 | | 4369 | |
| 4347 | <p>Loads a chunk using function <code>func</code> to get its pieces. | 4370 | <p>Loads a chunk using function <code>func</code> to get its pieces. |
| 4348 | Each call to <code>func</code> must return a string that concatenates | 4371 | Each call to <code>func</code> must return a string that concatenates |
| 4349 | with previous results. | 4372 | with previous results. |
| 4350 | A return of <B>nil</B> (or no value) signals the end of the chunk. | 4373 | A return of <b>nil</b> (or no value) signals the end of the chunk. |
| 4351 | | 4374 | |
| 4352 | <p>If there are no errors, | 4375 | <p>If there are no errors, |
| 4353 | returns the compiled chunk as a function; | 4376 | returns the compiled chunk as a function; |
| 4354 | otherwise, returns <B>nil</B> plus the error message. | 4377 | otherwise, returns <b>nil</b> plus the error message. |
| 4355 | The environment of the returned function is the global environment. | 4378 | The environment of the returned function is the global environment. |
| 4356 | | 4379 | |
| 4357 | <p><code>chunkname</code> is used as the chunk name for error messages | 4380 | <p><code>chunkname</code> is used as the chunk name for error messages |
| 4358 | and debug information. | 4381 | and debug information. |
| 4359 | | 4382 | |
| 4360 | <p><a name="pdf-loadfile"></a><hr><h3><code>loadfile (filename)</code></h3> | 4383 | <p><a name="pdf-loadfile"></a><hr/><h3><code>loadfile (filename)</code></h3> |
| 4361 | | 4384 | |
| 4362 | <p>Similar to <a href="#pdf-load"><code>load</code></a>, | 4385 | <p>Similar to <a href="#pdf-load"><code>load</code></a>, |
| 4363 | but gets the chunk from file <code>filename</code>. | 4386 | but gets the chunk from file <code>filename</code>. |
| 4364 | | 4387 | |
| 4365 | <p><a name="pdf-loadstring"></a><hr><h3><code>loadstring (string [, chunkname])</code></h3> | 4388 | <p><a name="pdf-loadstring"></a><hr/><h3><code>loadstring (string [, chunkname])</code></h3> |
| 4366 | | 4389 | |
| 4367 | <p>Similar to <a href="#pdf-load"><code>load</code></a>, | 4390 | <p>Similar to <a href="#pdf-load"><code>load</code></a>, |
| 4368 | but gets the chunk from the given string. | 4391 | but gets the chunk from the given string. |
| 4369 | | 4392 | |
| 4370 | <p>To load and run a given string, use the idiom | 4393 | <p>To load and run a given string, use the idiom |
| 4371 | <PRE> | 4394 | <pre> |
| 4372 | assert(loadstring(s))() | 4395 | assert(loadstring(s))() |
| 4373 | </PRE> | 4396 | </pre> |
| 4374 | | 4397 | |
| 4375 | <p><a name="pdf-next"></a><hr><h3><code>next (table [, index])</code></h3> | 4398 | <p><a name="pdf-next"></a><hr/><h3><code>next (table [, index])</code></h3> |
| 4376 | | 4399 | |
| 4377 | <p>Allows a program to traverse all fields of a table. | 4400 | <p>Allows a program to traverse all fields of a table. |
| 4378 | Its first argument is a table and its second argument | 4401 | Its first argument is a table and its second argument |
| 4379 | is an index in this table. | 4402 | is an index in this table. |
| 4380 | <a href="#pdf-next"><code>next</code></a> returns the next index of the table and the | 4403 | <a href="#pdf-next"><code>next</code></a> returns the next index of the table and the |
| 4381 | value associated with the index. | 4404 | value associated with the index. |
| 4382 | When called with <B>nil</B> as its second argument, | 4405 | When called with <b>nil</b> as its second argument, |
| 4383 | <a href="#pdf-next"><code>next</code></a> returns the first index | 4406 | <a href="#pdf-next"><code>next</code></a> returns the first index |
| 4384 | of the table and its associated value. | 4407 | of the table and its associated value. |
| 4385 | When called with the last index, | 4408 | When called with the last index, |
| 4386 | or with <B>nil</B> in an empty table, | 4409 | or with <b>nil</b> in an empty table, |
| 4387 | <a href="#pdf-next"><code>next</code></a> returns <B>nil</B>. | 4410 | <a href="#pdf-next"><code>next</code></a> returns <b>nil</b>. |
| 4388 | If the second argument is absent, then it is interpreted as <B>nil</B>. | 4411 | If the second argument is absent, then it is interpreted as <b>nil</b>. |
| 4389 | | 4412 | |
| 4390 | <p>Lua has no declaration of fields; | 4413 | <p>Lua has no declaration of fields; |
| 4391 | There is no difference between a | 4414 | There is no difference between a |
| 4392 | field not present in a table or a field with value <B>nil</B>. | 4415 | field not present in a table or a field with value <b>nil</b>. |
| 4393 | Therefore, <a href="#pdf-next"><code>next</code></a> only considers fields with non-<B>nil</B> values. | 4416 | Therefore, <a href="#pdf-next"><code>next</code></a> only considers fields with non-<b>nil</b> values. |
| 4394 | The order in which the indices are enumerated is not specified, | 4417 | The order in which the indices are enumerated is not specified, |
| 4395 | <em>even for numeric indices</em>. | 4418 | <em>even for numeric indices</em>. |
| 4396 | (To traverse a table in numeric order, | 4419 | (To traverse a table in numeric order, |
| @@ -4400,16 +4423,16 @@ use a numerical <b>for</b> or the <a href="#pdf-ipairs"><code>ipairs</code></a> · 3 unmodified lines |
| 4400 | during the traversal, | 4423 | during the traversal, |
| 4401 | you assign any value to a non-existent field in the table. | 4424 | you assign any value to a non-existent field in the table. |
| 4402 | | 4425 | |
| 4403 | <p><a name="pdf-pairs"></a><hr><h3><code>pairs (t)</code></h3> | 4426 | <p><a name="pdf-pairs"></a><hr/><h3><code>pairs (t)</code></h3> |
| 4404 | | 4427 | |
| 4405 | <p>Returns the <a href="#pdf-next"><code>next</code></a> function and the table <code>t</code> (plus a <B>nil</B>), | 4428 | <p>Returns the <a href="#pdf-next"><code>next</code></a> function and the table <code>t</code> (plus a <b>nil</b>), |
| 4406 | so that the construction | 4429 | so that the construction |
| 4407 | <PRE> | 4430 | <pre> |
| 4408 | for k,v in pairs(t) do ... end | 4431 | for k,v in pairs(t) do ... end |
| 4409 | </PRE> | 4432 | </pre> |
| 4410 | will iterate over all key–value pairs of table <code>t</code>. | 4433 | will iterate over all key--value pairs of table <code>t</code>. |
| 4411 | | 4434 | |
| 4412 | <p><a name="pdf-pcall"></a><hr><h3><code>pcall (f, arg1, arg2, ...)</code></h3> | 4435 | <p><a name="pdf-pcall"></a><hr/><h3><code>pcall (f, arg1, arg2, ...)</code></h3> |
| 4413 | | 4436 | |
| 4414 | <p>Calls function <code>f</code> with | 4437 | <p>Calls function <code>f</code> with |
| 4415 | the given arguments in protected mode. | 4438 | the given arguments in protected mode. |
| @@ -4420,9 +4443,9 @@ Its first result is the status code (a boolean), · 4 unmodified lines |
| 4420 | which is true if the call succeeds without errors. | 4443 | which is true if the call succeeds without errors. |
| 4421 | In such case, <a href="#pdf-pcall"><code>pcall</code></a> also returns all results from the call, | 4444 | In such case, <a href="#pdf-pcall"><code>pcall</code></a> also returns all results from the call, |
| 4422 | after this first result. | 4445 | after this first result. |
| 4423 | In case of any error, <a href="#pdf-pcall"><code>pcall</code></a> returns <B>false</B> plus the error message. | 4446 | In case of any error, <a href="#pdf-pcall"><code>pcall</code></a> returns <b>false</b> plus the error message. |
| 4424 | | 4447 | |
| 4425 | <p><a name="pdf-print"></a><hr><h3><code>print (e1, e2, ...)</code></h3> | 4448 | <p><a name="pdf-print"></a><hr/><h3><code>print (e1, e2, ...)</code></h3> |
| 4426 | Receives any number of arguments, | 4449 | Receives any number of arguments, |
| 4427 | and prints their values in <code>stdout</code>, | 4450 | and prints their values in <code>stdout</code>, |
| 4428 | using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings. | 4451 | using the <a href="#pdf-tostring"><code>tostring</code></a> function to convert them to strings. |
| @@ -4431,32 +4454,32 @@ but only as a quick way to show a value, · 2 unmodified lines |
| 4431 | typically for debugging. | 4454 | typically for debugging. |
| 4432 | For formatted output, use <code>format</code> (see <a href="#format">5.4</a>). | 4455 | For formatted output, use <code>format</code> (see <a href="#format">5.4</a>). |
| 4433 | | 4456 | |
| 4434 | <p><a name="pdf-rawequal"></a><hr><h3><code>rawequal (v1, v2)</code></h3> | 4457 | <p><a name="pdf-rawequal"></a><hr/><h3><code>rawequal (v1, v2)</code></h3> |
| 4435 | Checks whether <code>v1</code> is equal to <code>v2</code>, | 4458 | Checks whether <code>v1</code> is equal to <code>v2</code>, |
| 4436 | without invoking any metamethod. | 4459 | without invoking any metamethod. |
| 4437 | Returns a boolean. | 4460 | Returns a boolean. |
| 4438 | | 4461 | |
| 4439 | <p><a name="pdf-rawget"></a><hr><h3><code>rawget (table, index)</code></h3> | 4462 | <p><a name="pdf-rawget"></a><hr/><h3><code>rawget (table, index)</code></h3> |
| 4440 | Gets the real value of <code>table[index]</code>, | 4463 | Gets the real value of <code>table[index]</code>, |
| 4441 | without invoking any metamethod. | 4464 | without invoking any metamethod. |
| 4442 | <code>table</code> must be a table; | 4465 | <code>table</code> must be a table; |
| 4443 | <code>index</code> is any value different from <B>nil</B>. | 4466 | <code>index</code> is any value different from <b>nil</b>. |
| 4444 | | 4467 | |
| 4445 | <p><a name="pdf-rawset"></a><hr><h3><code>rawset (table, index, value)</code></h3> | 4468 | <p><a name="pdf-rawset"></a><hr/><h3><code>rawset (table, index, value)</code></h3> |
| 4446 | Sets the real value of <code>table[index]</code> to <code>value</code>, | 4469 | Sets the real value of <code>table[index]</code> to <code>value</code>, |
| 4447 | without invoking any metamethod. | 4470 | without invoking any metamethod. |
| 4448 | <code>table</code> must be a table, | 4471 | <code>table</code> must be a table, |
| 4449 | <code>index</code> is any value different from <B>nil</B>, | 4472 | <code>index</code> is any value different from <b>nil</b>, |
| 4450 | and <code>value</code> is any Lua value. | 4473 | and <code>value</code> is any Lua value. |
| 4451 | | 4474 | |
| 4452 | <p><a name="pdf-select"></a><hr><h3><code>select (index, ...)</code></h3> | 4475 | <p><a name="pdf-select"></a><hr/><h3><code>select (index, ...)</code></h3> |
| 4453 | | 4476 | |
| 4454 | <p>If <code>index</code> is a number, | 4477 | <p>If <code>index</code> is a number, |
| 4455 | returns all argument after argument number <code>index</code>. | 4478 | returns all argument after argument number <code>index</code>. |
| 4456 | Otherwise, <code>index</code> must be the string <code>"#"</code>, | 4479 | Otherwise, <code>index</code> must be the string <code>"#"</code>, |
| 4457 | and <code>select</code> returns the total number of extra arguments it received. | 4480 | and <code>select</code> returns the total number of extra arguments it received. |
| 4458 | | 4481 | |
| 4459 | <p><a name="setfenv"></a><a name="pdf-setfenv"></a><hr><h3><code>setfenv (f, table)</code></h3> | 4482 | <p><a name="setfenv"></a><a name="pdf-setfenv"></a><hr/><h3><code>setfenv (f, table)</code></h3> |
| 4460 | | 4483 | |
| 4461 | <p>Sets the environment to be used by the given function. | 4484 | <p>Sets the environment to be used by the given function. |
| 4462 | <code>f</code> can be a Lua function or a number, | 4485 | <code>f</code> can be a Lua function or a number, |
| @@ -4468,22 +4491,22 @@ Level 1 is the function calling <a href="#pdf-setfenv"><code>setfenv</code></a>. · 5 unmodified lines |
| 4468 | the environment of the running thread. | 4491 | the environment of the running thread. |
| 4469 | In this case, <a href="#pdf-setfenv"><code>setfenv</code></a> returns no values. | 4492 | In this case, <a href="#pdf-setfenv"><code>setfenv</code></a> returns no values. |
| 4470 | | 4493 | |
| 4471 | <p><a name="pdf-setmetatable"></a><hr><h3><code>setmetatable (table, metatable)</code></h3> | 4494 | <p><a name="pdf-setmetatable"></a><hr/><h3><code>setmetatable (table, metatable)</code></h3> |
| 4472 | | 4495 | |
| 4473 | <p>Sets the metatable for the given table. | 4496 | <p>Sets the metatable for the given table. |
| 4474 | (You cannot change the metatable of other types from Lua.) | 4497 | (You cannot change the metatable of other types from Lua.) |
| 4475 | If <code>metatable</code> is <B>nil</B>, | 4498 | If <code>metatable</code> is <b>nil</b>, |
| 4476 | removes the metatable of the given table. | 4499 | removes the metatable of the given table. |
| 4477 | If the original metatable has a <code>"__metatable"</code> field, | 4500 | If the original metatable has a <code>"__metatable"</code> field, |
| 4478 | raises an error. | 4501 | raises an error. |
| 4479 | | 4502 | |
| 4480 | <p>This function returns <code>table</code>. | 4503 | <p>This function returns <code>table</code>. |
| 4481 | | 4504 | |
| 4482 | <p><a name="pdf-tonumber"></a><hr><h3><code>tonumber (e [, base])</code></h3> | 4505 | <p><a name="pdf-tonumber"></a><hr/><h3><code>tonumber (e [, base])</code></h3> |
| 4483 | Tries to convert its argument to a number. | 4506 | Tries to convert its argument to a number. |
| 4484 | If the argument is already a number or a string convertible | 4507 | If the argument is already a number or a string convertible |
| 4485 | to a number, then <a href="#pdf-tonumber"><code>tonumber</code></a> returns that number; | 4508 | to a number, then <a href="#pdf-tonumber"><code>tonumber</code></a> returns that number; |
| 4486 | otherwise, it returns <B>nil</B>. | 4509 | otherwise, it returns <b>nil</b>. |
| 4487 | | 4510 | |
| 4488 | <p>An optional argument specifies the base to interpret the numeral. | 4511 | <p>An optional argument specifies the base to interpret the numeral. |
| 4489 | The base may be any integer between 2 and 36, inclusive. | 4512 | The base may be any integer between 2 and 36, inclusive. |
| @@ -4494,7 +4517,7 @@ In base 10 (the default), the number may have a decimal part, · 4 unmodified lines |
| 4494 | as well as an optional exponent part (see <a href="#coercion">2.2.1</a>). | 4517 | as well as an optional exponent part (see <a href="#coercion">2.2.1</a>). |
| 4495 | In other bases, only unsigned integers are accepted. | 4518 | In other bases, only unsigned integers are accepted. |
| 4496 | | 4519 | |
| 4497 | <p><a name="pdf-tostring"></a><hr><h3><code>tostring (e)</code></h3> | 4520 | <p><a name="pdf-tostring"></a><hr/><h3><code>tostring (e)</code></h3> |
| 4498 | Receives an argument of any type and | 4521 | Receives an argument of any type and |
| 4499 | converts it to a string in a reasonable format. | 4522 | converts it to a string in a reasonable format. |
| 4500 | For complete control of how numbers are converted, | 4523 | For complete control of how numbers are converted, |
| @@ -4505,10 +4528,10 @@ use <a href="#pdf-string.format"><code>string.format</code></a> (see <a href="#f · 4 unmodified lines |
| 4505 | with <code>e</code> as argument, | 4528 | with <code>e</code> as argument, |
| 4506 | and uses the result of the call as its result. | 4529 | and uses the result of the call as its result. |
| 4507 | | 4530 | |
| 4508 | <p><a name="pdf-type"></a><hr><h3><code>type (v)</code></h3> | 4531 | <p><a name="pdf-type"></a><hr/><h3><code>type (v)</code></h3> |
| 4509 | Returns the type of its only argument, coded as a string. | 4532 | Returns the type of its only argument, coded as a string. |
| 4510 | The possible results of this function are | 4533 | The possible results of this function are |
| 4511 | <code>"nil"</code> (a string, not the value <B>nil</B>), | 4534 | <code>"nil"</code> (a string, not the value <b>nil</b>), |
| 4512 | <code>"number"</code>, | 4535 | <code>"number"</code>, |
| 4513 | <code>"string"</code>, | 4536 | <code>"string"</code>, |
| 4514 | <code>"boolean</code>, | 4537 | <code>"boolean</code>, |
| @@ -4517,23 +4540,23 @@ The possible results of this function are · 2 unmodified lines |
| 4517 | <code>"thread"</code>, | 4540 | <code>"thread"</code>, |
| 4518 | and <code>"userdata"</code>. | 4541 | and <code>"userdata"</code>. |
| 4519 | | 4542 | |
| 4520 | <p><a name="pdf-unpack"></a><hr><h3><code>unpack (list [, i [, j]])</code></h3> | 4543 | <p><a name="pdf-unpack"></a><hr/><h3><code>unpack (list [, i [, j]])</code></h3> |
| 4521 | Returns the elements from the given list. | 4544 | Returns the elements from the given list. |
| 4522 | This function is equivalent to | 4545 | This function is equivalent to |
| 4523 | <PRE> | 4546 | <pre> |
| 4524 | return list[i], list[i+1], ..., list[j] | 4547 | return list[i], list[i+1], ..., list[j] |
| 4525 | </PRE> | 4548 | </pre> |
| 4526 | except that the above code can be written only for a fixed number | 4549 | except that the above code can be written only for a fixed number |
| 4527 | of elements. | 4550 | of elements. |
| 4528 | By default, <code>i</code> is 1 and <code>j</code> is the length of the list, | 4551 | By default, <code>i</code> is 1 and <code>j</code> is the length of the list, |
| 4529 | as defined by the length operator. | 4552 | as defined by the length operator. |
| 4530 | | 4553 | |
| 4531 | <p><a name="pdf-_VERSION"></a><hr><h3><code>_VERSION</code></h3> | 4554 | <p><a name="pdf-_VERSION"></a><hr/><h3><code>_VERSION</code></h3> |
| 4532 | A global variable (not a function) that | 4555 | A global variable (not a function) that |
| 4533 | holds a string containing the current interpreter version. | 4556 | holds a string containing the current interpreter version. |
| 4534 | The current contents of this variable is <code>"Lua 5.1"</code>. | 4557 | The current contents of this variable is <code>"Lua 5.1"</code>. |
| 4535 | | 4558 | |
| 4536 | <p><a name="pdf-xpcall"></a><hr><h3><code>xpcall (f, err)</code></h3> | 4559 | <p><a name="pdf-xpcall"></a><hr/><h3><code>xpcall (f, err)</code></h3> |
| 4537 | | 4560 | |
| 4538 | <p>This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>, | 4561 | <p>This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>, |
| 4539 | except that you can set a new error handler. | 4562 | except that you can set a new error handler. |
| @@ -4557,14 +4580,14 @@ In case of any error, · 17 unmodified lines |
| 4557 | the basic library and come inside the table <code>coroutine</code>. | 4580 | the basic library and come inside the table <code>coroutine</code>. |
| 4558 | See <a href="#coroutine">2.11</a> for a general description of coroutines. | 4581 | See <a href="#coroutine">2.11</a> for a general description of coroutines. |
| 4559 | | 4582 | |
| 4560 | <p><a name="pdf-coroutine.create"></a><hr><h3><code>coroutine.create (f)</code></h3> | 4583 | <p><a name="pdf-coroutine.create"></a><hr/><h3><code>coroutine.create (f)</code></h3> |
| 4561 | | 4584 | |
| 4562 | <p>Creates a new coroutine, with body <code>f</code>. | 4585 | <p>Creates a new coroutine, with body <code>f</code>. |
| 4563 | <code>f</code> must be a Lua function. | 4586 | <code>f</code> must be a Lua function. |
| 4564 | Returns this new coroutine, | 4587 | Returns this new coroutine, |
| 4565 | an object with type <code>"thread"</code>. | 4588 | an object with type <code>"thread"</code>. |
| 4566 | | 4589 | |
| 4567 | <p><a name="pdf-coroutine.resume"></a><hr><h3><code>coroutine.resume (co, val1, ...)</code></h3> | 4590 | <p><a name="pdf-coroutine.resume"></a><hr/><h3><code>coroutine.resume (co, val1, ...)</code></h3> |
| 4568 | | 4591 | |
| 4569 | <p>Starts or continues the execution of coroutine <code>co</code>. | 4592 | <p>Starts or continues the execution of coroutine <code>co</code>. |
| 4570 | The first time you resume a coroutine, | 4593 | The first time you resume a coroutine, |
| @@ -4575,18 +4598,18 @@ If the coroutine has yielded, · 4 unmodified lines |
| 4575 | the arguments <code>val1</code>, ... go as the results from the yield. | 4598 | the arguments <code>val1</code>, ... go as the results from the yield. |
| 4576 | | 4599 | |
| 4577 | <p>If the coroutine runs without any errors, | 4600 | <p>If the coroutine runs without any errors, |
| 4578 | <code>resume</code> returns <B>true</B> plus any values passed to <code>yield</code> | 4601 | <code>resume</code> returns <b>true</b> plus any values passed to <code>yield</code> |
| 4579 | (if the coroutine yields) or any values returned by the body function | 4602 | (if the coroutine yields) or any values returned by the body function |
| 4580 | (if the coroutine terminates). | 4603 | (if the coroutine terminates). |
| 4581 | If there is any error, | 4604 | If there is any error, |
| 4582 | <code>resume</code> returns <B>false</B> plus the error message. | 4605 | <code>resume</code> returns <b>false</b> plus the error message. |
| 4583 | | 4606 | |
| 4584 | <p><a name="pdf-coroutine.running"></a><hr><h3><code>coroutine.running ()</code></h3> | 4607 | <p><a name="pdf-coroutine.running"></a><hr/><h3><code>coroutine.running ()</code></h3> |
| 4585 | | 4608 | |
| 4586 | <p>Returns the running coroutine, | 4609 | <p>Returns the running coroutine, |
| 4587 | or <B>nil</B> when called by the main thread. | 4610 | or <b>nil</b> when called by the main thread. |
| 4588 | | 4611 | |
| 4589 | <p><a name="pdf-coroutine.status"></a><hr><h3><code>coroutine.status (co)</code></h3> | 4612 | <p><a name="pdf-coroutine.status"></a><hr/><h3><code>coroutine.status (co)</code></h3> |
| 4590 | | 4613 | |
| 4591 | <p>Returns the status of coroutine <code>co</code>, as a string: | 4614 | <p>Returns the status of coroutine <code>co</code>, as a string: |
| 4592 | <code>"running"</code>, | 4615 | <code>"running"</code>, |
| @@ -4598,7 +4621,7 @@ or if it has not started running yet; · 5 unmodified lines |
| 4598 | and <code>"dead"</code> if the coroutine has finished its body function, | 4621 | and <code>"dead"</code> if the coroutine has finished its body function, |
| 4599 | or if it has stopped with an error. | 4622 | or if it has stopped with an error. |
| 4600 | | 4623 | |
| 4601 | <p><a name="pdf-coroutine.wrap"></a><hr><h3><code>coroutine.wrap (f)</code></h3> | 4624 | <p><a name="pdf-coroutine.wrap"></a><hr/><h3><code>coroutine.wrap (f)</code></h3> |
| 4602 | | 4625 | |
| 4603 | <p>Creates a new coroutine, with body <code>f</code>. | 4626 | <p>Creates a new coroutine, with body <code>f</code>. |
| 4604 | <code>f</code> must be a Lua function. | 4627 | <code>f</code> must be a Lua function. |
| @@ -4609,7 +4632,7 @@ Returns the same values returned by <code>resume</code>, · 4 unmodified lines |
| 4609 | except the first boolean. | 4632 | except the first boolean. |
| 4610 | In case of error, propagates the error. | 4633 | In case of error, propagates the error. |
| 4611 | | 4634 | |
| 4612 | <p><a name="pdf-coroutine.yield"></a><hr><h3><code>coroutine.yield (val1, ...)</code></h3> | 4635 | <p><a name="pdf-coroutine.yield"></a><hr/><h3><code>coroutine.yield (val1, ...)</code></h3> |
| 4613 | | 4636 | |
| 4614 | <p>Suspends the execution of the calling coroutine. | 4637 | <p>Suspends the execution of the calling coroutine. |
| 4615 | The coroutine cannot be running neither a C function, | 4638 | The coroutine cannot be running neither a C function, |
| @@ -4624,7 +4647,7 @@ It exports two of its functions directly in the global environment: · 8 unmodified lines |
| 4624 | <a href="#pdf-require"><code>require</code></a> and <a href="#pdf-module"><code>module</code></a>. | 4647 | <a href="#pdf-require"><code>require</code></a> and <a href="#pdf-module"><code>module</code></a>. |
| 4625 | Everything else is exported in a table <code>package</code>. | 4648 | Everything else is exported in a table <code>package</code>. |
| 4626 | | 4649 | |
| 4627 | <p><a name="pdf-module"></a><hr><h3><code>module (name [, ...])</code></h3> | 4650 | <p><a name="pdf-module"></a><hr/><h3><code>module (name [, ...])</code></h3> |
| 4628 | | 4651 | |
| 4629 | <p>Creates a module. | 4652 | <p>Creates a module. |
| 4630 | If there is a table in <code>package.loaded[name]</code>, | 4653 | If there is a table in <code>package.loaded[name]</code>, |
| @@ -4654,7 +4677,7 @@ field <code>b</code> of global <code>a</code>. · 23 unmodified lines |
| 4654 | the module name, | 4677 | the module name, |
| 4655 | where each option is a function to be applied over the module. | 4678 | where each option is a function to be applied over the module. |
| 4656 | | 4679 | |
| 4657 | <p><a name="pdf-require"></a><hr><h3><code>require (modname)</code></h3> | 4680 | <p><a name="pdf-require"></a><hr/><h3><code>require (modname)</code></h3> |
| 4658 | | 4681 | |
| 4659 | <p>Loads the given module. | 4682 | <p>Loads the given module. |
| 4660 | The function starts by looking into the table <code>package.loaded</code> | 4683 | The function starts by looking into the table <code>package.loaded</code> |
| @@ -4682,9 +4705,9 @@ be used as the loader. · 21 unmodified lines |
| 4682 | The name of that C function is the string <code>"luaopen_"</code> | 4705 | The name of that C function is the string <code>"luaopen_"</code> |
| 4683 | concatenated with a copy of the module name wherein each dot | 4706 | concatenated with a copy of the module name wherein each dot |
| 4684 | is replaced by an underscore. | 4707 | is replaced by an underscore. |
| 4685 | Moreover, if the module name has a colon, | 4708 | Moreover, if the module name has a hyphen, |
| 4686 | its prefix up to (and including) the first colon is removed. | 4709 | its prefix up to (and including) the first hyphen is removed. |
| 4687 | For instance, if the module name is <code>a.v1:b.c</code>, | 4710 | For instance, if the module name is <code>a.v1-b.c</code>, |
| 4688 | the function name will be <code>luaopen_b_c</code>. | 4711 | the function name will be <code>luaopen_b_c</code>. |
| 4689 | | 4712 | |
| 4690 | <p>If <a href="#pdf-require"><code>require</code></a> finds neither a Lua library nor a | 4713 | <p>If <a href="#pdf-require"><code>require</code></a> finds neither a Lua library nor a |
| @@ -4715,7 +4738,7 @@ final value of <code>package.loaded[modname]</code>. · 24 unmodified lines |
| 4715 | or if it cannot find any loader for that module, | 4738 | or if it cannot find any loader for that module, |
| 4716 | then <a href="#pdf-require"><code>require</code></a> signals an error. | 4739 | then <a href="#pdf-require"><code>require</code></a> signals an error. |
| 4717 | | 4740 | |
| 4718 | <p><a name="pdf-package.cpath"></a><hr><h3><code>package.cpath</code></h3> | 4741 | <p><a name="pdf-package.cpath"></a><hr/><h3><code>package.cpath</code></h3> |
| 4719 | | 4742 | |
| 4720 | <p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader. | 4743 | <p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a C loader. |
| 4721 | | 4744 | |
| @@ -4724,7 +4747,7 @@ it initializes the Lua path <a href="#pdf-package.path"><code>package.path</code · 2 unmodified lines |
| 4724 | using the environment variable <code>LUA_CPATH</code> | 4747 | using the environment variable <code>LUA_CPATH</code> |
| 4725 | (plus another compiled-defined default path). | 4748 | (plus another compiled-defined default path). |
| 4726 | | 4749 | |
| 4727 | <p><a name="pdf-package.loaded"></a><hr><h3><code>package.loaded</code></h3> | 4750 | <p><a name="pdf-package.loaded"></a><hr/><h3><code>package.loaded</code></h3> |
| 4728 | | 4751 | |
| 4729 | <p>A table used by <a href="#pdf-require"><code>require</code></a> to control which | 4752 | <p>A table used by <a href="#pdf-require"><code>require</code></a> to control which |
| 4730 | modules are already loaded. | 4753 | modules are already loaded. |
| @@ -4732,7 +4755,7 @@ When you require a module <code>modname</code> and · 1 unmodified line |
| 4732 | <code>package.loaded[modname]</code> is not false, | 4755 | <code>package.loaded[modname]</code> is not false, |
| 4733 | <a href="#pdf-require"><code>require</code></a> simply returns the value stored there. | 4756 | <a href="#pdf-require"><code>require</code></a> simply returns the value stored there. |
| 4734 | | 4757 | |
| 4735 | <p><a name="pdf-package.loadlib"></a><hr><h3><code>package.loadlib (libname, funcname)</code></h3> | 4758 | <p><a name="pdf-package.loadlib"></a><hr/><h3><code>package.loadlib (libname, funcname)</code></h3> |
| 4736 | | 4759 | |
| 4737 | <p>Links the program with the dynamic C library <code>libname</code>. | 4760 | <p>Links the program with the dynamic C library <code>libname</code>. |
| 4738 | Inside this library, looks for a function <code>funcname</code> | 4761 | Inside this library, looks for a function <code>funcname</code> |
| @@ -4746,7 +4769,7 @@ As such, it is only available on some platforms · 7 unmodified lines |
| 4746 | (Windows, Linux, Solaris, BSD, plus other Unix systems that | 4769 | (Windows, Linux, Solaris, BSD, plus other Unix systems that |
| 4747 | support the <code>dlfcn</code> standard). | 4770 | support the <code>dlfcn</code> standard). |
| 4748 | | 4771 | |
| 4749 | <p><a name="pdf-package.path"></a><hr><h3><code>package.path</code></h3> | 4772 | <p><a name="pdf-package.path"></a><hr/><h3><code>package.path</code></h3> |
| 4750 | | 4773 | |
| 4751 | <p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader. | 4774 | <p>The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader. |
| 4752 | | 4775 | |
| @@ -4764,20 +4787,20 @@ which is <code>modname</code> with each dot replaced by a · 11 unmodified lines |
| 4764 | "directory separator" (such as <code>"/"</code> in Unix); | 4787 | "directory separator" (such as <code>"/"</code> in Unix); |
| 4765 | then it will try to load the resulting file name. | 4788 | then it will try to load the resulting file name. |
| 4766 | So, for instance, if the Lua path is | 4789 | So, for instance, if the Lua path is |
| 4767 | <PRE> | 4790 | <pre> |
| 4768 | "./?.lua;./?.lc;/usr/local/?/init.lua" | 4791 | "./?.lua;./?.lc;/usr/local/?/init.lua" |
| 4769 | </PRE> | 4792 | </pre> |
| 4770 | the search for a Lua loader for module <code>mod</code> | 4793 | the search for a Lua loader for module <code>mod</code> |
| 4771 | will try to load the files | 4794 | will try to load the files |
| 4772 | <code>./mod.lua</code>, <code>./mod.lc</code>, and | 4795 | <code>./mod.lua</code>, <code>./mod.lc</code>, and |
| 4773 | <code>/usr/local/mod/init.lua</code>, in that order. | 4796 | <code>/usr/local/mod/init.lua</code>, in that order. |
| 4774 | | 4797 | |
| 4775 | <p><a name="pdf-package.preload"></a><hr><h3><code>package.preload</code></h3> | 4798 | <p><a name="pdf-package.preload"></a><hr/><h3><code>package.preload</code></h3> |
| 4776 | | 4799 | |
| 4777 | <p>A table to store loaders for specific modules | 4800 | <p>A table to store loaders for specific modules |
| 4778 | (see <a href="#pdf-require"><code>require</code></a>). | 4801 | (see <a href="#pdf-require"><code>require</code></a>). |
| 4779 | | 4802 | |
| 4780 | <p><a name="pdf-package.seeall"></a><hr><h3><code>package.seeall (module)</code></h3> | 4803 | <p><a name="pdf-package.seeall"></a><hr/><h3><code>package.seeall (module)</code></h3> |
| 4781 | | 4804 | |
| 4782 | <p>Sets a metatable for <code>module</code> with | 4805 | <p>Sets a metatable for <code>module</code> with |
| 4783 | its <code>__index</code> field refering to the global environment, | 4806 | its <code>__index</code> field refering to the global environment, |
| @@ -4803,7 +4826,7 @@ Therefore, you can use the string function is object-oriented style. · 19 unmodified lines |
| 4803 | For instance, <code>string.byte(s, i)</code> | 4826 | For instance, <code>string.byte(s, i)</code> |
| 4804 | can be written as <code>s:byte(i)</code>. | 4827 | can be written as <code>s:byte(i)</code>. |
| 4805 | | 4828 | |
| 4806 | <p><a name="pdf-string.byte"></a><hr><h3><code>string.byte (s [, i [, j]])</code></h3> | 4829 | <p><a name="pdf-string.byte"></a><hr/><h3><code>string.byte (s [, i [, j]])</code></h3> |
| 4807 | Returns the internal numerical codes of the characters <code>s[i]</code>, | 4830 | Returns the internal numerical codes of the characters <code>s[i]</code>, |
| 4808 | <code>s[i+1]</code>, ..., <code>s[j]</code>. | 4831 | <code>s[i+1]</code>, ..., <code>s[j]</code>. |
| 4809 | The default value for <code>i</code> is 1; | 4832 | The default value for <code>i</code> is 1; |
| @@ -4811,7 +4834,7 @@ the default value for <code>j</code> is <code>i</code>. · 1 unmodified line |
| 4811 | | 4834 | |
| 4812 | <p>Note that numerical codes are not necessarily portable across platforms. | 4835 | <p>Note that numerical codes are not necessarily portable across platforms. |
| 4813 | | 4836 | |
| 4814 | <p><a name="pdf-string.char"></a><hr><h3><code>string.char (i1, i2, ...)</code></h3> | 4837 | <p><a name="pdf-string.char"></a><hr/><h3><code>string.char (i1, i2, ...)</code></h3> |
| 4815 | Receives 0 or more integers. | 4838 | Receives 0 or more integers. |
| 4816 | Returns a string with length equal to the number of arguments, | 4839 | Returns a string with length equal to the number of arguments, |
| 4817 | in which each character has the internal numerical code equal | 4840 | in which each character has the internal numerical code equal |
| @@ -4819,29 +4842,34 @@ to its correspondent argument. · 1 unmodified line |
| 4819 | | 4842 | |
| 4820 | <p>Note that numerical codes are not necessarily portable across platforms. | 4843 | <p>Note that numerical codes are not necessarily portable across platforms. |
| 4821 | | 4844 | |
| 4822 | <p><a name="pdf-string.dump"></a><hr><h3><code>string.dump (function)</code></h3> | 4845 | <p><a name="pdf-string.dump"></a><hr/><h3><code>string.dump (function)</code></h3> |
| 4823 | | 4846 | |
| 4824 | <p>Returns a binary representation of the given function, | 4847 | <p>Returns a binary representation of the given function, |
| 4825 | so that a later <a href="#pdf-loadstring"><code>loadstring</code></a> on that string returns | 4848 | so that a later <a href="#pdf-loadstring"><code>loadstring</code></a> on that string returns |
| 4826 | a copy of the function. | 4849 | a copy of the function. |
| 4827 | <code>function</code> must be a Lua function. | 4850 | <code>function</code> must be a Lua function. |
| 4828 | | 4851 | |
| 4829 | <p><a name="pdf-string.find"></a><hr><h3><code>string.find (s, pattern [, init [, plain]])</code></h3> | 4852 | <p><a name="pdf-string.find"></a><hr/><h3><code>string.find (s, pattern [, init [, plain]])</code></h3> |
| 4830 | Looks for the first <em>match</em> of | 4853 | Looks for the first <em>match</em> of |
| 4831 | <code>pattern</code> in the string <code>s</code>. | 4854 | <code>pattern</code> in the string <code>s</code>. |
| 4832 | If it finds one, then <code>find</code> returns the indices of <code>s</code> | 4855 | If it finds one, then <code>find</code> returns the indices of <code>s</code> |
| 4833 | where this occurrence starts and ends; | 4856 | where this occurrence starts and ends; |
| 4834 | otherwise, it returns <B>nil</B>. | 4857 | otherwise, it returns <b>nil</b>. |
| 4835 | A third, optional numerical argument <code>init</code> specifies | 4858 | A third, optional numerical argument <code>init</code> specifies |
| 4836 | where to start the search; | 4859 | where to start the search; |
| 4837 | its default value is 1 and may be negative. | 4860 | its default value is 1 and may be negative. |
| 4838 | A value of <B>true</B> as a fourth, optional argument <code>plain</code> | 4861 | A value of <b>true</b> as a fourth, optional argument <code>plain</code> |
| 4839 | turns off the pattern matching facilities, | 4862 | turns off the pattern matching facilities, |
| 4840 | so the function does a plain "find substring" operation, | 4863 | so the function does a plain "find substring" operation, |
| 4841 | with no characters in <code>pattern</code> being considered "magic". | 4864 | with no characters in <code>pattern</code> being considered "magic". |
| 4842 | Note that if <code>plain</code> is given, then <code>init</code> must be given too. | 4865 | Note that if <code>plain</code> is given, then <code>init</code> must be given too. |
| 4843 | | 4866 | |
| 4844 | <p><a name="format"></a><a name="pdf-string.format"></a><hr><h3><code>string.format (formatstring, e1, e2, ...)</code></h3> | 4867 | <p>If the pattern has captures, |
| | 4868 | then in a successful match |
| | 4869 | the captured values are also returned, |
| | 4870 | after the two indices. |
| | 4871 | |
| | 4872 | <p><a name="format"></a><a name="pdf-string.format"></a><hr/><h3><code>string.format (formatstring, e1, e2, ...)</code></h3> |
| 4845 | Returns a formatted version of its variable number of arguments | 4873 | Returns a formatted version of its variable number of arguments |
| 4846 | following the description given in its first argument (which must be a string). | 4874 | following the description given in its first argument (which must be a string). |
| 4847 | The format string follows the same rules as the <code>printf</code> family of | 4875 | The format string follows the same rules as the <code>printf</code> family of |
| @@ -4856,14 +4884,14 @@ The string is written between double quotes, · 8 unmodified lines |
| 4856 | and all double quotes, newlines, and backslashes in the string | 4884 | and all double quotes, newlines, and backslashes in the string |
| 4857 | are correctly escaped when written. | 4885 | are correctly escaped when written. |
| 4858 | For instance, the call | 4886 | For instance, the call |
| 4859 | <PRE> | 4887 | <pre> |
| 4860 | string.format('%q', 'a string with "quotes" and \n new line') | 4888 | string.format('%q', 'a string with "quotes" and \n new line') |
| 4861 | </PRE> | 4889 | </pre> |
| 4862 | will produce the string: | 4890 | will produce the string: |
| 4863 | <PRE> | 4891 | <pre> |
| 4864 | "a string with \"quotes\" and \ | 4892 | "a string with \"quotes\" and \ |
| 4865 | new line" | 4893 | new line" |
| 4866 | </PRE> | 4894 | </pre> |
| 4867 | | 4895 | |
| 4868 | <p>The options <code>c</code>, <code>d</code>, <code>E</code>, <code>e</code>, <code>f</code>, | 4896 | <p>The options <code>c</code>, <code>d</code>, <code>E</code>, <code>e</code>, <code>f</code>, |
| 4869 | <code>g</code>, <code>G</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code> all | 4897 | <code>g</code>, <code>G</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>X</code>, and <code>x</code> all |
| @@ -4873,7 +4901,7 @@ whereas <code>q</code> and <code>s</code> expect a string. · 3 unmodified lines |
| 4873 | <p>This function does not accept string values | 4901 | <p>This function does not accept string values |
| 4874 | containing embedded zeros. | 4902 | containing embedded zeros. |
| 4875 | | 4903 | |
| 4876 | <p><a name="pdf-string.gmatch"></a><hr><h3><code>string.gmatch (s, pat)</code></h3> | 4904 | <p><a name="pdf-string.gmatch"></a><hr/><h3><code>string.gmatch (s, pat)</code></h3> |
| 4877 | Returns an iterator function that, | 4905 | Returns an iterator function that, |
| 4878 | each time it is called, | 4906 | each time it is called, |
| 4879 | returns the next captures from pattern <code>pat</code> over string <code>s</code>. | 4907 | returns the next captures from pattern <code>pat</code> over string <code>s</code>. |
| @@ -4882,25 +4910,25 @@ returns the next captures from pattern <code>pat</code> over string <code>s</cod · 2 unmodified lines |
| 4882 | then the whole match is produced in each call. | 4910 | then the whole match is produced in each call. |
| 4883 | | 4911 | |
| 4884 | <p>As an example, the following loop | 4912 | <p>As an example, the following loop |
| 4885 | <PRE> | 4913 | <pre> |
| 4886 | s = "hello world from Lua" | 4914 | s = "hello world from Lua" |
| 4887 | for w in string.gmatch(s, "%a+") do | 4915 | for w in string.gmatch(s, "%a+") do |
| 4888 | print(w) | 4916 | print(w) |
| 4889 | end | 4917 | end |
| 4890 | </PRE> | 4918 | </pre> |
| 4891 | will iterate over all the words from string <code>s</code>, | 4919 | will iterate over all the words from string <code>s</code>, |
| 4892 | printing one per line. | 4920 | printing one per line. |
| 4893 | The next example collects all pairs <code>key=value</code> from the | 4921 | The next example collects all pairs <code>key=value</code> from the |
| 4894 | given string into a table: | 4922 | given string into a table: |
| 4895 | <PRE> | 4923 | <pre> |
| 4896 | t = {} | 4924 | t = {} |
| 4897 | s = "from=world, to=Lua" | 4925 | s = "from=world, to=Lua" |
| 4898 | for k, v in string.gmatch(s, "(%w+)=(%w+)") do | 4926 | for k, v in string.gmatch(s, "(%w+)=(%w+)") do |
| 4899 | t[k] = v | 4927 | t[k] = v |
| 4900 | end | 4928 | end |
| 4901 | </PRE> | 4929 | </pre> |
| 4902 | | 4930 | |
| 4903 | <p><a name="pdf-string.gsub"></a><hr><h3><code>string.gsub (s, pat, repl [, n])</code></h3> | 4931 | <p><a name="pdf-string.gsub"></a><hr/><h3><code>string.gsub (s, pat, repl [, n])</code></h3> |
| 4904 | Returns a copy of <code>s</code> | 4932 | Returns a copy of <code>s</code> |
| 4905 | in which all occurrences of the pattern <code>pat</code> have been | 4933 | in which all occurrences of the pattern <code>pat</code> have been |
| 4906 | replaced by a replacement string specified by <code>repl</code>. | 4934 | replaced by a replacement string specified by <code>repl</code>. |
| @@ -4920,9 +4948,16 @@ match occurs, with all captured substrings passed as arguments, · 13 unmodified lines |
| 4920 | in order; | 4948 | in order; |
| 4921 | if the pattern specifies no captures, | 4949 | if the pattern specifies no captures, |
| 4922 | then the whole match is passed as a sole argument. | 4950 | then the whole match is passed as a sole argument. |
| 4923 | If the value returned by this function is a string, | 4951 | If <code>repl</code> is a table, then this table is queried with the |
| | 4952 | value of the first capture or of the whole match, |
| | 4953 | if the pattern specifies no captures. |
| | 4954 | In both cases, |
| | 4955 | if the value returned by the function or resulted by the query |
| | 4956 | is a string, |
| 4924 | then it is used as the replacement string; | 4957 | then it is used as the replacement string; |
| 4925 | otherwise, the replacement string is the empty string. | 4958 | otherwise, if it is <b>false</b> or <b>nil</b>, |
| | 4959 | then there is no replacement |
| | 4960 | (that is, the original match is kept in the string). |
| 4926 | | 4961 | |
| 4927 | <p>The optional last parameter <code>n</code> limits | 4962 | <p>The optional last parameter <code>n</code> limits |
| 4928 | the maximum number of substitutions to occur. | 4963 | the maximum number of substitutions to occur. |
| @@ -4930,7 +4965,7 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 1 unmodified line |
| 4930 | <code>pat</code> is replaced. | 4965 | <code>pat</code> is replaced. |
| 4931 | | 4966 | |
| 4932 | <p>Here are some examples: | 4967 | <p>Here are some examples: |
| 4933 | <PRE> | 4968 | <pre> |
| 4934 | x = string.gsub("hello world", "(%w+)", "%1 %1") | 4969 | x = string.gsub("hello world", "(%w+)", "%1 %1") |
| 4935 | --> x="hello hello world world" | 4970 | --> x="hello hello world world" |
| 4936 | | 4971 | |
| @@ -4949,44 +4984,42 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 12 unmodified lines |
| 4949 | --> x="4+5 = 9" | 4984 | --> x="4+5 = 9" |
| 4950 | | 4985 | |
| 4951 | local t = {name="lua", version="5.0"} | 4986 | local t = {name="lua", version="5.0"} |
| 4952 | x = string.gsub("$name_$version.tar.gz", "%$(%w+)", function (v) | 4987 | x = string.gsub("$name_$version.tar.gz", "%$(%w+)", t) |
| 4953 | return t[v] | | |
| 4954 | end) | | |
| 4955 | --> x="lua_5.0.tar.gz" | 4988 | --> x="lua_5.0.tar.gz" |
| 4956 | </PRE> | 4989 | </pre> |
| 4957 | | 4990 | |
| 4958 | <p><a name="pdf-string.len"></a><hr><h3><code>string.len (s)</code></h3> | 4991 | <p><a name="pdf-string.len"></a><hr/><h3><code>string.len (s)</code></h3> |
| 4959 | Receives a string and returns its length. | 4992 | Receives a string and returns its length. |
| 4960 | The empty string <code>""</code> has length 0. | 4993 | The empty string <code>""</code> has length 0. |
| 4961 | Embedded zeros are counted, | 4994 | Embedded zeros are counted, |
| 4962 | so <code>"a\000bc\000"</code> has length 5. | 4995 | so <code>"a\000bc\000"</code> has length 5. |
| 4963 | | 4996 | |
| 4964 | <p><a name="pdf-string.lower"></a><hr><h3><code>string.lower (s)</code></h3> | 4997 | <p><a name="pdf-string.lower"></a><hr/><h3><code>string.lower (s)</code></h3> |
| 4965 | Receives a string and returns a copy of that string with all | 4998 | Receives a string and returns a copy of that string with all |
| 4966 | uppercase letters changed to lowercase. | 4999 | uppercase letters changed to lowercase. |
| 4967 | All other characters are left unchanged. | 5000 | All other characters are left unchanged. |
| 4968 | The definition of what is an uppercase letter depends on the current locale. | 5001 | The definition of what is an uppercase letter depends on the current locale. |
| 4969 | | 5002 | |
| 4970 | <p><a name="pdf-string.match"></a><hr><h3><code>string.match (s, pattern [, init])</code></h3> | 5003 | <p><a name="pdf-string.match"></a><hr/><h3><code>string.match (s, pattern [, init])</code></h3> |
| 4971 | Looks for the first <em>match</em> of | 5004 | Looks for the first <em>match</em> of |
| 4972 | <code>pattern</code> in the string <code>s</code>. | 5005 | <code>pattern</code> in the string <code>s</code>. |
| 4973 | If it finds one, then <code>match</code> returns | 5006 | If it finds one, then <code>match</code> returns |
| 4974 | the captures from the pattern; | 5007 | the captures from the pattern; |
| 4975 | otherwise it returns <B>nil</B>. | 5008 | otherwise it returns <b>nil</b>. |
| 4976 | If <code>pattern</code> specifies no captures, | 5009 | If <code>pattern</code> specifies no captures, |
| 4977 | then the whole match is returned. | 5010 | then the whole match is returned. |
| 4978 | A third, optional numerical argument <code>init</code> specifies | 5011 | A third, optional numerical argument <code>init</code> specifies |
| 4979 | where to start the search; | 5012 | where to start the search; |
| 4980 | its default value is 1 and may be negative. | 5013 | its default value is 1 and may be negative. |
| 4981 | | 5014 | |
| 4982 | <p><a name="pdf-string.rep"></a><hr><h3><code>string.rep (s, n)</code></h3> | 5015 | <p><a name="pdf-string.rep"></a><hr/><h3><code>string.rep (s, n)</code></h3> |
| 4983 | Returns a string that is the concatenation of <code>n</code> copies of | 5016 | Returns a string that is the concatenation of <code>n</code> copies of |
| 4984 | the string <code>s</code>. | 5017 | the string <code>s</code>. |
| 4985 | | 5018 | |
| 4986 | <p><a name="pdf-string.reverse"></a><hr><h3><code>string.reverse (s)</code></h3> | 5019 | <p><a name="pdf-string.reverse"></a><hr/><h3><code>string.reverse (s)</code></h3> |
| 4987 | Returns a string that is the string <code>s</code> reversed. | 5020 | Returns a string that is the string <code>s</code> reversed. |
| 4988 | | 5021 | |
| 4989 | <p><a name="pdf-string.sub"></a><hr><h3><code>string.sub (s, i [, j])</code></h3> | 5022 | <p><a name="pdf-string.sub"></a><hr/><h3><code>string.sub (s, i [, j])</code></h3> |
| 4990 | Returns the substring of <code>s</code> that | 5023 | Returns the substring of <code>s</code> that |
| 4991 | starts at <code>i</code> and continues until <code>j</code>; | 5024 | starts at <code>i</code> and continues until <code>j</code>; |
| 4992 | <code>i</code> and <code>j</code> may be negative. | 5025 | <code>i</code> and <code>j</code> may be negative. |
| @@ -4998,7 +5031,7 @@ with length <code>j</code>, · 5 unmodified lines |
| 4998 | and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code> | 5031 | and <code>string.sub(s, -i)</code> returns a suffix of <code>s</code> |
| 4999 | with length <code>i</code>. | 5032 | with length <code>i</code>. |
| 5000 | | 5033 | |
| 5001 | <p><a name="pdf-string.upper"></a><hr><h3><code>string.upper (s)</code></h3> | 5034 | <p><a name="pdf-string.upper"></a><hr/><h3><code>string.upper (s)</code></h3> |
| 5002 | Receives a string and returns a copy of that string with all | 5035 | Receives a string and returns a copy of that string with all |
| 5003 | lowercase letters changed to uppercase. | 5036 | lowercase letters changed to uppercase. |
| 5004 | All other characters are left unchanged. | 5037 | All other characters are left unchanged. |
| @@ -5012,26 +5045,26 @@ The following combinations are allowed in describing a character class: · 7 unmodified lines |
| 5012 | <ul> | 5045 | <ul> |
| 5013 | <li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters | 5046 | <li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters |
| 5014 | <code>^$()%.[]*+-?</code>) | 5047 | <code>^$()%.[]*+-?</code>) |
| 5015 | — represents the character <em>x</em> itself. | 5048 | --- represents the character <em>x</em> itself. |
| 5016 | <li><b><code>.</code></b> — (a dot) represents all characters. | 5049 | <li><b><code>.</code></b> --- (a dot) represents all characters. |
| 5017 | <li><b><code>%a</code></b> — represents all letters. | 5050 | <li><b><code>%a</code></b> --- represents all letters. |
| 5018 | <li><b><code>%c</code></b> — represents all control characters. | 5051 | <li><b><code>%c</code></b> --- represents all control characters. |
| 5019 | <li><b><code>%d</code></b> — represents all digits. | 5052 | <li><b><code>%d</code></b> --- represents all digits. |
| 5020 | <li><b><code>%l</code></b> — represents all lowercase letters. | 5053 | <li><b><code>%l</code></b> --- represents all lowercase letters. |
| 5021 | <li><b><code>%p</code></b> — represents all punctuation characters. | 5054 | <li><b><code>%p</code></b> --- represents all punctuation characters. |
| 5022 | <li><b><code>%s</code></b> — represents all space characters. | 5055 | <li><b><code>%s</code></b> --- represents all space characters. |
| 5023 | <li><b><code>%u</code></b> — represents all uppercase letters. | 5056 | <li><b><code>%u</code></b> --- represents all uppercase letters. |
| 5024 | <li><b><code>%w</code></b> — represents all alphanumeric characters. | 5057 | <li><b><code>%w</code></b> --- represents all alphanumeric characters. |
| 5025 | <li><b><code>%x</code></b> — represents all hexadecimal digits. | 5058 | <li><b><code>%x</code></b> --- represents all hexadecimal digits. |
| 5026 | <li><b><code>%z</code></b> — represents the character with representation 0. | 5059 | <li><b><code>%z</code></b> --- represents the character with representation 0. |
| 5027 | <li><b><code>%<em>x</em></code></b> (where <em>x</em> is any non-alphanumeric character) — | 5060 | <li><b><code>%<em>x</em></code></b> (where <em>x</em> is any non-alphanumeric character) --- |
| 5028 | represents the character <em>x</em>. | 5061 | represents the character <em>x</em>. |
| 5029 | This is the standard way to escape the magic characters. | 5062 | This is the standard way to escape the magic characters. |
| 5030 | Any punctuation character (even the non magic) | 5063 | Any punctuation character (even the non magic) |
| 5031 | can be preceded by a `<code>%</code>´ | 5064 | can be preceded by a `<code>%</code>´ |
| 5032 | when used to represent itself in a pattern. | 5065 | when used to represent itself in a pattern. |
| 5033 | | 5066 | |
| 5034 | <p><li><b><code>[<em>set</em>]</code></b> — | 5067 | <p><li><b><code>[<em>set</em>]</code></b> --- |
| 5035 | represents the class which is the union of all | 5068 | represents the class which is the union of all |
| 5036 | characters in <em>set</em>. | 5069 | characters in <em>set</em>. |
| 5037 | A range of characters may be specified by | 5070 | A range of characters may be specified by |
| @@ -5049,7 +5082,7 @@ the lowercase letters plus the `<code>-</code>´ character. · 11 unmodified lines |
| 5049 | Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code> | 5082 | Therefore, patterns like <code>[%a-z]</code> or <code>[a-%%]</code> |
| 5050 | have no meaning. | 5083 | have no meaning. |
| 5051 | | 5084 | |
| 5052 | <p><li><b><code>[^<em>set</em>]</code></b> — | 5085 | <p><li><b><code>[^<em>set</em>]</code></b> --- |
| 5053 | represents the complement of <em>set</em>, | 5086 | represents the complement of <em>set</em>, |
| 5054 | where <em>set</em> is interpreted as above. | 5087 | where <em>set</em> is interpreted as above. |
| 5055 | </ul> | 5088 | </ul> |
| @@ -5135,30 +5168,14 @@ represents an array or a list. · 79 unmodified lines |
| 5135 | For those functions, when we talk about "the length" of a table | 5168 | For those functions, when we talk about "the length" of a table |
| 5136 | we mean the result of the length operator. | 5169 | we mean the result of the length operator. |
| 5137 | | 5170 | |
| 5138 | <p><a name="pdf-table.concat"></a><hr><h3><code>table.concat (table [, sep [, i [, j]]])</code></h3> | 5171 | <p><a name="pdf-table.concat"></a><hr/><h3><code>table.concat (table [, sep [, i [, j]]])</code></h3> |
| 5139 | Returns <code>table[i]..sep..table[i+1] ... sep..table[j]</code>. | 5172 | Returns <code>table[i]..sep..table[i+1] ... sep..table[j]</code>. |
| 5140 | The default value for <code>sep</code> is the empty string, | 5173 | The default value for <code>sep</code> is the empty string, |
| 5141 | the default for <code>i</code> is 1, | 5174 | the default for <code>i</code> is 1, |
| 5142 | and the default for <code>j</code> is the length of the table. | 5175 | and the default for <code>j</code> is the length of the table. |
| 5143 | If <code>i</code> is greater than <code>j</code>, returns the empty string. | 5176 | If <code>i</code> is greater than <code>j</code>, returns the empty string. |
| 5144 | | 5177 | |
| 5145 | <p><a name="pdf-table.sort"></a><hr><h3><code>table.sort (table [, comp])</code></h3> | 5178 | <p><a name="pdf-table.insert"></a><hr/><h3><code>table.insert (table, [pos,] value)</code></h3> |
| 5146 | Sorts table elements in a given order, <em>in-place</em>, | | |
| 5147 | from <code>table[1]</code> to <code>table[n]</code>, | | |
| 5148 | where <code>n</code> is the length of the table. | | |
| 5149 | If <code>comp</code> is given, | | |
| 5150 | then it must be a function that receives two table elements, | | |
| 5151 | and returns true | | |
| 5152 | when the first is less than the second | | |
| 5153 | (so that <code>not comp(a[i+1],a[i])</code> will be true after the sort). | | |
| 5154 | If <code>comp</code> is not given, | | |
| 5155 | then the standard Lua operator <code><</code> is used instead. | | |
| 5156 | | | |
| 5157 | <p>The sort algorithm is not stable, | | |
| 5158 | that is, elements considered equal by the given order | | |
| 5159 | may have their relative positions changed by the sort. | | |
| 5160 | | | |
| 5161 | <p><a name="pdf-table.insert"></a><hr><h3><code>table.insert (table, [pos,] value)</code></h3> | | |
| 5162 | | 5179 | |
| 5163 | <p>Inserts element <code>value</code> at position <code>pos</code> in <code>table</code>, | 5180 | <p>Inserts element <code>value</code> at position <code>pos</code> in <code>table</code>, |
| 5164 | shifting up other elements to open space, if necessary. | 5181 | shifting up other elements to open space, if necessary. |
| @@ -5167,7 +5184,12 @@ where <code>n</code> is the length of the table (see <a href="#len-op">2.5.5</a> · 2 unmodified lines |
| 5167 | so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end | 5184 | so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end |
| 5168 | of table <code>t</code>. | 5185 | of table <code>t</code>. |
| 5169 | | 5186 | |
| 5170 | <p><a name="pdf-table.remove"></a><hr><h3><code>table.remove (table [, pos])</code></h3> | 5187 | <p><a name="pdf-table.maxn(table)"></a><hr/><h3><code>table.maxn(table)</code></h3> |
| | 5188 | |
| | 5189 | <p>Returns the largest positive numerical index of the given table, |
| | 5190 | or zero if the table has no positive numerical indices. |
| | 5191 | |
| | 5192 | <p><a name="pdf-table.remove"></a><hr/><h3><code>table.remove (table [, pos])</code></h3> |
| 5171 | | 5193 | |
| 5172 | <p>Removes from <code>table</code> the element at position <code>pos</code>, | 5194 | <p>Removes from <code>table</code> the element at position <code>pos</code>, |
| 5173 | shifting down other elements to close the space, if necessary. | 5195 | shifting down other elements to close the space, if necessary. |
| @@ -5177,26 +5199,42 @@ where <code>n</code> is the length of the table, · 3 unmodified lines |
| 5177 | so that a call <code>table.remove(t)</code> removes the last element | 5199 | so that a call <code>table.remove(t)</code> removes the last element |
| 5178 | of table <code>t</code>. | 5200 | of table <code>t</code>. |
| 5179 | | 5201 | |
| | 5202 | <p><a name="pdf-table.sort"></a><hr/><h3><code>table.sort (table [, comp])</code></h3> |
| | 5203 | Sorts table elements in a given order, <em>in-place</em>, |
| | 5204 | from <code>table[1]</code> to <code>table[n]</code>, |
| | 5205 | where <code>n</code> is the length of the table. |
| | 5206 | If <code>comp</code> is given, |
| | 5207 | then it must be a function that receives two table elements, |
| | 5208 | and returns true |
| | 5209 | when the first is less than the second |
| | 5210 | (so that <code>not comp(a[i+1],a[i])</code> will be true after the sort). |
| | 5211 | If <code>comp</code> is not given, |
| | 5212 | then the standard Lua operator <code><</code> is used instead. |
| | 5213 | |
| | 5214 | <p>The sort algorithm is not stable, |
| | 5215 | that is, elements considered equal by the given order |
| | 5216 | may have their relative positions changed by the sort. |
| | 5217 | |
| 5180 | <p><a name="mathlib"></a><a name="5.6"></a><h2>5.6 - Mathematical Functions</h2> | 5218 | <p><a name="mathlib"></a><a name="5.6"></a><h2>5.6 - Mathematical Functions</h2> |
| 5181 | | 5219 | |
| 5182 | <p>This library is an interface to the standard C math library. | 5220 | <p>This library is an interface to the standard C math library. |
| 5183 | It provides all its functions inside the table <code>math</code>. | 5221 | It provides all its functions inside the table <code>math</code>. |
| 5184 | The library provides the following functions: | 5222 | The library provides the following functions: |
| 5185 | | 5223 | <a name="pdf-math.abs"></a><a name="pdf-math.acos"></a><a name="pdf-math.asin"></a><a name="pdf-math.atan"></a> |
| 5186 | | 5224 | <a name="pdf-math.atan2"></a><a name="pdf-math.ceil"></a><a name="pdf-math.cos"></a><a name="pdf-math.cosh"></a> |
| 5187 | | 5225 | <a name="pdf-math.def"></a><a name="pdf-math.exp"></a> |
| 5188 | | 5226 | <a name="pdf-math.floor"></a><a name="pdf-math.log"></a><a name="pdf-math.log10"></a> |
| 5189 | | 5227 | <a name="pdf-math.fmod"></a><a name="pdf-math.pow"></a><a name="pdf-math.sin"></a> |
| 5190 | | 5228 | <a name="pdf-math.sqrt"></a><a name="pdf-math.tan"></a><a name="pdf-math.ldexp"></a> |
| 5191 | | 5229 | <a name="pdf-math.sinh"></a><a name="pdf-math.tanh"></a> |
| 5192 | <PRE> | 5230 | <pre> |
| 5193 | math.abs math.acos math.asin math.atan math.atan2 | 5231 | math.abs math.acos math.asin math.atan math.atan2 |
| 5194 | math.ceil math.cosh math.cos math.deg math.exp | 5232 | math.ceil math.cosh math.cos math.deg math.exp |
| 5195 | math.floor math.fmod math.frexp math.ldexp math.log | 5233 | math.floor math.fmod math.frexp math.ldexp math.log |
| 5196 | math.log10 math.max math.min math.modf math.pow | 5234 | math.log10 math.max math.min math.modf math.pow |
| 5197 | math.rad math.random math.randomseed math.sin | 5235 | math.rad math.random math.randomseed math.sin |
| 5198 | math.sinh math.sqrt math.tan math.tanh | 5236 | math.sinh math.sqrt math.tan math.tanh |
| 5199 | </PRE> | 5237 | </pre> |
| 5200 | plus a variable <code>math.pi</code> and | 5238 | plus a variable <code>math.pi</code> and |
| 5201 | a variable <code>math.huge</code>, | 5239 | a variable <code>math.huge</code>, |
| 5202 | with the value <code>HUGE_VAL</code>. | 5240 | with the value <code>HUGE_VAL</code>. |
| @@ -5255,20 +5293,20 @@ three predefined file descriptors with their usual meanings from C: · 52 unmodified lines |
| 5255 | <code>io.stdin</code>, <code>io.stdout</code>, and <code>io.stderr</code>. | 5293 | <code>io.stdin</code>, <code>io.stdout</code>, and <code>io.stderr</code>. |
| 5256 | | 5294 | |
| 5257 | <p>Unless otherwise stated, | 5295 | <p>Unless otherwise stated, |
| 5258 | all I/O functions return <B>nil</B> on failure | 5296 | all I/O functions return <b>nil</b> on failure |
| 5259 | (plus an error message as a second result) | 5297 | (plus an error message as a second result) |
| 5260 | and some value different from <B>nil</B> on success. | 5298 | and some value different from <b>nil</b> on success. |
| 5261 | | 5299 | |
| 5262 | <p><a name="pdf-io.close"></a><hr><h3><code>io.close ([file])</code></h3> | 5300 | <p><a name="pdf-io.close"></a><hr/><h3><code>io.close ([file])</code></h3> |
| 5263 | | 5301 | |
| 5264 | <p>Equivalent to <code>file:close()</code>. | 5302 | <p>Equivalent to <code>file:close()</code>. |
| 5265 | Without a <code>file</code>, closes the default output file. | 5303 | Without a <code>file</code>, closes the default output file. |
| 5266 | | 5304 | |
| 5267 | <p><a name="pdf-io.flush"></a><hr><h3><code>io.flush ()</code></h3> | 5305 | <p><a name="pdf-io.flush"></a><hr/><h3><code>io.flush ()</code></h3> |
| 5268 | | 5306 | |
| 5269 | <p>Equivalent to <code>file:flush</code> over the default output file. | 5307 | <p>Equivalent to <code>file:flush</code> over the default output file. |
| 5270 | | 5308 | |
| 5271 | <p><a name="pdf-io.input"></a><hr><h3><code>io.input ([file])</code></h3> | 5309 | <p><a name="pdf-io.input"></a><hr/><h3><code>io.input ([file])</code></h3> |
| 5272 | | 5310 | |
| 5273 | <p>When called with a file name, it opens the named file (in text mode), | 5311 | <p>When called with a file name, it opens the named file (in text mode), |
| 5274 | and sets its handle as the default input file. | 5312 | and sets its handle as the default input file. |
| @@ -5280,31 +5318,31 @@ it returns the current default input file. · 5 unmodified lines |
| 5280 | <p>In case of errors this function raises the error, | 5318 | <p>In case of errors this function raises the error, |
| 5281 | instead of returning an error code. | 5319 | instead of returning an error code. |
| 5282 | | 5320 | |
| 5283 | <p><a name="pdf-io.lines"></a><hr><h3><code>io.lines ([filename])</code></h3> | 5321 | <p><a name="pdf-io.lines"></a><hr/><h3><code>io.lines ([filename])</code></h3> |
| 5284 | | 5322 | |
| 5285 | <p>Opens the given file name in read mode | 5323 | <p>Opens the given file name in read mode |
| 5286 | and returns an iterator function that, | 5324 | and returns an iterator function that, |
| 5287 | each time it is called, | 5325 | each time it is called, |
| 5288 | returns a new line from the file. | 5326 | returns a new line from the file. |
| 5289 | Therefore, the construction | 5327 | Therefore, the construction |
| 5290 | <PRE> | 5328 | <pre> |
| 5291 | for line in io.lines(filename) do ... end | 5329 | for line in io.lines(filename) do ... end |
| 5292 | </PRE> | 5330 | </pre> |
| 5293 | will iterate over all lines of the file. | 5331 | will iterate over all lines of the file. |
| 5294 | When the iterator function detects the end of file, | 5332 | When the iterator function detects the end of file, |
| 5295 | it returns <B>nil</B> (to finish the loop) and automatically closes the file. | 5333 | it returns <b>nil</b> (to finish the loop) and automatically closes the file. |
| 5296 | | 5334 | |
| 5297 | <p>The call <code>io.lines()</code> (without a file name) is equivalent | 5335 | <p>The call <code>io.lines()</code> (without a file name) is equivalent |
| 5298 | to <code>io.input():lines()</code>, that is, it iterates over the | 5336 | to <code>io.input():lines()</code>, that is, it iterates over the |
| 5299 | lines of the default input file. | 5337 | lines of the default input file. |
| 5300 | In that case it does not close the file when the loop ends. | 5338 | In that case it does not close the file when the loop ends. |
| 5301 | | 5339 | |
| 5302 | <p><a name="pdf-io.open"></a><hr><h3><code>io.open (filename [, mode])</code></h3> | 5340 | <p><a name="pdf-io.open"></a><hr/><h3><code>io.open (filename [, mode])</code></h3> |
| 5303 | | 5341 | |
| 5304 | <p>This function opens a file, | 5342 | <p>This function opens a file, |
| 5305 | in the mode specified in the string <code>mode</code>. | 5343 | in the mode specified in the string <code>mode</code>. |
| 5306 | It returns a new file handle, | 5344 | It returns a new file handle, |
| 5307 | or, in case of errors, <B>nil</B> plus an error message. | 5345 | or, in case of errors, <b>nil</b> plus an error message. |
| 5308 | | 5346 | |
| 5309 | <p>The <code>mode</code> string can be any of the following: | 5347 | <p>The <code>mode</code> string can be any of the following: |
| 5310 | <ul> | 5348 | <ul> |
| @@ -5321,11 +5359,11 @@ which is needed in some systems to open the file in binary mode. · 10 unmodified lines |
| 5321 | This string is exactly what is used in the | 5359 | This string is exactly what is used in the |
| 5322 | standard C function <code>fopen</code>. | 5360 | standard C function <code>fopen</code>. |
| 5323 | | 5361 | |
| 5324 | <p><a name="pdf-io.output"></a><hr><h3><code>io.output ([file])</code></h3> | 5362 | <p><a name="pdf-io.output"></a><hr/><h3><code>io.output ([file])</code></h3> |
| 5325 | | 5363 | |
| 5326 | <p>Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file. | 5364 | <p>Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over the default output file. |
| 5327 | | 5365 | |
| 5328 | <p><a name="pdf-io.popen"></a><hr><h3><code>io.popen ([prog [, mode]])</code></h3> | 5366 | <p><a name="pdf-io.popen"></a><hr/><h3><code>io.popen ([prog [, mode]])</code></h3> |
| 5329 | | 5367 | |
| 5330 | <p>Starts program <code>prog</code> in a separated process and returns | 5368 | <p>Starts program <code>prog</code> in a separated process and returns |
| 5331 | a file handle that you can use to read data from that program | 5369 | a file handle that you can use to read data from that program |
| @@ -5336,57 +5374,57 @@ or to write data to that program · 4 unmodified lines |
| 5336 | <p>This function is system dependent and is not available | 5374 | <p>This function is system dependent and is not available |
| 5337 | in all platforms. | 5375 | in all platforms. |
| 5338 | | 5376 | |
| 5339 | <p><a name="pdf-io.read"></a><hr><h3><code>io.read (format1, ...)</code></h3> | 5377 | <p><a name="pdf-io.read"></a><hr/><h3><code>io.read (format1, ...)</code></h3> |
| 5340 | | 5378 | |
| 5341 | <p>Equivalent to <code>io.input():read</code>. | 5379 | <p>Equivalent to <code>io.input():read</code>. |
| 5342 | | 5380 | |
| 5343 | <p><a name="pdf-io.tmpfile"></a><hr><h3><code>io.tmpfile ()</code></h3> | 5381 | <p><a name="pdf-io.tmpfile"></a><hr/><h3><code>io.tmpfile ()</code></h3> |
| 5344 | | 5382 | |
| 5345 | <p>Returns a handle for a temporary file. | 5383 | <p>Returns a handle for a temporary file. |
| 5346 | This file is open in update mode | 5384 | This file is open in update mode |
| 5347 | and it is automatically removed when the program ends. | 5385 | and it is automatically removed when the program ends. |
| 5348 | | 5386 | |
| 5349 | <p><a name="pdf-io.type"></a><hr><h3><code>io.type (obj)</code></h3> | 5387 | <p><a name="pdf-io.type"></a><hr/><h3><code>io.type (obj)</code></h3> |
| 5350 | | 5388 | |
| 5351 | <p>Checks whether <code>obj</code> is a valid file handle. | 5389 | <p>Checks whether <code>obj</code> is a valid file handle. |
| 5352 | Returns the string <code>"file"</code> if <code>obj</code> is an open file handle, | 5390 | Returns the string <code>"file"</code> if <code>obj</code> is an open file handle, |
| 5353 | <code>"closed file"</code> if <code>obj</code> is a closed file handle, | 5391 | <code>"closed file"</code> if <code>obj</code> is a closed file handle, |
| 5354 | and <B>nil</B> if <code>obj</code> is not a file handle. | 5392 | and <b>nil</b> if <code>obj</code> is not a file handle. |
| 5355 | | 5393 | |
| 5356 | <p><a name="pdf-io.write"></a><hr><h3><code>io.write (value1, ...)</code></h3> | 5394 | <p><a name="pdf-io.write"></a><hr/><h3><code>io.write (value1, ...)</code></h3> |
| 5357 | | 5395 | |
| 5358 | <p>Equivalent to <code>io.output():write</code>. | 5396 | <p>Equivalent to <code>io.output():write</code>. |
| 5359 | | 5397 | |
| 5360 | <p><a name="pdf-file:close"></a><hr><h3><code>file:close ()</code></h3> | 5398 | <p><a name="pdf-file:close"></a><hr/><h3><code>file:close ()</code></h3> |
| 5361 | | 5399 | |
| 5362 | <p>Closes <code>file</code>. | 5400 | <p>Closes <code>file</code>. |
| 5363 | Note that files are automatically closed when garbage collected, | 5401 | Note that files are automatically closed when garbage collected, |
| 5364 | but that takes an unpredictable time to happen. | 5402 | but that takes an unpredictable time to happen. |
| 5365 | | 5403 | |
| 5366 | <p><a name="flush"></a><a name="pdf-file:flush"></a><hr><h3><code>file:flush ()</code></h3> | 5404 | <p><a name="flush"></a><a name="pdf-file:flush"></a><hr/><h3><code>file:flush ()</code></h3> |
| 5367 | | 5405 | |
| 5368 | <p>Saves any written data to <code>file</code>. | 5406 | <p>Saves any written data to <code>file</code>. |
| 5369 | | 5407 | |
| 5370 | <p><a name="pdf-file:lines"></a><hr><h3><code>file:lines ()</code></h3> | 5408 | <p><a name="pdf-file:lines"></a><hr/><h3><code>file:lines ()</code></h3> |
| 5371 | | 5409 | |
| 5372 | <p>Returns an iterator function that, | 5410 | <p>Returns an iterator function that, |
| 5373 | each time it is called, | 5411 | each time it is called, |
| 5374 | returns a new line from the file. | 5412 | returns a new line from the file. |
| 5375 | Therefore, the construction | 5413 | Therefore, the construction |
| 5376 | <PRE> | 5414 | <pre> |
| 5377 | for line in file:lines() do ... end | 5415 | for line in file:lines() do ... end |
| 5378 | </PRE> | 5416 | </pre> |
| 5379 | will iterate over all lines of the file. | 5417 | will iterate over all lines of the file. |
| 5380 | (Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file | 5418 | (Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file |
| 5381 | when the loop ends.) | 5419 | when the loop ends.) |
| 5382 | | 5420 | |
| 5383 | <p><a name="pdf-file:read"></a><hr><h3><code>file:read (format1, ...)</code></h3> | 5421 | <p><a name="pdf-file:read"></a><hr/><h3><code>file:read (format1, ...)</code></h3> |
| 5384 | | 5422 | |
| 5385 | <p>Reads the file <code>file</code>, | 5423 | <p>Reads the file <code>file</code>, |
| 5386 | according to the given formats, which specify what to read. | 5424 | according to the given formats, which specify what to read. |
| 5387 | For each format, | 5425 | For each format, |
| 5388 | the function returns a string (or a number) with the characters read, | 5426 | the function returns a string (or a number) with the characters read, |
| 5389 | or <B>nil</B> if it cannot read data with the specified format. | 5427 | or <b>nil</b> if it cannot read data with the specified format. |
| 5390 | When called without formats, | 5428 | When called without formats, |
| 5391 | it uses a default format that reads the entire next line | 5429 | it uses a default format that reads the entire next line |
| 5392 | (see below). | 5430 | (see below). |
| @@ -5398,16 +5436,16 @@ this is the only format that returns a number instead of a string. · 5 unmodified lines |
| 5398 | <li><b>"*a"</b> reads the whole file, starting at the current position. | 5436 | <li><b>"*a"</b> reads the whole file, starting at the current position. |
| 5399 | On end of file, it returns the empty string. | 5437 | On end of file, it returns the empty string. |
| 5400 | <li><b>"*l"</b> reads the next line (skipping the end of line), | 5438 | <li><b>"*l"</b> reads the next line (skipping the end of line), |
| 5401 | returning <B>nil</B> on end of file. | 5439 | returning <b>nil</b> on end of file. |
| 5402 | This is the default format. | 5440 | This is the default format. |
| 5403 | <li><b><em>number</em></b> reads a string with up to that number of characters, | 5441 | <li><b><em>number</em></b> reads a string with up to that number of characters, |
| 5404 | returning <B>nil</B> on end of file. | 5442 | returning <b>nil</b> on end of file. |
| 5405 | If number is zero, | 5443 | If number is zero, |
| 5406 | it reads nothing and returns an empty string, | 5444 | it reads nothing and returns an empty string, |
| 5407 | or <B>nil</B> on end of file. | 5445 | or <b>nil</b> on end of file. |
| 5408 | </ul> | 5446 | </ul> |
| 5409 | | 5447 | |
| 5410 | <p><a name="pdf-file:seek"></a><hr><h3><code>file:seek ([whence] [, offset])</code></h3> | 5448 | <p><a name="pdf-file:seek"></a><hr/><h3><code>file:seek ([whence] [, offset])</code></h3> |
| 5411 | | 5449 | |
| 5412 | <p>Sets and gets the file position, | 5450 | <p>Sets and gets the file position, |
| 5413 | measured from the beginning of the file, | 5451 | measured from the beginning of the file, |
| @@ -5420,7 +5458,7 @@ specified by the string <code>whence</code>, as follows: · 6 unmodified lines |
| 5420 | </ul> | 5458 | </ul> |
| 5421 | In case of success, function <code>seek</code> returns the final file position, | 5459 | In case of success, function <code>seek</code> returns the final file position, |
| 5422 | measured in bytes from the beginning of the file. | 5460 | measured in bytes from the beginning of the file. |
| 5423 | If this function fails, it returns <B>nil</B>, | 5461 | If this function fails, it returns <b>nil</b>, |
| 5424 | plus a string describing the error. | 5462 | plus a string describing the error. |
| 5425 | | 5463 | |
| 5426 | <p>The default value for <code>whence</code> is <code>"cur"</code>, | 5464 | <p>The default value for <code>whence</code> is <code>"cur"</code>, |
| @@ -5432,7 +5470,7 @@ beginning of the file (and returns 0); · 5 unmodified lines |
| 5432 | and the call <code>file:seek("end")</code> sets the position to the | 5470 | and the call <code>file:seek("end")</code> sets the position to the |
| 5433 | end of the file, and returns its size. | 5471 | end of the file, and returns its size. |
| 5434 | | 5472 | |
| 5435 | <p><a name="pdf-file:setvbuf"></a><hr><h3><code>file:setvbuf (mode [, size])</code></h3> | 5473 | <p><a name="pdf-file:setvbuf"></a><hr/><h3><code>file:setvbuf (mode [, size])</code></h3> |
| 5436 | | 5474 | |
| 5437 | <p>Sets the buffering mode for an output file. | 5475 | <p>Sets the buffering mode for an output file. |
| 5438 | There are three available modes: | 5476 | There are three available modes: |
| @@ -5448,7 +5486,7 @@ For the last two cases, <code>sizes</code> · 9 unmodified lines |
| 5448 | specifies the size of the buffer, in bytes. | 5486 | specifies the size of the buffer, in bytes. |
| 5449 | The default is an appropriate size. | 5487 | The default is an appropriate size. |
| 5450 | | 5488 | |
| 5451 | <p><a name="pdf-file:write"></a><hr><h3><code>file:write (value1, ...)</code></h3> | 5489 | <p><a name="pdf-file:write"></a><hr/><h3><code>file:write (value1, ...)</code></h3> |
| 5452 | | 5490 | |
| 5453 | <p>Writes the value of each of its arguments to | 5491 | <p>Writes the value of each of its arguments to |
| 5454 | the filehandle <code>file</code>. | 5492 | the filehandle <code>file</code>. |
| @@ -5460,12 +5498,12 @@ use <a href="#pdf-tostring"><code>tostring</code></a> or <a href="#pdf-string.fo · 5 unmodified lines |
| 5460 | | 5498 | |
| 5461 | <p>This library is implemented through table <code>os</code>. | 5499 | <p>This library is implemented through table <code>os</code>. |
| 5462 | | 5500 | |
| 5463 | <p><a name="pdf-os.clock"></a><hr><h3><code>os.clock ()</code></h3> | 5501 | <p><a name="pdf-os.clock"></a><hr/><h3><code>os.clock ()</code></h3> |
| 5464 | | 5502 | |
| 5465 | <p>Returns an approximation of the amount of CPU time | 5503 | <p>Returns an approximation of the amount of CPU time |
| 5466 | used by the program, in seconds. | 5504 | used by the program, in seconds. |
| 5467 | | 5505 | |
| 5468 | <p><a name="pdf-os.date"></a><hr><h3><code>os.date ([format [, time]])</code></h3> | 5506 | <p><a name="pdf-os.date"></a><hr/><h3><code>os.date ([format [, time]])</code></h3> |
| 5469 | | 5507 | |
| 5470 | <p>Returns a string or a table containing date and time, | 5508 | <p>Returns a string or a table containing date and time, |
| 5471 | formatted according to the given string <code>format</code>. | 5509 | formatted according to the given string <code>format</code>. |
| @@ -5495,43 +5533,43 @@ formatted according to the same rules as the C function <code>strftime</code>. · 23 unmodified lines |
| 5495 | the host system and on the current locale | 5533 | the host system and on the current locale |
| 5496 | (that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>). | 5534 | (that is, <code>os.date()</code> is equivalent to <code>os.date("%c")</code>). |
| 5497 | | 5535 | |
| 5498 | <p><a name="pdf-os.difftime"></a><hr><h3><code>os.difftime (t2, t1)</code></h3> | 5536 | <p><a name="pdf-os.difftime"></a><hr/><h3><code>os.difftime (t2, t1)</code></h3> |
| 5499 | | 5537 | |
| 5500 | <p>Returns the number of seconds from time <code>t1</code> to time <code>t2</code>. | 5538 | <p>Returns the number of seconds from time <code>t1</code> to time <code>t2</code>. |
| 5501 | In Posix, Windows, and some other systems, | 5539 | In Posix, Windows, and some other systems, |
| 5502 | this value is exactly <code>t2</code><em>-</em><code>t1</code>. | 5540 | this value is exactly <code>t2</code><em>-</em><code>t1</code>. |
| 5503 | | 5541 | |
| 5504 | <p><a name="pdf-os.execute"></a><hr><h3><code>os.execute (command)</code></h3> | 5542 | <p><a name="pdf-os.execute"></a><hr/><h3><code>os.execute (command)</code></h3> |
| 5505 | | 5543 | |
| 5506 | <p>This function is equivalent to the C function <code>system</code>. | 5544 | <p>This function is equivalent to the C function <code>system</code>. |
| 5507 | It passes <code>command</code> to be executed by an operating system shell. | 5545 | It passes <code>command</code> to be executed by an operating system shell. |
| 5508 | It returns a status code, which is system-dependent. | 5546 | It returns a status code, which is system-dependent. |
| 5509 | | 5547 | |
| 5510 | <p><a name="pdf-os.exit"></a><hr><h3><code>os.exit ([code])</code></h3> | 5548 | <p><a name="pdf-os.exit"></a><hr/><h3><code>os.exit ([code])</code></h3> |
| 5511 | | 5549 | |
| 5512 | <p>Calls the C function <code>exit</code>, | 5550 | <p>Calls the C function <code>exit</code>, |
| 5513 | with an optional <code>code</code>, | 5551 | with an optional <code>code</code>, |
| 5514 | to terminate the host program. | 5552 | to terminate the host program. |
| 5515 | The default value for <code>code</code> is the success code. | 5553 | The default value for <code>code</code> is the success code. |
| 5516 | | 5554 | |
| 5517 | <p><a name="pdf-os.getenv"></a><hr><h3><code>os.getenv (varname)</code></h3> | 5555 | <p><a name="pdf-os.getenv"></a><hr/><h3><code>os.getenv (varname)</code></h3> |
| 5518 | | 5556 | |
| 5519 | <p>Returns the value of the process environment variable <code>varname</code>, | 5557 | <p>Returns the value of the process environment variable <code>varname</code>, |
| 5520 | or <B>nil</B> if the variable is not defined. | 5558 | or <b>nil</b> if the variable is not defined. |
| 5521 | | 5559 | |
| 5522 | <p><a name="pdf-os.remove"></a><hr><h3><code>os.remove (filename)</code></h3> | 5560 | <p><a name="pdf-os.remove"></a><hr/><h3><code>os.remove (filename)</code></h3> |
| 5523 | | 5561 | |
| 5524 | <p>Deletes the file with the given name. | 5562 | <p>Deletes the file with the given name. |
| 5525 | If this function fails, it returns <B>nil</B>, | 5563 | If this function fails, it returns <b>nil</b>, |
| 5526 | plus a string describing the error. | 5564 | plus a string describing the error. |
| 5527 | | 5565 | |
| 5528 | <p><a name="pdf-os.rename"></a><hr><h3><code>os.rename (oldname, newname)</code></h3> | 5566 | <p><a name="pdf-os.rename"></a><hr/><h3><code>os.rename (oldname, newname)</code></h3> |
| 5529 | | 5567 | |
| 5530 | <p>Renames file named <code>oldname</code> to <code>newname</code>. | 5568 | <p>Renames file named <code>oldname</code> to <code>newname</code>. |
| 5531 | If this function fails, it returns <B>nil</B>, | 5569 | If this function fails, it returns <b>nil</b>, |
| 5532 | plus a string describing the error. | 5570 | plus a string describing the error. |
| 5533 | | 5571 | |
| 5534 | <p><a name="pdf-os.setlocale"></a><hr><h3><code>os.setlocale (locale [, category])</code></h3> | 5572 | <p><a name="pdf-os.setlocale"></a><hr/><h3><code>os.setlocale (locale [, category])</code></h3> |
| 5535 | | 5573 | |
| 5536 | <p>Sets the current locale of the program. | 5574 | <p>Sets the current locale of the program. |
| 5537 | <code>locale</code> is a string specifying a locale; | 5575 | <code>locale</code> is a string specifying a locale; |
| @@ -5540,9 +5578,9 @@ plus a string describing the error. · 2 unmodified lines |
| 5540 | <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>; | 5578 | <code>"monetary"</code>, <code>"numeric"</code>, or <code>"time"</code>; |
| 5541 | the default category is <code>"all"</code>. | 5579 | the default category is <code>"all"</code>. |
| 5542 | The function returns the name of the new locale, | 5580 | The function returns the name of the new locale, |
| 5543 | or <B>nil</B> if the request cannot be honored. | 5581 | or <b>nil</b> if the request cannot be honored. |
| 5544 | | 5582 | |
| 5545 | <p><a name="pdf-os.time"></a><hr><h3><code>os.time ([table])</code></h3> | 5583 | <p><a name="pdf-os.time"></a><hr/><h3><code>os.time ([table])</code></h3> |
| 5546 | | 5584 | |
| 5547 | <p>Returns the current time when called without arguments, | 5585 | <p>Returns the current time when called without arguments, |
| 5548 | or a time representing the date and time specified by the given table. | 5586 | or a time representing the date and time specified by the given table. |
| @@ -5557,7 +5595,7 @@ In other systems, the meaning is not specified, · 8 unmodified lines |
| 5557 | and the number returned by <code>time</code> can be used only as an argument to | 5595 | and the number returned by <code>time</code> can be used only as an argument to |
| 5558 | <code>date</code> and <code>difftime</code>. | 5596 | <code>date</code> and <code>difftime</code>. |
| 5559 | | 5597 | |
| 5560 | <p><a name="pdf-os.tmpname"></a><hr><h3><code>os.tmpname ()</code></h3> | 5598 | <p><a name="pdf-os.tmpname"></a><hr/><h3><code>os.tmpname ()</code></h3> |
| 5561 | | 5599 | |
| 5562 | <p>Returns a string with a file name that can | 5600 | <p>Returns a string with a file name that can |
| 5563 | be used for a temporary file. | 5601 | be used for a temporary file. |
| @@ -5583,7 +5621,7 @@ and therefore can compromise some otherwise secure code. · 19 unmodified lines |
| 5583 | <p>All functions in this library are provided | 5621 | <p>All functions in this library are provided |
| 5584 | inside a <code>debug</code> table. | 5622 | inside a <code>debug</code> table. |
| 5585 | | 5623 | |
| 5586 | <p><a name="pdf-debug.debug"></a><hr><h3><code>debug.debug ()</code></h3> | 5624 | <p><a name="pdf-debug.debug"></a><hr/><h3><code>debug.debug ()</code></h3> |
| 5587 | | 5625 | |
| 5588 | <p>Enters an interactive mode with the user, | 5626 | <p>Enters an interactive mode with the user, |
| 5589 | running each string that the user enters. | 5627 | running each string that the user enters. |
| @@ -5596,17 +5634,17 @@ so that the caller continues its execution. · 6 unmodified lines |
| 5596 | <p>Note that commands for <a href="#pdf-debug.debug"><code>debug.debug</code></a> are not lexically nested | 5634 | <p>Note that commands for <a href="#pdf-debug.debug"><code>debug.debug</code></a> are not lexically nested |
| 5597 | with any function, so they have no direct access to local variables. | 5635 | with any function, so they have no direct access to local variables. |
| 5598 | | 5636 | |
| 5599 | <p><a name="pdf-debug.getfenv"></a><hr><h3><code>debug.getfenv (o)</code></h3> | 5637 | <p><a name="pdf-debug.getfenv"></a><hr/><h3><code>debug.getfenv (o)</code></h3> |
| 5600 | Returns the environment of object <code>o</code>. | 5638 | Returns the environment of object <code>o</code>. |
| 5601 | | 5639 | |
| 5602 | <p><a name="pdf-debug.gethook"></a><hr><h3><code>debug.gethook ()</code></h3> | 5640 | <p><a name="pdf-debug.gethook"></a><hr/><h3><code>debug.gethook ()</code></h3> |
| 5603 | | 5641 | |
| 5604 | <p>Returns the current hook settings, as three values: | 5642 | <p>Returns the current hook settings, as three values: |
| 5605 | the current hook function, the current hook mask, | 5643 | the current hook function, the current hook mask, |
| 5606 | and the current hook count | 5644 | and the current hook count |
| 5607 | (as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function). | 5645 | (as set by the <a href="#pdf-debug.sethook"><code>debug.sethook</code></a> function). |
| 5608 | | 5646 | |
| 5609 | <p><a name="pdf-debug.getinfo"></a><hr><h3><code>debug.getinfo (function [, what])</code></h3> | 5647 | <p><a name="pdf-debug.getinfo"></a><hr/><h3><code>debug.getinfo (function [, what])</code></h3> |
| 5610 | | 5648 | |
| 5611 | <p>This function returns a table with information about a function. | 5649 | <p>This function returns a table with information about a function. |
| 5612 | You can give the function directly, | 5650 | You can give the function directly, |
| @@ -5616,7 +5654,7 @@ Level 0 is the current function (<code>getinfo</code> itself); · 3 unmodified lines |
| 5616 | level 1 is the function that called <code>getinfo</code>; | 5654 | level 1 is the function that called <code>getinfo</code>; |
| 5617 | and so on. | 5655 | and so on. |
| 5618 | If <code>function</code> is a number larger than the number of active functions, | 5656 | If <code>function</code> is a number larger than the number of active functions, |
| 5619 | then <code>getinfo</code> returns <B>nil</B>. | 5657 | then <code>getinfo</code> returns <b>nil</b>. |
| 5620 | | 5658 | |
| 5621 | <p>The returned table contains all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>, | 5659 | <p>The returned table contains all the fields returned by <a href="#lua_getinfo"><code>lua_getinfo</code></a>, |
| 5622 | with the string <code>what</code> describing which fields to fill in. | 5660 | with the string <code>what</code> describing which fields to fill in. |
| @@ -5630,33 +5668,41 @@ the name of the current function, if a reasonable name can be found, · 7 unmodified lines |
| 5630 | and <code>debug.getinfo(print)</code> returns a table with all available information | 5668 | and <code>debug.getinfo(print)</code> returns a table with all available information |
| 5631 | about the <a href="#pdf-print"><code>print</code></a> function. | 5669 | about the <a href="#pdf-print"><code>print</code></a> function. |
| 5632 | | 5670 | |
| 5633 | <p><a name="pdf-debug.getlocal"></a><hr><h3><code>debug.getlocal (level, local)</code></h3> | 5671 | <p><a name="pdf-debug.getlocal"></a><hr/><h3><code>debug.getlocal (level, local)</code></h3> |
| 5634 | | 5672 | |
| 5635 | <p>This function returns the name and the value of the local variable | 5673 | <p>This function returns the name and the value of the local variable |
| 5636 | with index <code>local</code> of the function at level <code>level</code> of the stack. | 5674 | with index <code>local</code> of the function at level <code>level</code> of the stack. |
| 5637 | (The first parameter or local variable has index 1, and so on, | 5675 | (The first parameter or local variable has index 1, and so on, |
| 5638 | until the last active local variable.) | 5676 | until the last active local variable.) |
| 5639 | The function returns <B>nil</B> if there is no local | 5677 | The function returns <b>nil</b> if there is no local |
| 5640 | variable with the given index, | 5678 | variable with the given index, |
| 5641 | and raises an error when called with a <code>level</code> out of range. | 5679 | and raises an error when called with a <code>level</code> out of range. |
| 5642 | (You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the level is valid.) | 5680 | (You can call <a href="#pdf-debug.getinfo"><code>debug.getinfo</code></a> to check whether the level is valid.) |
| 5643 | | 5681 | |
| 5644 | <p><a name="pdf-debug.getmetatable"></a><hr><h3><code>debug.getmetatable (object)</code></h3> | 5682 | <p>Variable names starting with `<code>(</code>´ (open parentheses) |
| | 5683 | represent internal variables |
| | 5684 | (loop control variables, temporaries, and C function locals). |
| 5645 | | 5685 | |
| 5646 | <p>If <code>object</code> does not have a metatable, returns <B>nil</B>. | 5686 | <p><a name="pdf-debug.getmetatable"></a><hr/><h3><code>debug.getmetatable (object)</code></h3> |
| | 5687 | |
| | 5688 | <p>If <code>object</code> does not have a metatable, returns <b>nil</b>. |
| 5647 | Otherwise, returns the metatable of the given object. | 5689 | Otherwise, returns the metatable of the given object. |
| 5648 | | 5690 | |
| 5649 | <p><a name="pdf-debug.getupvalue"></a><hr><h3><code>debug.getupvalue (func, up)</code></h3> | 5691 | <p><a name="pdf-debug.getregistry"></a><hr/><h3><code>debug.getregistry ()</code></h3> |
| | 5692 | |
| | 5693 | <p>Returns the registry table (see <a href="#registry">3.5</a>). |
| | 5694 | |
| | 5695 | <p><a name="pdf-debug.getupvalue"></a><hr/><h3><code>debug.getupvalue (func, up)</code></h3> |
| 5650 | | 5696 | |
| 5651 | <p>This function returns the name and the value of the upvalue | 5697 | <p>This function returns the name and the value of the upvalue |
| 5652 | with index <code>up</code> of the function <code>func</code>. | 5698 | with index <code>up</code> of the function <code>func</code>. |
| 5653 | The function returns <B>nil</B> if there is no upvalue with the given index. | 5699 | The function returns <b>nil</b> if there is no upvalue with the given index. |
| 5654 | | 5700 | |
| 5655 | <p><a name="pdf-debug.setfenv"></a><hr><h3><code>debug.setfenv (o, table)</code></h3> | 5701 | <p><a name="pdf-debug.setfenv"></a><hr/><h3><code>debug.setfenv (o, table)</code></h3> |
| 5656 | | 5702 | |
| 5657 | <p>Sets the environment of the given object. | 5703 | <p>Sets the environment of the given object. |
| 5658 | | 5704 | |
| 5659 | <p><a name="pdf-debug.sethook"></a><hr><h3><code>debug.sethook (hook, mask [, count])</code></h3> | 5705 | <p><a name="pdf-debug.sethook"></a><hr/><h3><code>debug.sethook (hook, mask [, count])</code></h3> |
| 5660 | | 5706 | |
| 5661 | <p>Sets the given function as a hook. | 5707 | <p>Sets the given function as a hook. |
| 5662 | The string <code>mask</code> and the number <code>count</code> describe | 5708 | The string <code>mask</code> and the number <code>count</code> describe |
| @@ -5689,29 +5735,29 @@ unless the event is <code>"tail return"</code>. · 26 unmodified lines |
| 5689 | In this case, Lua is only simulating the return, | 5735 | In this case, Lua is only simulating the return, |
| 5690 | and a call to <code>getinfo</code> will return invalid data. | 5736 | and a call to <code>getinfo</code> will return invalid data. |
| 5691 | | 5737 | |
| 5692 | <p><a name="pdf-debug.setlocal"></a><hr><h3><code>debug.setlocal (level, local, value)</code></h3> | 5738 | <p><a name="pdf-debug.setlocal"></a><hr/><h3><code>debug.setlocal (level, local, value)</code></h3> |
| 5693 | | 5739 | |
| 5694 | <p>This function assigns the value <code>value</code> to the local variable | 5740 | <p>This function assigns the value <code>value</code> to the local variable |
| 5695 | with index <code>local</code> of the function at level <code>level</code> of the stack. | 5741 | with index <code>local</code> of the function at level <code>level</code> of the stack. |
| 5696 | The function returns <B>nil</B> if there is no local | 5742 | The function returns <b>nil</b> if there is no local |
| 5697 | variable with the given index, | 5743 | variable with the given index, |
| 5698 | and raises an error when called with a <code>level</code> out of range. | 5744 | and raises an error when called with a <code>level</code> out of range. |
| 5699 | (You can call <code>getinfo</code> to check whether the level is valid.) | 5745 | (You can call <code>getinfo</code> to check whether the level is valid.) |
| 5700 | Otherwise, it returns the name of the local variable. | 5746 | Otherwise, it returns the name of the local variable. |
| 5701 | | 5747 | |
| 5702 | <p><a name="pdf-debug.setmetatable"></a><hr><h3><code>debug.setmetatable (o, metatable)</code></h3> | 5748 | <p><a name="pdf-debug.setmetatable"></a><hr/><h3><code>debug.setmetatable (o, metatable)</code></h3> |
| 5703 | | 5749 | |
| 5704 | <p>Sets the metatable for the given object. | 5750 | <p>Sets the metatable for the given object. |
| 5705 | | 5751 | |
| 5706 | <p><a name="pdf-debug.setupvalue"></a><hr><h3><code>debug.setupvalue (func, up, value)</code></h3> | 5752 | <p><a name="pdf-debug.setupvalue"></a><hr/><h3><code>debug.setupvalue (func, up, value)</code></h3> |
| 5707 | | 5753 | |
| 5708 | <p>This function assigns the value <code>value</code> to the upvalue | 5754 | <p>This function assigns the value <code>value</code> to the upvalue |
| 5709 | with index <code>up</code> of the function <code>func</code>. | 5755 | with index <code>up</code> of the function <code>func</code>. |
| 5710 | The function returns <B>nil</B> if there is no upvalue | 5756 | The function returns <b>nil</b> if there is no upvalue |
| 5711 | with the given index. | 5757 | with the given index. |
| 5712 | Otherwise, it returns the name of the upvalue. | 5758 | Otherwise, it returns the name of the upvalue. |
| 5713 | | 5759 | |
| 5714 | <p><a name="pdf-debug.traceback"></a><hr><h3><code>debug.traceback ([message])</code></h3> | 5760 | <p><a name="pdf-debug.traceback"></a><hr/><h3><code>debug.traceback ([message])</code></h3> |
| 5715 | | 5761 | |
| 5716 | <p>Returns a string with a traceback of the call stack. | 5762 | <p>Returns a string with a traceback of the call stack. |
| 5717 | An optional <code>message</code> string is appended | 5763 | An optional <code>message</code> string is appended |
| @@ -5731,17 +5777,17 @@ is provided with the standard distribution. · 13 unmodified lines |
| 5731 | The stand-alone interpreter includes | 5777 | The stand-alone interpreter includes |
| 5732 | all standard libraries plus the reflexive debug interface. | 5778 | all standard libraries plus the reflexive debug interface. |
| 5733 | Its usage is: | 5779 | Its usage is: |
| 5734 | <PRE> | 5780 | <pre> |
| 5735 | lua [options] [script [args]] | 5781 | lua [options] [script [args]] |
| 5736 | </PRE> | 5782 | </pre> |
| 5737 | The options are: | 5783 | The options are: |
| 5738 | <ul> | 5784 | <ul> |
| 5739 | <li><b><code>-</code> </b> executes <code>stdin</code> as a file; | | |
| 5740 | <li><b><code>-e</code> <em>stat</em></b> executes string <em>stat</em>; | 5785 | <li><b><code>-e</code> <em>stat</em></b> executes string <em>stat</em>; |
| 5741 | <li><b><code>-l</code> <em>mod</em></b> "requires" <em>mod</em>; | 5786 | <li><b><code>-l</code> <em>mod</em></b> "requires" <em>mod</em>; |
| 5742 | <li><b><code>-i</code></b> enters interactive mode after running <em>script</em>; | 5787 | <li><b><code>-i</code></b> enters interactive mode after running <em>script</em>; |
| 5743 | <li><b><code>-v</code></b> prints version information; | 5788 | <li><b><code>-v</code></b> prints version information; |
| 5744 | <li><b><code>--</code></b> stop handling options. | 5789 | <li><b><code>--</code></b> stops handling options; |
| | 5790 | <li><b><code>-</code> </b> executes <code>stdin</code> as a file and stops handling options. |
| 5745 | </ul> | 5791 | </ul> |
| 5746 | After handling its options, <code>lua</code> runs the given <em>script</em>, | 5792 | After handling its options, <code>lua</code> runs the given <em>script</em>, |
| 5747 | passing to it the given <em>args</em>. | 5793 | passing to it the given <em>args</em>. |
| @@ -5757,9 +5803,9 @@ Otherwise, lua executes the string itself. · 9 unmodified lines |
| 5757 | | 5803 | |
| 5758 | <p>All options are handled in order, except <code>-i</code>. | 5804 | <p>All options are handled in order, except <code>-i</code>. |
| 5759 | For instance, an invocation like | 5805 | For instance, an invocation like |
| 5760 | <PRE> | 5806 | <pre> |
| 5761 | $ lua -e'a=1' -e 'print(a)' script.lua | 5807 | $ lua -e'a=1' -e 'print(a)' script.lua |
| 5762 | </PRE> | 5808 | </pre> |
| 5763 | will first set <code>a</code> to 1, then print <code>a</code>, | 5809 | will first set <code>a</code> to 1, then print <code>a</code>, |
| 5764 | and finally run the file <code>script.lua</code>. | 5810 | and finally run the file <code>script.lua</code>. |
| 5765 | (Here <code>$</code> is the shell prompt. Your prompt may be different.) | 5811 | (Here <code>$</code> is the shell prompt. Your prompt may be different.) |
| @@ -5774,15 +5820,15 @@ Any arguments before the script name · 8 unmodified lines |
| 5774 | (that is, the interpreter name plus the options) | 5820 | (that is, the interpreter name plus the options) |
| 5775 | go to negative indices. | 5821 | go to negative indices. |
| 5776 | For instance, in the call | 5822 | For instance, in the call |
| 5777 | <PRE> | 5823 | <pre> |
| 5778 | $ lua -la.lua b.lua t1 t2 | 5824 | $ lua -la.lua b.lua t1 t2 |
| 5779 | </PRE> | 5825 | </pre> |
| 5780 | the interpreter first runs the file <code>a.lua</code>, | 5826 | the interpreter first runs the file <code>a.lua</code>, |
| 5781 | then creates a table | 5827 | then creates a table |
| 5782 | <PRE> | 5828 | <pre> |
| 5783 | arg = { [-2] = "lua", [-1] = "-la.lua", [0] = "b.lua", | 5829 | arg = { [-2] = "lua", [-1] = "-la.lua", [0] = "b.lua", |
| 5784 | [1] = "t1", [2] = "t2" } | 5830 | [1] = "t1", [2] = "t2" } |
| 5785 | </PRE> | 5831 | </pre> |
| 5786 | and finally runs the file <code>b.lua</code>. | 5832 | and finally runs the file <code>b.lua</code>. |
| 5787 | The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ... | 5833 | The script is called with <code>arg[1]</code>, <code>arg[2]</code>, ... |
| 5788 | as arguments; | 5834 | as arguments; |
| @@ -5795,9 +5841,9 @@ the interpreter waits for its completion. · 6 unmodified lines |
| 5795 | <p>If the global variable <code>_PROMPT</code> is defined as a string, | 5841 | <p>If the global variable <code>_PROMPT</code> is defined as a string, |
| 5796 | then its value is used as the prompt. | 5842 | then its value is used as the prompt. |
| 5797 | Therefore, the prompt can be changed directly on the command line: | 5843 | Therefore, the prompt can be changed directly on the command line: |
| 5798 | <PRE> | 5844 | <pre> |
| 5799 | $ lua -e"_PROMPT='myprompt> '" -i | 5845 | $ lua -e"_PROMPT='myprompt> '" -i |
| 5800 | </PRE> | 5846 | </pre> |
| 5801 | (the outer pair of quotes is for the shell, | 5847 | (the outer pair of quotes is for the shell, |
| 5802 | the inner is for Lua), | 5848 | the inner is for Lua), |
| 5803 | or in any Lua programs by assigning to <code>_PROMPT</code>. | 5849 | or in any Lua programs by assigning to <code>_PROMPT</code>. |
| @@ -5811,19 +5857,19 @@ the first line of a chunk if it starts with <code>#</code>. · 7 unmodified lines |
| 5811 | Therefore, Lua scripts can be made into executable programs | 5857 | Therefore, Lua scripts can be made into executable programs |
| 5812 | by using <code>chmod +x</code> and the <code>#!</code> form, | 5858 | by using <code>chmod +x</code> and the <code>#!</code> form, |
| 5813 | as in | 5859 | as in |
| 5814 | <PRE> | 5860 | <pre> |
| 5815 | #!/usr/local/bin/lua | 5861 | #!/usr/local/bin/lua |
| 5816 | </PRE> | 5862 | </pre> |
| 5817 | (Of course, | 5863 | (Of course, |
| 5818 | the location of the Lua interpreter may be different in your machine. | 5864 | the location of the Lua interpreter may be different in your machine. |
| 5819 | If <code>lua</code> is in your <code>PATH</code>, | 5865 | If <code>lua</code> is in your <code>PATH</code>, |
| 5820 | then | 5866 | then |
| 5821 | <PRE> | 5867 | <pre> |
| 5822 | #!/usr/bin/env lua | 5868 | #!/usr/bin/env lua |
| 5823 | </PRE> | 5869 | </pre> |
| 5824 | is a more portable solution.) | 5870 | is a more portable solution.) |
| 5825 | | 5871 | |
| 5826 | <p><hr> | 5872 | <p><hr/> |
| 5827 | | 5873 | |
| 5828 | <p><h1>Incompatibilities with Previous Version</h1> | 5874 | <p><h1>Incompatibilities with Previous Version</h1> |
| 5829 | | 5875 | |
| @@ -5866,6 +5912,13 @@ Use <a href="#pdf-string.match"><code>string.match</code></a> for that. · 36 unmodified lines |
| 5866 | Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>. | 5912 | Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>. |
| 5867 | (Option <code>LUA_COMPAT_GFIND</code>) | 5913 | (Option <code>LUA_COMPAT_GFIND</code>) |
| 5868 | | 5914 | |
| | 5915 | <p><li> |
| | 5916 | When <a href="#pdf-string.gsub"><code>string.gsub</code></a> is called with a function as its |
| | 5917 | third argument, |
| | 5918 | whenever that function returns <b>nil</b> or <b>false</b> the |
| | 5919 | replacement string is the whole match, |
| | 5920 | instead of the empty string. |
| | 5921 | |
| 5869 | <p><li> | 5922 | <p><li> |
| 5870 | Function <code>table.setn</code> was deprecated. | 5923 | Function <code>table.setn</code> was deprecated. |
| 5871 | Function <code>table.getn</code> corresponds | 5924 | Function <code>table.getn</code> corresponds |
| @@ -5924,48 +5977,66 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 52 unmodified lines |
| 5924 | | 5977 | |
| 5925 | <p><pre> | 5978 | <p><pre> |
| 5926 | | 5979 | |
| 5927 | <p> chunk ::= {stat [`<b>;</b>´]} | 5980 | chunk ::= {stat [`<b>;</b>´]} [laststat[`<b>;</b>´]] |
| | 5981 | |
| | 5982 | block ::= chunk |
| 5928 | | 5983 | |
| 5929 | <p> block ::= chunk | 5984 | stat ::= varlist1 `<b>=</b>´ explist1 | |
| | 5985 | functioncall | |
| | 5986 | <b>do</b> block <b>end</b> | |
| | 5987 | <b>while</b> exp <b>do</b> block <b>end</b> | |
| | 5988 | <b>repeat</b> block <b>until</b> exp | |
| | 5989 | <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | |
| | 5990 | <b>for</b> Name `<b>=</b>´ exp `<b>,</b>´ exp [`<b>,</b>´ exp] <b>do</b> block <b>end</b> | |
| | 5991 | <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> | |
| | 5992 | <b>function</b> funcname funcbody | |
| | 5993 | <b>local</b> <b>function</b> Name funcbody | |
| | 5994 | <b>local</b> namelist [init] |
| 5930 | | 5995 | |
| 5931 | <p> stat ::= varlist1 `<b>=</b>´ explist1 | functioncall | <b>do</b> block <b>end</b> | <b>while</b> exp <b>do</b> block <b>end</b> | <b>repeat</b> block <b>until</b> exp | <b>if</b> exp <b>then</b> block {<b>elseif</b> exp <b>then</b> block} [<b>else</b> block] <b>end</b> | <b>return</b> [explist1] | <b>break</b> | <b>for</b> Name `<b>=</b>´ exp `<b>,</b>´ exp [`<b>,</b>´ exp] <b>do</b> block <b>end</b> | <b>for</b> namelist <b>in</b> explist1 <b>do</b> block <b>end</b> | <b>function</b> funcname funcbody | <b>local</b> <b>function</b> Name funcbody | <b>local</b> namelist [init] | 5996 | laststat ::= <b>return</b> [explist1] | <b>break</b> |
| 5932 | | 5997 | |
| 5933 | <p> funcname ::= Name {`<b>.</b>´ Name} [`<b>:</b>´ Name] | 5998 | funcname ::= Name {`<b>.</b>´ Name} [`<b>:</b>´ Name] |
| | 5999 | |
| | 6000 | varlist1 ::= var {`<b>,</b>´ var} |
| 5934 | | 6001 | |
| 5935 | <p> varlist1 ::= var {`<b>,</b>´ var} | 6002 | var ::= Name | prefixexp `<b>[</b>´ exp `<b>]</b>´ | prefixexp `<b>.</b>´ Name |
| 5936 | | 6003 | |
| 5937 | <p> var ::= Name | prefixexp `<b>[</b>´ exp `<b>]</b>´ | prefixexp `<b>.</b>´ Name | 6004 | namelist ::= Name {`<b>,</b>´ Name} |
| 5938 | | 6005 | |
| 5939 | <p> namelist ::= Name {`<b>,</b>´ Name} | 6006 | init ::= `<b>=</b>´ explist1 |
| 5940 | | 6007 | |
| 5941 | <p> init ::= `<b>=</b>´ explist1 | 6008 | explist1 ::= {exp `<b>,</b>´} exp |
| 5942 | | 6009 | |
| 5943 | <p> explist1 ::= {exp `<b>,</b>´} exp | 6010 | exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | `<b>...</b>´ | |
| | 6011 | function | prefixexp | tableconstructor | exp binop exp | unop exp |
| 5944 | | 6012 | |
| 5945 | <p> exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | `<b>...</b>´ | function | prefixexp | tableconstructor | exp binop exp | unop exp | 6013 | prefixexp ::= var | functioncall | `<b>(</b>´ exp `<b>)</b>´ |
| 5946 | | 6014 | |
| 5947 | <p> prefixexp ::= var | functioncall | `<b>(</b>´ exp `<b>)</b>´ | 6015 | functioncall ::= prefixexp args | prefixexp `<b>:</b>´ Name args |
| 5948 | | 6016 | |
| 5949 | <p> functioncall ::= prefixexp args | prefixexp `<b>:</b>´ Name args | 6017 | args ::= `<b>(</b>´ [explist1] `<b>)</b>´ | tableconstructor | Literal |
| 5950 | | 6018 | |
| 5951 | <p> args ::= `<b>(</b>´ [explist1] `<b>)</b>´ | tableconstructor | Literal | 6019 | function ::= <b>function</b> funcbody |
| 5952 | | 6020 | |
| 5953 | <p> function ::= <b>function</b> funcbody | 6021 | funcbody ::= `<b>(</b>´ [parlist1] `<b>)</b>´ block <b>end</b> |
| 5954 | | 6022 | |
| 5955 | <p> funcbody ::= `<b>(</b>´ [parlist1] `<b>)</b>´ block <b>end</b> | 6023 | parlist1 ::= namelist [`<b>,</b>´ `<b>...</b>´] | `<b>...</b>´ |
| 5956 | | 6024 | |
| 5957 | <p> parlist1 ::= namelist [`<b>,</b>´ `<b>...</b>´] | `<b>...</b>´ | 6025 | tableconstructor ::= `<b>{</b>´ [fieldlist] `<b>}</b>´ |
| 5958 | | 6026 | |
| 5959 | <p> tableconstructor ::= `<b>{</b>´ [fieldlist] `<b>}</b>´ | | |
| 5960 | fieldlist ::= field {fieldsep field} [fieldsep] | 6027 | fieldlist ::= field {fieldsep field} [fieldsep] |
| 5961 | field ::= `<b>[</b>´ exp `<b>]</b>´ `<b>=</b>´ exp | name `<b>=</b>´ exp | exp | | |
| 5962 | fieldsep ::= `<b>,</b>´ | `<b>;</b>´ | | |
| 5963 | | 6028 | |
| 5964 | <p> binop ::= `<b>+</b>´ | `<b>-</b>´ | `<b>*</b>´ | `<b>/</b>´ | `<b>^</b>´ | `<b>%</b>´ | `<b>..</b>´ | `<b><</b>´ | `<b><=</b>´ | `<b>></b>´ | `<b>>=</b>´ | `<b>==</b>´ | `<b>~=</b>´ | <b>and</b> | <b>or</b> | 6029 | field ::= `<b>[</b>´ exp `<b>]</b>´ `<b>=</b>´ exp | name `<b>=</b>´ exp | exp |
| 5965 | | 6030 | |
| 5966 | <p> unop ::= `<b>-</b>´ | <b>not</b> | `<b>#</b>´ | 6031 | fieldsep ::= `<b>,</b>´ | `<b>;</b>´ |
| 5967 | | 6032 | |
| 5968 | <p></pre> | 6033 | binop ::= `<b>+</b>´ | `<b>-</b>´ | `<b>*</b>´ | `<b>/</b>´ | `<b>^</b>´ | `<b>%</b>´ | `<b>..</b>´ | |
| | 6034 | `<b><</b>´ | `<b><=</b>´ | `<b>></b>´ | `<b>>=</b>´ | `<b>==</b>´ | `<b>~=</b>´ | |
| | 6035 | <b>and</b> | <b>or</b> |
| | 6036 | |
| | 6037 | unop ::= `<b>-</b>´ | <b>not</b> | `<b>#</b>´ |
| | 6038 | |
| | 6039 | </pre> |
| 5969 | | 6040 | |
| 5970 | <p> | 6041 | <p> |
| 5971 | | 6042 | |
| @@ -5974,7 +6045,7 @@ Function <code>luaL_openlib</code> was replaced by <a href="#luaL_register"><cod · 2 unmodified lines |
| 5974 | <HR> | 6045 | <HR> |
| 5975 | <SMALL> | 6046 | <SMALL> |
| 5976 | Last update: | 6047 | Last update: |
| 5977 | Wed Sep 7 13:53:49 BRT 2005 | 6048 | Tue Nov 1 15:20:21 BRST 2005 |
| 5978 | </SMALL> | 6049 | </SMALL> |
| 5979 | | 6050 | |
| 5980 | </body></html> | 6051 | </body></html> |