| @@ -2,16 +2,14 @@ · 1 unmodified line |
| 2 | 2 | <html> |
| 3 | 3 | |
| 4 | 4 | <head> |
| 5 | | −<title>Lua 5.0 Reference Manual</title> |
| 5 | +<TITLE>Lua: 5.0 reference manual</TITLE> |
| 6 | 6 | </head> |
| 7 | 7 | |
| 8 | 8 | <body BGCOLOR="#FFFFFF"> |
| 9 | 9 | |
| 10 | 10 | <hr> |
| 11 | 11 | <h1> |
| 12 | | −<a HREF="http://www.lua.org/home.html"> |
| 13 | | −<img SRC="logo.gif" ALT="[Lua logo]" BORDER=0> |
| 14 | | −</a> |
| 12 | +<A HREF="http://www.lua.org/home.html"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A> |
| 15 | 13 | Lua 5.0 Reference Manual |
| 16 | 14 | </h1> |
| 17 | 15 | |
| @@ -19,7 +17,7 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 1 unmodified line |
| 19 | 17 | <p> |
| 20 | 18 | <small> |
| 21 | 19 | <a HREF="http://www.lua.org/copyright.html">Copyright</a> |
| 22 | | −© 2003 TeCGraf, PUC-Rio. All rights reserved. |
| 20 | +© 2003 Tecgraf, PUC-Rio. All rights reserved. |
| 23 | 21 | </small> |
| 24 | 22 | <hr> |
| 25 | 23 | |
| @@ -29,12 +27,12 @@ by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes · 3 unmodified lines |
| 29 | 27 | |
| 30 | 28 | |
| 31 | 29 | |
| 32 | | −<h1>1 - Introduction</h1> |
| 30 | +<a name="1"><h1>1 - Introduction</h1></a> |
| 33 | 31 | |
| 34 | 32 | <p>Lua is an extension programming language designed to support |
| 35 | 33 | general procedural programming with data description |
| 36 | 34 | facilities. |
| 37 | | −It also offers good suport for object-oriented programming, |
| 35 | +It also offers good support for object-oriented programming, |
| 38 | 36 | functional programming, and data-driven programming. |
| 39 | 37 | Lua is intended to be used as a powerful, light-weight |
| 40 | 38 | configuration language for any program that needs one. |
| @@ -51,7 +49,7 @@ Through the use of C functions, Lua can be augmented to cope with · 10 unmodified lines |
| 51 | 49 | a wide range of different domains, |
| 52 | 50 | thus creating customized programming languages sharing a syntactical framework. |
| 53 | 51 | |
| 54 | | −<p>The Lua distribuition includes a stand-alone embedding program, |
| 52 | +<p>The Lua distribution includes a stand-alone embedding program, |
| 55 | 53 | <code>lua</code>, that uses the Lua library to offer a complete Lua interpreter. |
| 56 | 54 | |
| 57 | 55 | <p>Lua is free software, |
| @@ -87,7 +85,7 @@ The evolution of an extension language: a history of Lua, · 29 unmodified lines |
| 87 | 85 | <p>Lua means "moon" in Portuguese and is pronounced LOO-ah. |
| 88 | 86 | |
| 89 | 87 | <p> |
| 90 | | −<a name="language"><h1>2 - The Language</h1></a> |
| 88 | +<a name="language"><a name="2"><h1>2 - The Language</h1></a></a> |
| 91 | 89 | |
| 92 | 90 | <p>This section describes the lexis, the syntax, and the semantics of Lua. |
| 93 | 91 | In other words, |
| @@ -105,7 +103,7 @@ keywords are shown in <b>bold</b>, · 11 unmodified lines |
| 105 | 103 | and other terminal symbols are shown in <code>typewriter</code> font, |
| 106 | 104 | enclosed in single quotes. |
| 107 | 105 | |
| 108 | | −<p><a name="lexical"><h2>2.1 - Lexical Conventions</h2></a> |
| 106 | +<p><a name="lexical"><a name="2.1"><h2>2.1 - Lexical Conventions</h2></a></a> |
| 109 | 107 | |
| 110 | 108 | <p><em>Identifiers</em> in Lua can be any string of letters, |
| 111 | 109 | digits, and underscores, |
| @@ -122,8 +120,7 @@ and cannot be used as identifiers: · 10 unmodified lines |
| 122 | 120 | and break do else elseif |
| 123 | 121 | end false for function if |
| 124 | 122 | in local nil not or |
| 125 | | − repeat return then true until |
| 126 | | − while |
| 123 | + repeat return then true until while |
| 127 | 124 | </PRE> |
| 128 | 125 | |
| 129 | 126 | <p>Lua is a case-sensitive language: |
| @@ -211,7 +208,7 @@ the first line of a chunk is skipped if it starts with <code>#</code>. · 81 unmodified lines |
| 211 | 208 | This facility allows the use of Lua as a script interpreter |
| 212 | 209 | in Unix systems (see <a href="#lua-sa">6</a>). |
| 213 | 210 | |
| 214 | | −<p><a name="TypesSec"><h2>2.2 - Values and Types</h2></a> |
| 211 | +<p><a name="TypesSec"><a name="2.2"><h2>2.2 - Values and Types</h2></a></a> |
| 215 | 212 | |
| 216 | 213 | <p>Lua is a <em>dynamically typed language</em>. |
| 217 | 214 | That means that |
| @@ -292,7 +289,7 @@ these operations do not imply any kind of copy. · 74 unmodified lines |
| 292 | 289 | <p>The library function <code>type</code> returns a string describing the type |
| 293 | 290 | of a given value (see <a href="#pdf-type">5.1</a>). |
| 294 | 291 | |
| 295 | | −<p><a name="coercion"><h3>2.2.1 - Coercion</h3></a> |
| 292 | +<p><a name="coercion"><a name="2.2.1"><h3>2.2.1 - Coercion</h3></a></a> |
| 296 | 293 | |
| 297 | 294 | <p>Lua provides automatic conversion between |
| 298 | 295 | string and number values at run time. |
| @@ -303,7 +300,7 @@ the number is converted to a string, in a reasonable format. · 4 unmodified lines |
| 303 | 300 | For complete control of how numbers are converted to strings, |
| 304 | 301 | use the <code>format</code> function from the string library (see <a href="#format">5.3</a>). |
| 305 | 302 | |
| 306 | | −<p><a name="variables"><h2>2.3 - Variables</h2></a> |
| 303 | +<p><a name="variables"><a name="2.3"><h2>2.3 - Variables</h2></a></a> |
| 307 | 304 | |
| 308 | 305 | <p>Variables are places that store values. |
| 309 | 306 | |
| @@ -372,7 +369,7 @@ where <code>_env</code> is the environment of the running function. · 62 unmodified lines |
| 372 | 369 | (The <code>_env</code> variable is not defined in Lua. |
| 373 | 370 | We use it here only for explanatory purposes.) |
| 374 | 371 | |
| 375 | | −<p><a name="stats"><h2>2.4 - Statements</h2></a> |
| 372 | +<p><a name="stats"><a name="2.4"><h2>2.4 - Statements</h2></a></a> |
| 376 | 373 | |
| 377 | 374 | <p>Lua supports an almost conventional set of statements, |
| 378 | 375 | similar to those in Pascal or C. |
| @@ -380,7 +377,7 @@ This set includes · 1 unmodified line |
| 380 | 377 | assignment, control structures, procedure calls, |
| 381 | 378 | table constructors, and variable declarations. |
| 382 | 379 | |
| 383 | | −<p><a name="chunks"><h3>2.4.1 - Chunks</h3></a> |
| 380 | +<p><a name="chunks"><a name="2.4.1"><h3>2.4.1 - Chunks</h3></a></a> |
| 384 | 381 | |
| 385 | 382 | <p>The unit of execution of Lua is called a <em>chunk</em>. |
| 386 | 383 | A chunk is simply a sequence of statements, |
| @@ -405,7 +402,7 @@ Programs in source and compiled forms are interchangeable; · 18 unmodified lines |
| 405 | 402 | Lua automatically detects the file type and acts accordingly. |
| 406 | 403 | |
| 407 | 404 | |
| 408 | | −<p><h3>2.4.2 - Blocks</h3> |
| 405 | +<p><a name="2.4.2"><h3>2.4.2 - Blocks</h3></a> |
| 409 | 406 | A block is a list of statements; |
| 410 | 407 | syntactically, a block is equal to a chunk: |
| 411 | 408 | <pre> |
| @@ -423,7 +420,7 @@ add a <b>return</b> or <b>break</b> statement in the middle · 11 unmodified lines |
| 423 | 420 | of another block (see <a href="#control">2.4.4</a>). |
| 424 | 421 | |
| 425 | 422 | |
| 426 | | −<p><a name="assignment"><h3>2.4.3 - Assignment</h3></a> |
| 423 | +<p><a name="assignment"><a name="2.4.3"><h3>2.4.3 - Assignment</h3></a></a> |
| 427 | 424 | |
| 428 | 425 | <p>Lua allows multiple assignment. |
| 429 | 426 | Therefore, the syntax for assignment |
| @@ -458,7 +455,7 @@ Thus the code · 28 unmodified lines |
| 458 | 455 | </PRE> |
| 459 | 456 | sets <code>a[3]</code> to 20, without affecting <code>a[4]</code> |
| 460 | 457 | because the <code>i</code> in <code>a[i]</code> is evaluated (to 3) |
| 461 | | −before it is assigned 4. |
| 458 | +before it is assigned 4. |
| 462 | 459 | Similarly, the line |
| 463 | 460 | <PRE> |
| 464 | 461 | x, y = y, x |
| @@ -485,7 +482,7 @@ where <code>_env</code> is the environment of the running function. · 20 unmodified lines |
| 485 | 482 | (The <code>_env</code> variable is not defined in Lua. |
| 486 | 483 | We use it here only for explanatory purposes.) |
| 487 | 484 | |
| 488 | | −<p><a name="control"><h3>2.4.4 - Control Structures</h3></a> |
| 485 | +<p><a name="control"><a name="2.4.4"><h3>2.4.4 - Control Structures</h3></a></a> |
| 489 | 486 | The control structures |
| 490 | 487 | <b>if</b>, <b>while</b>, and <b>repeat</b> have the usual meaning and |
| 491 | 488 | familiar syntax: |
| @@ -516,7 +513,7 @@ so the syntax for the <b>return</b> statement is · 24 unmodified lines |
| 516 | 513 | |
| 517 | 514 | <p>The <b>break</b> statement can be used to terminate the execution of a |
| 518 | 515 | <b>while</b>, <b>repeat</b>, or <b>for</b> loop, |
| 519 | | −skiping to the next statement after the loop: |
| 516 | +skipping to the next statement after the loop: |
| 520 | 517 | |
| 521 | 518 | <pre> |
| 522 | 519 | stat ::= <b>break</b> |
| @@ -536,7 +533,7 @@ their (inner) blocks. · 13 unmodified lines |
| 536 | 533 | In practice, |
| 537 | 534 | those idioms are only used during debugging. |
| 538 | 535 | |
| 539 | | −<p><a name="for"><h3>2.4.5 - For Statement</h3></a> |
| 536 | +<p><a name="for"><a name="2.4.5"><h3>2.4.5 - For Statement</h3></a></a> |
| 540 | 537 | |
| 541 | 538 | <p>The <b>for</b> statement has two forms: |
| 542 | 539 | one numeric and one generic. |
| @@ -623,7 +620,7 @@ If you need these values, · 80 unmodified lines |
| 623 | 620 | then assign them to other variables before breaking or exiting the loop. |
| 624 | 621 | </ul> |
| 625 | 622 | |
| 626 | | −<p><a name="funcstat"><h3>2.4.6 - Function Calls as Statements</h3></a> |
| 623 | +<p><a name="funcstat"><a name="2.4.6"><h3>2.4.6 - Function Calls as Statements</h3></a></a> |
| 627 | 624 | To allow possible side-effects, |
| 628 | 625 | function calls can be executed as statements: |
| 629 | 626 | <pre> |
| @@ -632,7 +629,7 @@ function calls can be executed as statements: · 2 unmodified lines |
| 632 | 629 | In this case, all returned values are thrown away. |
| 633 | 630 | Function calls are explained in <a href="#functioncall">2.5.7</a>. |
| 634 | 631 | |
| 635 | | −<p><a name="localvar"><h3>2.4.7 - Local Declarations</h3></a> |
| 632 | +<p><a name="localvar"><a name="2.4.7"><h3>2.4.7 - Local Declarations</h3></a></a> |
| 636 | 633 | Local variables may be declared anywhere inside a block. |
| 637 | 634 | The declaration may include an initial assignment: |
| 638 | 635 | <pre> |
| @@ -649,7 +646,7 @@ Such local variables die when the chunk ends. · 10 unmodified lines |
| 649 | 646 | |
| 650 | 647 | <p>The visibility rules for local variables are explained in <a href="#visibility">2.6</a>. |
| 651 | 648 | |
| 652 | | −<p><a name="expressions"><h2>2.5 - Expressions</h2></a> |
| 649 | +<p><a name="expressions"><a name="2.5"><h2>2.5 - Expressions</h2></a></a> |
| 653 | 650 | |
| 654 | 651 | <p> |
| 655 | 652 | The basic expressions in Lua are the following: |
| @@ -680,7 +677,7 @@ or <B>nil</B> if <code>f</code> does not return any values.) · 24 unmodified lines |
| 680 | 677 | <p>Expressions can also be built with arithmetic operators, relational operators, |
| 681 | 678 | and logical operators, all of which are explained below. |
| 682 | 679 | |
| 683 | | −<p><h3>2.5.1 - Arithmetic Operators</h3> |
| 680 | +<p><a name="2.5.1"><h3>2.5.1 - Arithmetic Operators</h3></a> |
| 684 | 681 | Lua supports the usual arithmetic operators: |
| 685 | 682 | the binary <code>+</code> (addition), |
| 686 | 683 | <code>-</code> (subtraction), <code>*</code> (multiplication), |
| @@ -695,7 +692,7 @@ The standard mathematical library defines function <code>__pow</code>, · 8 unmodified lines |
| 695 | 692 | giving the expected meaning to exponentiation |
| 696 | 693 | (see <a href="#mathlib">5.5</a>). |
| 697 | 694 | |
| 698 | | −<p><a name="rel-ops"><h3>2.5.2 - Relational Operators</h3></a> |
| 695 | +<p><a name="rel-ops"><a name="2.5.2"><h3>2.5.2 - Relational Operators</h3></a></a> |
| 699 | 696 | The relational operators in Lua are |
| 700 | 697 | <PRE> |
| 701 | 698 | == ~= < > <= >= |
| @@ -731,7 +728,7 @@ then their values are compared according to the current locale. · 29 unmodified lines |
| 731 | 728 | Otherwise, Lua tries to call the "lt" or the "le" |
| 732 | 729 | metamethod (see <a href="#metatable">2.8</a>). |
| 733 | 730 | |
| 734 | | −<p><h3>2.5.3 - Logical Operators</h3> |
| 731 | +<p><a name="2.5.3"><h3>2.5.3 - Logical Operators</h3></a> |
| 735 | 732 | The logical operators in Lua are |
| 736 | 733 | |
| 737 | 734 | <PRE> |
| @@ -764,14 +761,14 @@ For example, · 26 unmodified lines |
| 764 | 761 | 10 and 20 -> 20 |
| 765 | 762 | </PRE> |
| 766 | 763 | |
| 767 | | −<p><a name="concat"><h3>2.5.4 - Concatenation</h3></a> |
| 764 | +<p><a name="concat"><a name="2.5.4"><h3>2.5.4 - Concatenation</h3></a></a> |
| 768 | 765 | The string concatenation operator in Lua is |
| 769 | 766 | denoted by two dots (`<code>..</code>´). |
| 770 | 767 | If both operands are strings or numbers, then they are converted to |
| 771 | 768 | strings according to the rules mentioned in <a href="#coercion">2.2.1</a>. |
| 772 | 769 | Otherwise, the "concat" metamethod is called (see <a href="#metatable">2.8</a>). |
| 773 | 770 | |
| 774 | | −<p><h3>2.5.5 - Precedence</h3> |
| 771 | +<p><a name="2.5.5"><h3>2.5.5 - Precedence</h3></a> |
| 775 | 772 | Operator precedence in Lua follows the table below, |
| 776 | 773 | from lower to higher priority: |
| 777 | 774 | <PRE> |
| @@ -784,12 +781,12 @@ from lower to higher priority: · 6 unmodified lines |
| 784 | 781 | not - (unary) |
| 785 | 782 | ^ |
| 786 | 783 | </PRE> |
| 787 | | −As usual, you can use parentheses to change the precedences of an expression. |
| 784 | +You can use parentheses to change the precedences in an expression. |
| 788 | 785 | The concatenation (`<code>..</code>´) and exponentiation (`<code>^</code>´) |
| 789 | 786 | operators are right associative. |
| 790 | 787 | All other binary operators are left associative. |
| 791 | 788 | |
| 792 | | −<p><a name="tableconstructor"><h3>2.5.6 - Table Constructors</h3></a> |
| 789 | +<p><a name="tableconstructor"><a name="2.5.6"><h3>2.5.6 - Table Constructors</h3></a></a> |
| 793 | 790 | Table constructors are expressions that create tables. |
| 794 | 791 | Every time a constructor is evaluated, a new table is created. |
| 795 | 792 | Constructors can be used to create empty tables, |
| @@ -839,7 +836,7 @@ enclose the function call in parentheses (see <a href="#expressions">2.5</a>). · 43 unmodified lines |
| 839 | 836 | <p>The field list may have an optional trailing separator, |
| 840 | 837 | as a convenience for machine-generated code. |
| 841 | 838 | |
| 842 | | −<p><a name="functioncall"><h3>2.5.7 - Function Calls</h3></a> |
| 839 | +<p><a name="functioncall"><a name="2.5.7"><h3>2.5.7 - Function Calls</h3></a></a> |
| 843 | 840 | A function call in Lua has the following syntax: |
| 844 | 841 | <pre> |
| 845 | 842 | functioncall ::= prefixexp args |
| @@ -944,12 +941,12 @@ So, all the following examples are not tails calls: · 98 unmodified lines |
| 944 | 941 | <PRE> |
| 945 | 942 | return (f(x)) -- results adjusted to 1 |
| 946 | 943 | return 2 * f(x) |
| 947 | | − return x, f(x) -- adicional results |
| 944 | + return x, f(x) -- additional results |
| 948 | 945 | f(x); return -- results discarded |
| 949 | 946 | return x or f(x) -- results adjusted to 1 |
| 950 | 947 | </PRE> |
| 951 | 948 | |
| 952 | | −<p><a name="func-def"><h3>2.5.8 - Function Definitions</h3></a> |
| 949 | +<p><a name="func-def"><a name="2.5.8"><h3>2.5.8 - Function Definitions</h3></a></a> |
| 953 | 950 | |
| 954 | 951 | <p>The syntax for function definition is |
| 955 | 952 | <pre> |
| @@ -1058,7 +1055,7 @@ is syntactic sugar for · 102 unmodified lines |
| 1058 | 1055 | t.a.b.c.f = function (self, ...) ... end |
| 1059 | 1056 | </PRE> |
| 1060 | 1057 | |
| 1061 | | −<p><a name="visibility"><h2>2.6 - Visibility Rules</h2></a> |
| 1058 | +<p><a name="visibility"><a name="2.6"><h2>2.6 - Visibility Rules</h2></a></a> |
| 1062 | 1059 | |
| 1063 | 1060 | |
| 1064 | 1061 | <p>Lua is a lexically scoped language. |
| @@ -1115,7 +1112,7 @@ The loop creates ten closures · 50 unmodified lines |
| 1115 | 1112 | Each of these closures uses a different <code>y</code> variable, |
| 1116 | 1113 | while all of them share the same <code>x</code>. |
| 1117 | 1114 | |
| 1118 | | −<p><a name="error"><h2>2.7 - Error Handling</h2></a> |
| 1115 | +<p><a name="error"><a name="2.7"><h2>2.7 - Error Handling</h2></a></a> |
| 1119 | 1116 | |
| 1120 | 1117 | <p>Because Lua is an extension language, |
| 1121 | 1118 | all Lua actions start from C code in the host program |
| @@ -1130,7 +1127,7 @@ which can take appropriate measures · 8 unmodified lines |
| 1130 | 1127 | If you need to catch errors in Lua, |
| 1131 | 1128 | you can use the <code>pcall</code> function (see <a href="#pdf-pcall">5.1</a>). |
| 1132 | 1129 | |
| 1133 | | −<p><a name="metatable"><h2>2.8 - Metatables</h2></a> |
| 1130 | +<p><a name="metatable"><a name="2.8"><h2>2.8 - Metatables</h2></a></a> |
| 1134 | 1131 | |
| 1135 | 1132 | <p>Every table and userdata object in Lua may have a <em>metatable</em>. |
| 1136 | 1133 | This <em>metatable</em> is an ordinary Lua table |
| @@ -1312,7 +1309,7 @@ and the same metamethod for the selected operation. · 175 unmodified lines |
| 1312 | 1309 | The "eq" event is defined as follows: |
| 1313 | 1310 | <PRE> |
| 1314 | 1311 | function eq_event (op1, op2) |
| 1315 | | − if type(op1) ~= type(op2) then -- diferent types? |
| 1312 | + if type(op1) ~= type(op2) then -- different types? |
| 1316 | 1313 | return false -- different objects |
| 1317 | 1314 | end |
| 1318 | 1315 | if op1 == op2 then -- primitive equal? |
| @@ -1440,7 +1437,7 @@ called when Lua calls a value. · 121 unmodified lines |
| 1440 | 1437 | |
| 1441 | 1438 | <p></ul> |
| 1442 | 1439 | |
| 1443 | | −<p><a name="GC"><h2>2.9 - Garbage Collection</h2></a> |
| 1440 | +<p><a name="GC"><a name="2.9"><h2>2.9 - Garbage Collection</h2></a></a> |
| 1444 | 1441 | |
| 1445 | 1442 | <p>Lua does automatic memory management. |
| 1446 | 1443 | That means that |
| @@ -1471,7 +1468,7 @@ Using Lua code you have a more limited control over garbage-collection cycles, · 24 unmodified lines |
| 1471 | 1468 | through the <code>gcinfo</code> and <code>collectgarbage</code> functions |
| 1472 | 1469 | (see <a href="#predefined">5.1</a>). |
| 1473 | 1470 | |
| 1474 | | −<p><h3>2.9.1 - Garbage-Collection Metamethods</h3> |
| 1471 | +<p><a name="2.9.1"><h3>2.9.1 - Garbage-Collection Metamethods</h3></a> |
| 1475 | 1472 | |
| 1476 | 1473 | <p>Using the C API, |
| 1477 | 1474 | you can set garbage-collector metamethods for userdata (see <a href="#metatable">2.8</a>). |
| @@ -1503,7 +1500,7 @@ among those collected in that cycle. · 25 unmodified lines |
| 1503 | 1500 | That is, the first finalizer to be called is the one associated |
| 1504 | 1501 | with the userdata created last in the program. |
| 1505 | 1502 | |
| 1506 | | −<p><a name="weak-table"><h3>2.9.2 - Weak Tables</h3></a> |
| 1503 | +<p><a name="weak-table"><a name="2.9.2"><h3>2.9.2 - Weak Tables</h3></a></a> |
| 1507 | 1504 | |
| 1508 | 1505 | <p>A <em>weak table</em> is a table whose elements are |
| 1509 | 1506 | <em>weak references</em>. |
| @@ -1521,7 +1518,7 @@ In any case, if either the key or the value is collected, · 11 unmodified lines |
| 1521 | 1518 | the whole pair is removed from the table. |
| 1522 | 1519 | The weakness of a table is controlled by the value of the |
| 1523 | 1520 | <code>__mode</code> field of its metatable. |
| 1524 | | −If the <code>__mode</code> field is a string containing the character `<code>k</code>´, |
| 1521 | +If the <code>__mode</code> field is a string containing the character `<code>k</code>´, |
| 1525 | 1522 | the keys in the table are weak. |
| 1526 | 1523 | If <code>__mode</code> contains `<code>v</code>´, |
| 1527 | 1524 | the values in the table are weak. |
| @@ -1531,7 +1528,7 @@ you should not change the value of its field <code>__mode</code>. · 3 unmodified lines |
| 1531 | 1528 | Otherwise, the weak behavior of the tables controlled by this |
| 1532 | 1529 | metatable is undefined. |
| 1533 | 1530 | |
| 1534 | | −<p><a name="coroutine"><h2>2.10 - Coroutines</h2></a> |
| 1531 | +<p><a name="coroutine"><a name="2.10"><h2>2.10 - Coroutines</h2></a></a> |
| 1535 | 1532 | |
| 1536 | 1533 | <p>Lua supports coroutines, |
| 1537 | 1534 | also called <em>semi-coroutines</em> |
| @@ -1549,7 +1546,7 @@ returns a handle to it (an object of type <em>thread</em>); · 11 unmodified lines |
| 1549 | 1546 | it does not start the coroutine execution. |
| 1550 | 1547 | |
| 1551 | 1548 | <p>When you first call <code>coroutine.resume</code>, |
| 1552 | | −passing as argument the thread returned by <code>coroutine.create</code>, |
| 1549 | +passing as its first argument the thread returned by <code>coroutine.create</code>, |
| 1553 | 1550 | the coroutine starts its execution, |
| 1554 | 1551 | at the first line of its main function. |
| 1555 | 1552 | Extra arguments passed to <code>coroutine.resume</code> are given as |
| @@ -1630,7 +1627,7 @@ main false cannot resume dead coroutine · 74 unmodified lines |
| 1630 | 1627 | </PRE> |
| 1631 | 1628 | |
| 1632 | 1629 | <p> |
| 1633 | | −<a name="API"><h1>3 - The Application Program Interface</h1></a> |
| 1630 | +<a name="API"><a name="3"><h1>3 - The Application Program Interface</h1></a></a> |
| 1634 | 1631 | |
| 1635 | 1632 | |
| 1636 | 1633 | <p>This section describes the C API for Lua, that is, |
| @@ -1645,7 +1642,7 @@ All such macros use each of its arguments exactly once · 8 unmodified lines |
| 1645 | 1642 | (except for the first argument, which is always a Lua state), |
| 1646 | 1643 | and so do not generate hidden side-effects. |
| 1647 | 1644 | |
| 1648 | | −<p><a name="mangstate"><h2>3.1 - States</h2></a> |
| 1645 | +<p><a name="mangstate"><a name="3.1"><h2>3.1 - States</h2></a></a> |
| 1649 | 1646 | |
| 1650 | 1647 | <p>The Lua library is fully reentrant: |
| 1651 | 1648 | it has no global variables. |
| @@ -1681,7 +1678,7 @@ such as a daemon or a web server, · 29 unmodified lines |
| 1681 | 1678 | might need to release states as soon as they are not needed, |
| 1682 | 1679 | to avoid growing too large. |
| 1683 | 1680 | |
| 1684 | | −<p><h2>3.2 - The Stack and Indices</h2> |
| 1681 | +<p><a name="3.2"><h2>3.2 - The Stack and Indices</h2></a> |
| 1685 | 1682 | |
| 1686 | 1683 | <p>Lua uses a <em>virtual stack</em> to pass values to and from C. |
| 1687 | 1684 | Each element in this stack represents a Lua value |
| @@ -1691,7 +1688,7 @@ Each element in this stack represents a Lua value · 3 unmodified lines |
| 1691 | 1688 | which is independent of previous stacks and of stacks of |
| 1692 | 1689 | C functions that are still active. |
| 1693 | 1690 | That stack initially contains any arguments to the C function, |
| 1694 | | −and it is where the C function pushes its results (see <a href="#LuacallC">3.16</a>) |
| 1691 | +and it is where the C function pushes its results to be returned to the caller (see <a href="#LuacallC">3.16</a>) |
| 1695 | 1692 | to be returned to the caller. |
| 1696 | 1693 | |
| 1697 | 1694 | <p>For convenience, |
| @@ -1736,7 +1733,7 @@ if the stack is already larger than the new size, · 38 unmodified lines |
| 1736 | 1733 | it is left unchanged. |
| 1737 | 1734 | |
| 1738 | 1735 | <p>Whenever Lua calls C, |
| 1739 | | −it ensures that at least <code>LUA_MINSTACK</code> positions are available. |
| 1736 | +it ensures that at least <code>LUA_MINSTACK</code> stack positions are available. |
| 1740 | 1737 | <code>LUA_MINSTACK</code> is defined in <code>lua.h</code> as 20, |
| 1741 | 1738 | so that usually you do not have to worry about stack space |
| 1742 | 1739 | unless your code has loops pushing elements onto the stack. |
| @@ -1760,7 +1757,7 @@ but are not in the stack. · 17 unmodified lines |
| 1760 | 1757 | Pseudo-indices are used to access the global environment, |
| 1761 | 1758 | the registry, and the upvalues of a C function (see <a href="#c-closure">3.17</a>). |
| 1762 | 1759 | |
| 1763 | | −<p><h2>3.3 - Stack Manipulation</h2> |
| 1760 | +<p><a name="3.3"><h2>3.3 - Stack Manipulation</h2></a> |
| 1764 | 1761 | The API offers the following functions for basic stack manipulation: |
| 1765 | 1762 | <PRE> |
| 1766 | 1763 | void lua_settop (lua_State *L, int index); |
| @@ -1813,7 +1810,7 @@ then · 46 unmodified lines |
| 1813 | 1810 | lua_settop(L, 6) --> 30 40 nil nil nil nil* |
| 1814 | 1811 | </PRE> |
| 1815 | 1812 | |
| 1816 | | −<p><h2>3.4 - Querying the Stack</h2> |
| 1813 | +<p><a name="3.4"><h2>3.4 - Querying the Stack</h2></a> |
| 1817 | 1814 | |
| 1818 | 1815 | <p>To check the type of a stack element, |
| 1819 | 1816 | the following functions are available: |
| @@ -1887,7 +1884,7 @@ are equivalent to their counterparts in Lua (see <a href="#rel-ops">2.5.2</a>). · 67 unmodified lines |
| 1887 | 1884 | without metamethods. |
| 1888 | 1885 | These functions return 0 (false) if any of the indices are non-valid. |
| 1889 | 1886 | |
| 1890 | | −<p><a name="lua-to"><h2>3.5 - Getting Values from the Stack</h2></a> |
| 1887 | +<p><a name="lua-to"><a name="3.5"><h2>3.5 - Getting Values from the Stack</h2></a></a> |
| 1891 | 1888 | |
| 1892 | 1889 | <p>To translate a value in the stack to a specific C type, |
| 1893 | 1890 | you can use the following conversion functions: |
| @@ -1966,7 +1963,7 @@ Typically this function is used for debug information. · 72 unmodified lines |
| 1966 | 1963 | |
| 1967 | 1964 | <p><code>lua_touserdata</code> is explained in <a href="#userdata">3.8</a>. |
| 1968 | 1965 | |
| 1969 | | −<p><a name="pushing"><h2>3.6 - Pushing Values onto the Stack</h2></a> |
| 1966 | +<p><a name="pushing"><a name="3.6"><h2>3.6 - Pushing Values onto the Stack</h2></a></a> |
| 1970 | 1967 | |
| 1971 | 1968 | <p>The API has the following functions to |
| 1972 | 1969 | push C values onto the stack: |
| @@ -1996,8 +1993,7 @@ which accepts an explicit size. · 23 unmodified lines |
| 1996 | 1993 | <p>You can also push "formatted" strings: |
| 1997 | 1994 | <PRE> |
| 1998 | 1995 | const char *lua_pushfstring (lua_State *L, const char *fmt, ...); |
| 1999 | | − const char *lua_pushvfstring (lua_State *L, const char *fmt, |
| 2000 | | − va_list argp); |
| 1996 | + const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp); |
| 2001 | 1997 | </PRE> |
| 2002 | 1998 | |
| 2003 | 1999 | These functions push onto the stack a formatted string |
| @@ -2025,13 +2021,13 @@ The conversion specifiers can be simply · 21 unmodified lines |
| 2025 | 2021 | |
| 2026 | 2022 | concatenates the <code>n</code> values at the top of the stack, |
| 2027 | 2023 | pops them, and leaves the result at the top. |
| 2028 | | −If <code>n</code> is 1, the result is that single string |
| 2024 | +If <code>n</code> is 1, the result is that single string |
| 2029 | 2025 | (that is, the function does nothing); |
| 2030 | 2026 | if <code>n</code> is 0, the result is the empty string. |
| 2031 | 2027 | Concatenation is done following the usual semantics of Lua |
| 2032 | 2028 | (see <a href="#concat">2.5.4</a>). |
| 2033 | 2029 | |
| 2034 | | −<p><a name="GC-API"><h2>3.7 - Controlling Garbage Collection</h2></a> |
| 2030 | +<p><a name="GC-API"><a name="3.7"><h2>3.7 - Controlling Garbage Collection</h2></a></a> |
| 2035 | 2031 | |
| 2036 | 2032 | <p>Lua uses two numbers to control its garbage collection: |
| 2037 | 2033 | the <em>count</em> and the <em>threshold</em> (see <a href="#GC">2.9</a>). |
| @@ -2044,7 +2040,7 @@ and the threshold is set to twice the count value. · 6 unmodified lines |
| 2044 | 2040 | <p>You can access the current values of these two numbers through the |
| 2045 | 2041 | following functions: |
| 2046 | 2042 | <PRE> |
| 2047 | | − int lua_getgccount (lua_State *L); |
| 2043 | + int lua_getgccount (lua_State *L); |
| 2048 | 2044 | int lua_getgcthreshold (lua_State *L); |
| 2049 | 2045 | </PRE> |
| 2050 | 2046 | |
| @@ -2064,7 +2060,7 @@ In particular · 13 unmodified lines |
| 2064 | 2060 | After the collection, |
| 2065 | 2061 | a new threshold is set according to the previous rule. |
| 2066 | 2062 | |
| 2067 | | −<p><a name="userdata"><h2>3.8 - Userdata</h2></a> |
| 2063 | +<p><a name="userdata"><a name="3.8"><h2>3.8 - Userdata</h2></a></a> |
| 2068 | 2064 | |
| 2069 | 2065 | <p>Userdata represents C values in Lua. |
| 2070 | 2066 | Lua supports two types of userdata: |
| @@ -2109,7 +2105,7 @@ when applied on a non-userdata value, it returns <code>NULL</code>. · 38 unmodified lines |
| 2109 | 2105 | it calls the userdata's <code>gc</code> metamethod, if any, |
| 2110 | 2106 | and then it frees the userdata's corresponding memory. |
| 2111 | 2107 | |
| 2112 | | −<p><h2>3.9 - Metatables</h2> |
| 2108 | +<p><a name="3.9"><h2>3.9 - Metatables</h2></a> |
| 2113 | 2109 | |
| 2114 | 2110 | <p>The following functions allow you to manipulate the metatables |
| 2115 | 2111 | of an object: |
| @@ -2130,7 +2126,7 @@ set the metatable of the given object · 14 unmodified lines |
| 2130 | 2126 | (that is, when the object is neither a userdata nor a table); |
| 2131 | 2127 | even then it pops the table from the stack. |
| 2132 | 2128 | |
| 2133 | | −<p><h2>3.10 - Loading Lua Chunks</h2> |
| 2129 | +<p><a name="3.10"><h2>3.10 - Loading Lua Chunks</h2></a> |
| 2134 | 2130 | |
| 2135 | 2131 | <p>You can load a Lua chunk with <code>lua_load</code>: |
| 2136 | 2132 | <PRE> |
| @@ -2157,9 +2153,9 @@ Otherwise, it pushes an error message. · 20 unmodified lines |
| 2157 | 2153 | <p><code>lua_load</code> automatically detects whether the chunk is text or binary, |
| 2158 | 2154 | and loads it accordingly (see program <code>luac</code>). |
| 2159 | 2155 | |
| 2160 | | −<p><code>lua_load</code> uses an user-supplied <em>reader</em> function to read the chunk. |
| 2156 | +<p><code>lua_load</code> uses a user-supplied <em>reader</em> function to read the chunk. |
| 2161 | 2157 | Everytime it needs another piece of the chunk, |
| 2162 | | −it calls the reader, |
| 2158 | +<code>lua_load</code> calls the reader, |
| 2163 | 2159 | passing along its <code>data</code> parameter. |
| 2164 | 2160 | The reader must return a pointer to a block of memory |
| 2165 | 2161 | with a new piece of the chunk |
| @@ -2179,7 +2175,7 @@ for examples of how to use <code>lua_load</code> · 13 unmodified lines |
| 2179 | 2175 | and for some ready-to-use functions to load chunks |
| 2180 | 2176 | from files and strings. |
| 2181 | 2177 | |
| 2182 | | −<p><h2>3.11 - Manipulating Tables</h2> |
| 2178 | +<p><a name="3.11"><h2>3.11 - Manipulating Tables</h2></a> |
| 2183 | 2179 | |
| 2184 | 2180 | <p>Tables are created by calling |
| 2185 | 2181 | the function |
| @@ -2260,7 +2256,7 @@ unless you know that the key is actually a string. · 74 unmodified lines |
| 2260 | 2256 | Recall that <code>lua_tostring</code> <em>changes</em> the value at the given index; |
| 2261 | 2257 | this confuses the next call to <code>lua_next</code>. |
| 2262 | 2258 | |
| 2263 | | −<p><a name="globals"><h2>3.12 - Manipulating Environments</h2></a> |
| 2259 | +<p><a name="globals"><a name="3.12"><h2>3.12 - Manipulating Environments</h2></a></a> |
| 2264 | 2260 | |
| 2265 | 2261 | <p>All global variables are kept in ordinary Lua tables, |
| 2266 | 2262 | called environments. |
| @@ -2292,7 +2288,7 @@ the new environment for the function at index <code>index</code> in the stack. · 25 unmodified lines |
| 2292 | 2288 | If the object at the given index is not a Lua function, |
| 2293 | 2289 | <code>lua_setfenv</code> returns 0. |
| 2294 | 2290 | |
| 2295 | | −<p><h2>3.13 - Using Tables as Arrays</h2> |
| 2291 | +<p><a name="3.13"><h2>3.13 - Using Tables as Arrays</h2></a> |
| 2296 | 2292 | The API has functions that help to use Lua tables as arrays, |
| 2297 | 2293 | that is, |
| 2298 | 2294 | tables indexed by numbers only: |
| @@ -2309,7 +2305,7 @@ at stack position <code>index</code>. · 10 unmodified lines |
| 2309 | 2305 | at stack position <code>index</code> to the value at the top of the stack, |
| 2310 | 2306 | removing this value from the stack. |
| 2311 | 2307 | |
| 2312 | | −<p><h2>3.14 - Calling Functions</h2> |
| 2308 | +<p><a name="3.14"><h2>3.14 - Calling Functions</h2></a> |
| 2313 | 2309 | |
| 2314 | 2310 | <p>Functions defined in Lua |
| 2315 | 2311 | and C functions registered in Lua |
| @@ -2364,7 +2360,7 @@ Usually programmers define and use several macros and auxiliary functions · 48 unmodified lines |
| 2364 | 2360 | that provide higher level access to Lua. |
| 2365 | 2361 | See the source code of the standard libraries for examples.) |
| 2366 | 2362 | |
| 2367 | | −<p><a name="lua_pcall"><h2>3.15 - Protected Calls</h2></a> |
| 2363 | +<p><a name="lua_pcall"><a name="3.15"><h2>3.15 - Protected Calls</h2></a></a> |
| 2368 | 2364 | |
| 2369 | 2365 | <p>When you call a function with <code>lua_call</code>, |
| 2370 | 2366 | any error inside the called function is propagated upwards |
| @@ -2411,7 +2407,7 @@ For such errors, Lua does not call the error handler function. · 40 unmodified lines |
| 2411 | 2407 | error while running the error handler function. |
| 2412 | 2408 | </ul> |
| 2413 | 2409 | |
| 2414 | | −<p><a name="LuacallC"><h2>3.16 - Defining C Functions</h2></a> |
| 2410 | +<p><a name="LuacallC"><a name="3.16"><h2>3.16 - Defining C Functions</h2></a></a> |
| 2415 | 2411 | |
| 2416 | 2412 | <p>Lua can be extended with functions written in C. |
| 2417 | 2413 | These functions must be of type <code>lua_CFunction</code>, |
| @@ -2479,7 +2475,7 @@ the C function <code>foo</code> above may be registered in Lua as · 61 unmodified lines |
| 2479 | 2475 | lua_register(L, "average", foo); |
| 2480 | 2476 | </PRE> |
| 2481 | 2477 | |
| 2482 | | −<p><a name="c-closure"><h2>3.17 - Defining C Closures</h2></a> |
| 2478 | +<p><a name="c-closure"><a name="3.17"><h2>3.17 - Defining C Closures</h2></a></a> |
| 2483 | 2479 | |
| 2484 | 2480 | <p>When a C function is created, |
| 2485 | 2481 | it is possible to associate some values with it, |
| @@ -2514,7 +2510,7 @@ produces an acceptable (but invalid) index. · 28 unmodified lines |
| 2514 | 2510 | see the standard libraries in the official Lua distribution |
| 2515 | 2511 | (<code>src/lib/*.c</code>). |
| 2516 | 2512 | |
| 2517 | | −<p><a name="registry"><h2>3.18 - Registry</h2></a> |
| 2513 | +<p><a name="registry"><a name="3.18"><h2>3.18 - Registry</h2></a></a> |
| 2518 | 2514 | |
| 2519 | 2515 | <p>Lua provides a registry, |
| 2520 | 2516 | a pre-defined table that can be used by any C code to |
| @@ -2532,26 +2528,26 @@ or a light userdata with the address of a C object in your code. · 11 unmodified lines |
| 2532 | 2528 | implemented by the auxiliary library, |
| 2533 | 2529 | and therefore should not be used by other purposes. |
| 2534 | 2530 | |
| 2535 | | −<p><h2>3.19 - Error Handling in C</h2> |
| 2531 | +<p><a name="3.19"><h2>3.19 - Error Handling in C</h2></a> |
| 2536 | 2532 | |
| 2537 | 2533 | <p>Internally, Lua uses the C <code>longjmp</code> facility to handle errors. |
| 2538 | 2534 | When Lua faces any error |
| 2539 | 2535 | (such as memory allocation errors, type errors, syntax errors) |
| 2540 | 2536 | it <em>raises</em> an error, that is, it does a long jump. |
| 2541 | 2537 | A <em>protected environment</em> uses <code>setjmp</code> |
| 2542 | | −to set a recover point, |
| 2543 | | −and any error jumps to the most recent active recover point. |
| 2538 | +to set a recover point; |
| 2539 | +any error jumps to the most recent active recover point. |
| 2544 | 2540 | |
| 2545 | 2541 | <p>If an error happens outside any protected environment, |
| 2546 | | −Lua calls a <em>panic function</em>, |
| 2542 | +Lua calls a <em>panic function</em> |
| 2547 | 2543 | and then calls <code>exit(EXIT_FAILURE)</code>. |
| 2548 | 2544 | You can change the panic function with |
| 2549 | 2545 | <PRE> |
| 2550 | 2546 | lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf); |
| 2551 | 2547 | </PRE> |
| 2552 | 2548 | Your new panic function may avoid the application exit by |
| 2553 | | −never returning (e.g. doing a long jump). |
| 2554 | | −Nevertheless, the corresponding Lua will not be consistent; |
| 2549 | +never returning (e.g., by doing a long jump). |
| 2550 | +Nevertheless, the corresponding Lua state will not be consistent; |
| 2555 | 2551 | the only safe operation with it is to close it. |
| 2556 | 2552 | |
| 2557 | 2553 | <p>Almost any function in the API may raise an error, |
| @@ -2575,7 +2571,7 @@ In case of errors, · 17 unmodified lines |
| 2575 | 2571 | (see <a href="#lua_pcall">3.15</a>), |
| 2576 | 2572 | plus the error object on the top of the stack; |
| 2577 | 2573 | otherwise, it returns zero, and does not change the stack. |
| 2578 | | −Any value returned by <code>func</code> is dicarded. |
| 2574 | +Any value returned by <code>func</code> is discarded. |
| 2579 | 2575 | |
| 2580 | 2576 | <p>C code can generate a Lua error calling the function |
| 2581 | 2577 | <PRE> |
| @@ -2587,7 +2583,7 @@ must be on the stack top. · 5 unmodified lines |
| 2587 | 2583 | This function does a long jump, |
| 2588 | 2584 | and therefore never returns. |
| 2589 | 2585 | |
| 2590 | | −<p><h2>3.20 - Threads</h2> |
| 2586 | +<p><a name="3.20"><h2>3.20 - Threads</h2></a> |
| 2591 | 2587 | |
| 2592 | 2588 | <p>Lua offers partial support for multiple threads of execution. |
| 2593 | 2589 | If you have a C library that offers multi-threading, |
| @@ -2608,18 +2604,15 @@ but has an independent run-time stack. · 14 unmodified lines |
| 2608 | 2604 | When you create a thread, this table is the same as that of the given state, |
| 2609 | 2605 | but you can change each one independently. |
| 2610 | 2606 | |
| 2611 | | −<p>You destroy threads with <code>lua_closethread</code>: |
| 2612 | | −<PRE> |
| 2613 | | − void lua_closethread (lua_State *L, lua_State *thread); |
| 2614 | | −</PRE> |
| 2615 | | −You cannot close the sole (or last) thread of a state. |
| 2616 | | −Instead, you must close the state itself. |
| 2607 | +<p>There is no explicit function to close or to destroy a thread. |
| 2608 | +Threads are subject to garbage collection, |
| 2609 | +like any Lua object. |
| 2617 | 2610 | |
| 2618 | 2611 | <p>To manipulate threads as coroutines, |
| 2619 | 2612 | Lua offers the following functions: |
| 2620 | 2613 | <PRE> |
| 2621 | 2614 | int lua_resume (lua_State *L, int narg); |
| 2622 | | − int lua_yield (lua_State *L, int nresults); |
| 2615 | + int lua_yield (lua_State *L, int nresults); |
| 2623 | 2616 | </PRE> |
| 2624 | 2617 | |
| 2625 | 2618 | To start a coroutine, you first create a new thread; |
| @@ -2629,7 +2622,7 @@ with <code>narg</code> being the number of arguments. · 3 unmodified lines |
| 2629 | 2622 | This call returns when the coroutine suspends or finishes its execution. |
| 2630 | 2623 | When it returns, the stack contains all values passed to <code>lua_yield</code>, |
| 2631 | 2624 | or all values returned by the body function. |
| 2632 | | −<code>lua_resume</code> returns 0 if there is no errors running the coroutine, |
| 2625 | +<code>lua_resume</code> returns 0 if there are no errors running the coroutine, |
| 2633 | 2626 | or an error code (see <a href="#lua_pcall">3.15</a>). |
| 2634 | 2627 | In case of errors, |
| 2635 | 2628 | the stack contains only the error message. |
| @@ -2657,7 +2650,7 @@ It pops <code>n</code> values from the stack <code>from</code>, · 21 unmodified lines |
| 2657 | 2650 | and puhses them into the stack <code>to</code>. |
| 2658 | 2651 | |
| 2659 | 2652 | <p> |
| 2660 | | −<a name="debugI"><h1>4 - The Debug Interface</h1></a> |
| 2653 | +<a name="debugI"><a name="4"><h1>4 - The Debug Interface</h1></a></a> |
| 2661 | 2654 | |
| 2662 | 2655 | <p>Lua has no built-in debugging facilities. |
| 2663 | 2656 | Instead, it offers a special interface |
| @@ -2666,7 +2659,7 @@ This interface allows the construction of different · 2 unmodified lines |
| 2666 | 2659 | kinds of debuggers, profilers, and other tools |
| 2667 | 2660 | that need "inside information" from the interpreter. |
| 2668 | 2661 | |
| 2669 | | −<p><h2>4.1 - Stack and Function Information</h2> |
| 2662 | +<p><a name="4.1"><h2>4.1 - Stack and Function Information</h2></a> |
| 2670 | 2663 | |
| 2671 | 2664 | <p>The main function to get information about the interpreter runtime stack is |
| 2672 | 2665 | <PRE> |
| @@ -2678,7 +2671,7 @@ an identification of the <em>activation record</em> · 5 unmodified lines |
| 2678 | 2671 | of the function executing at a given level. |
| 2679 | 2672 | Level 0 is the current running function, |
| 2680 | 2673 | whereas level <em>n+1</em> is the function that has called level <em>n</em>. |
| 2681 | | −When there is no errors, <code>lua_getstack</code> returns 1; |
| 2674 | +When there are no errors, <code>lua_getstack</code> returns 1; |
| 2682 | 2675 | when called with a level greater than the stack depth, |
| 2683 | 2676 | it returns 0. |
| 2684 | 2677 | |
| @@ -2786,7 +2779,7 @@ The number of upvalues of the function. · 101 unmodified lines |
| 2786 | 2779 | |
| 2787 | 2780 | <p></ul> |
| 2788 | 2781 | |
| 2789 | | −<p><h2>4.2 - Manipulating Local Variables and Upvalues</h2> |
| 2782 | +<p><a name="4.2"><h2>4.2 - Manipulating Local Variables and Upvalues</h2></a> |
| 2790 | 2783 | |
| 2791 | 2784 | <p>For the manipulation of local variables and upvalues, |
| 2792 | 2785 | the debug interface uses indices: |
| @@ -2863,7 +2856,7 @@ local variables and upvalues for a function at a given level of the stack: · 70 unmodified lines |
| 2863 | 2856 | } |
| 2864 | 2857 | </PRE> |
| 2865 | 2858 | |
| 2866 | | −<p><a name="sub-hooks"><h2>4.3 - Hooks</h2></a> |
| 2859 | +<p><a name="sub-hooks"><a name="4.3"><h2>4.3 - Hooks</h2></a></a> |
| 2867 | 2860 | |
| 2868 | 2861 | <p>Lua offers a mechanism of hooks, which are |
| 2869 | 2862 | user-defined C functions that are called during the program execution. |
| @@ -2939,7 +2932,7 @@ Therefore, if a hook calls back Lua to execute a function or a chunk, · 69 unmodified lines |
| 2939 | 2932 | that execution occurs without any calls to hooks. |
| 2940 | 2933 | |
| 2941 | 2934 | <p> |
| 2942 | | −<a name="libraries"><h1>5 - Standard Libraries</h1></a> |
| 2935 | +<a name="libraries"><a name="5"><h1>5 - Standard Libraries</h1></a></a> |
| 2943 | 2936 | |
| 2944 | 2937 | <p>The standard libraries provide useful functions |
| 2945 | 2938 | that are implemented directly through the C API. |
| @@ -2982,7 +2975,7 @@ These functions are declared in <code>lualib.h</code>. · 36 unmodified lines |
| 2982 | 2975 | |
| 2983 | 2976 | |
| 2984 | 2977 | |
| 2985 | | −<p><a name="predefined"><h2>5.1 - Basic Functions</h2></a> |
| 2978 | +<p><a name="predefined"><a name="5.1"><h2>5.1 - Basic Functions</h2></a></a> |
| 2986 | 2979 | |
| 2987 | 2980 | <p>The basic library provides some core functions to Lua. |
| 2988 | 2981 | If you do not include this library in your application, |
| @@ -3015,7 +3008,7 @@ to its caller (that is, it does not run in protected mode). · 26 unmodified lines |
| 3015 | 3008 | |
| 3016 | 3009 | <p><a name="pdf-error"><h3><code>error (message [, level])</code></h3></a> |
| 3017 | 3010 | |
| 3018 | | −Terminates the last protected function called, |
| 3011 | +Terminates the last protected function called |
| 3019 | 3012 | and returns <code>message</code> as the error message. |
| 3020 | 3013 | Function <code>error</code> never returns. |
| 3021 | 3014 | |
| @@ -3043,7 +3036,7 @@ or if <code>f</code> is 0, · 21 unmodified lines |
| 3043 | 3036 | <code>getfenv</code> returns the global environment. |
| 3044 | 3037 | The default for <code>f</code> is 1. |
| 3045 | 3038 | |
| 3046 | | −<p>if the environment has a <code>"__fenv"</code> field, |
| 3039 | +<p>If the environment has a <code>"__fenv"</code> field, |
| 3047 | 3040 | returns the associated value, instead of the environment. |
| 3048 | 3041 | |
| 3049 | 3042 | <p><a name="pdf-getmetatable"><h3><code>getmetatable (object)</code></h3></a> |
| @@ -3148,11 +3141,11 @@ will iterate over all key-value pairs of table <code>t</code>. · 98 unmodified lines |
| 3148 | 3141 | |
| 3149 | 3142 | <p>Calls function <code>f</code> with |
| 3150 | 3143 | the given arguments in protected mode. |
| 3151 | | −That means that any error inside <code>f</code> is not propagated; |
| 3144 | +That means that any error inside <code>f</code> is not propagated; |
| 3152 | 3145 | instead, <code>pcall</code> catches the error |
| 3153 | 3146 | and returns a status code. |
| 3154 | 3147 | Its first result is the status code (a boolean), |
| 3155 | | −which is true if the call succeeds without errors. |
| 3148 | +which is <B>true</B> if the call succeeds without errors. |
| 3156 | 3149 | In such case, <code>pcall</code> also returns all results from the call, |
| 3157 | 3150 | after this first result. |
| 3158 | 3151 | In case of any error, <code>pcall</code> returns <B>false</B> plus the error message. |
| @@ -3327,10 +3320,10 @@ after this first result. · 168 unmodified lines |
| 3327 | 3320 | In case of any error, |
| 3328 | 3321 | <code>xpcall</code> returns false plus the result from <code>err</code>. |
| 3329 | 3322 | |
| 3330 | | −<p><h2>5.2 - Coroutine Manipulation</h2> |
| 3323 | +<p><a name="5.2"><h2>5.2 - Coroutine Manipulation</h2></a> |
| 3331 | 3324 | |
| 3332 | 3325 | <p>The operations related to coroutines comprise a sub-library of |
| 3333 | | −the basic library, and come inside the table . |
| 3326 | +the basic library and come inside the table <code>coroutine</code>. |
| 3334 | 3327 | See <a href="#coroutine">2.10</a> for a general description of coroutines. |
| 3335 | 3328 | |
| 3336 | 3329 | <p><h3><code>coroutine.create (f)</code></h3> |
| @@ -3385,7 +3378,7 @@ The coroutine cannot be running neither a C function, · 48 unmodified lines |
| 3385 | 3378 | nor a metamethod, nor an iterator. |
| 3386 | 3379 | Any arguments to <code>yield</code> go as extra results to <code>resume</code>. |
| 3387 | 3380 | |
| 3388 | | −<p><h2>5.3 - String Manipulation</h2> |
| 3381 | +<p><a name="5.3"><h2>5.3 - String Manipulation</h2></a> |
| 3389 | 3382 | This library provides generic functions for string manipulation, |
| 3390 | 3383 | such as finding and extracting substrings, and pattern matching. |
| 3391 | 3384 | When indexing a string in Lua, the first character is at position 1 |
| @@ -3592,7 +3585,7 @@ For instance, when <code>n</code> is 1 only the first occurrence of · 200 unmodified lines |
| 3592 | 3585 | <p><a name="pm"><h3>Patterns</h3></a> |
| 3593 | 3586 | |
| 3594 | 3587 | <p><p> |
| 3595 | | −a <em>character class</em> is used to represent a set of characters. |
| 3588 | +A <em>character class</em> is used to represent a set of characters. |
| 3596 | 3589 | The following combinations are allowed in describing a character class: |
| 3597 | 3590 | <ul> |
| 3598 | 3591 | <li><b><em>x</em></b> (where <em>x</em> is not one of the magic characters |
| @@ -3648,7 +3641,7 @@ In particular, the class <code>[a-z]</code> may not be equivalent to <code>%l</c · 49 unmodified lines |
| 3648 | 3641 | The second form should be preferred for portability. |
| 3649 | 3642 | |
| 3650 | 3643 | <p><p> |
| 3651 | | −a <em>pattern item</em> may be |
| 3644 | +A <em>pattern item</em> may be |
| 3652 | 3645 | <ul> |
| 3653 | 3646 | <li> |
| 3654 | 3647 | a single character class, |
| @@ -3685,7 +3678,7 @@ balanced parentheses. · 30 unmodified lines |
| 3685 | 3678 | </ul> |
| 3686 | 3679 | |
| 3687 | 3680 | <p><p> |
| 3688 | | −a <em>pattern</em> is a sequence of pattern items. |
| 3681 | +A <em>pattern</em> is a sequence of pattern items. |
| 3689 | 3682 | A `<code>^</code>´ at the beginning of a pattern anchors the match at the |
| 3690 | 3683 | beginning of the subject string. |
| 3691 | 3684 | A `<code>$</code>´ at the end of a pattern anchors the match at the |
| @@ -3712,7 +3705,7 @@ string <code>"flaaap"</code>, there will be two captures: 3 and 5. · 20 unmodified lines |
| 3712 | 3705 | |
| 3713 | 3706 | <p>A pattern cannot contain embedded zeros. Use <code>%z</code> instead. |
| 3714 | 3707 | |
| 3715 | | −<p><h2>5.4 - Table Manipulation</h2> |
| 3708 | +<p><a name="5.4"><h2>5.4 - Table Manipulation</h2></a> |
| 3716 | 3709 | This library provides generic functions for table manipulation. |
| 3717 | 3710 | It provides all its functions inside the table <code>table</code>. |
| 3718 | 3711 | |
| @@ -3821,7 +3814,7 @@ that value is changed to the given <code>n</code>. · 102 unmodified lines |
| 3821 | 3814 | Otherwise, it updates an internal state |
| 3822 | 3815 | so that subsequent calls to <code>table.getn(table)</code> return <code>n</code>. |
| 3823 | 3816 | |
| 3824 | | −<p><a name="mathlib"><h2>5.5 - Mathematical Functions</h2></a> |
| 3817 | +<p><a name="mathlib"><a name="5.5"><h2>5.5 - Mathematical Functions</h2></a></a> |
| 3825 | 3818 | |
| 3826 | 3819 | <p>This library is an interface to most of the functions of the |
| 3827 | 3820 | standard C math library. |
| @@ -3876,7 +3869,7 @@ The <code>math.randomseed</code> function sets a "seed" · 48 unmodified lines |
| 3876 | 3869 | for the pseudo-random generator: |
| 3877 | 3870 | Equal seeds produce equal sequences of numbers. |
| 3878 | 3871 | |
| 3879 | | −<p><a name="libio"><h2>5.6 - Input and Output Facilities</h2></a> |
| 3872 | +<p><a name="libio"><a name="5.6"><h2>5.6 - Input and Output Facilities</h2></a></a> |
| 3880 | 3873 | |
| 3881 | 3874 | <p>The I/O library provides two different styles for file manipulation. |
| 3882 | 3875 | The first one uses implicit file descriptors, |
| @@ -4069,7 +4062,7 @@ The arguments must be strings or numbers. · 186 unmodified lines |
| 4069 | 4062 | To write other values, |
| 4070 | 4063 | use <code>tostring</code> or <code>string.format</code> before <code>write</code>. |
| 4071 | 4064 | |
| 4072 | | −<p><a name="libiosys"><h2>5.7 - Operating System Facilities</h2></a> |
| 4065 | +<p><a name="libiosys"><a name="5.7"><h2>5.7 - Operating System Facilities</h2></a></a> |
| 4073 | 4066 | |
| 4074 | 4067 | <p>This library is implemented through table <code>os</code>. |
| 4075 | 4068 | |
| @@ -4095,7 +4088,7 @@ if <code>format</code> is <code>*t</code>, · 19 unmodified lines |
| 4095 | 4088 | then <code>date</code> returns a table with the following fields: |
| 4096 | 4089 | <code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31), |
| 4097 | 4090 | <code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61), |
| 4098 | | −<code>wday</code> (weekday, Sunday is 1), |
| 4091 | +<code>wday</code> (weekday, Sunday is 1), |
| 4099 | 4092 | <code>yday</code> (day of the year), |
| 4100 | 4093 | and <code>isdst</code> (daylight saving flag, a boolean). |
| 4101 | 4094 | |
| @@ -4184,7 +4177,7 @@ and the time you open the file, · 82 unmodified lines |
| 4184 | 4177 | it is possible for another process |
| 4185 | 4178 | to create a file with the same name. |
| 4186 | 4179 | |
| 4187 | | −<p><h2>5.8 - The Reflexive Debug Interface</h2> |
| 4180 | +<p><a name="5.8"><h2>5.8 - The Reflexive Debug Interface</h2></a> |
| 4188 | 4181 | |
| 4189 | 4182 | <p>The <code>debug</code> library provides |
| 4190 | 4183 | the functionality of the debug interface to Lua programs. |
| @@ -4320,7 +4313,7 @@ This function is typically used with <code>xpcall</code> to produce · 129 unmodified lines |
| 4320 | 4313 | better error messages. |
| 4321 | 4314 | |
| 4322 | 4315 | <p> |
| 4323 | | −<a name="lua-sa"><h1>6 - Lua Stand-alone</h1></a> |
| 4316 | +<a name="lua-sa"><a name="6"><h1>6 - Lua Stand-alone</h1></a></a> |
| 4324 | 4317 | |
| 4325 | 4318 | <p>Although Lua has been designed as an extension language, |
| 4326 | 4319 | to be embedded in a host C program, |
| @@ -4459,7 +4452,7 @@ Stephan Herrmann, · 132 unmodified lines |
| 4459 | 4452 | Steve Dekorte, |
| 4460 | 4453 | Thatcher Ulrich, |
| 4461 | 4454 | Tomás Gorham, |
| 4462 | | −Vincent Penquerc'h, |
| 4455 | +Vincent Penquerc'h. |
| 4463 | 4456 | Thank you! |
| 4464 | 4457 | |
| 4465 | 4458 | <p><hr> |
| @@ -4580,7 +4573,7 @@ Use <code>lua_newuserdata</code> or <code>lua_pushlightuserdata</code> instead. · 114 unmodified lines |
| 4580 | 4573 | |
| 4581 | 4574 | <p> explist1 ::= {exp `<b>,</b>´} exp |
| 4582 | 4575 | |
| 4583 | | −<p> exp ::= <b>nil</b> <b>false</b> <b>true</b> | Number | Literal | function | prefixexp | tableconstructor | exp binop exp | unop exp |
| 4576 | +<p> exp ::= <b>nil</b> | <b>false</b> | <b>true</b> | Number | Literal | function | prefixexp | tableconstructor | exp binop exp | unop exp |
| 4584 | 4577 | |
| 4585 | 4578 | <p> prefixexp ::= var | functioncall | `<b>(</b>´ exp `<b>)</b>´ |
| 4586 | 4579 | |
| @@ -4609,5 +4602,11 @@ Use <code>lua_newuserdata</code> or <code>lua_pushlightuserdata</code> instead. · 22 unmodified lines |
| 4609 | 4602 | |
| 4610 | 4603 | <p> |
| 4611 | 4604 | |
| 4612 | | −</body></html> |
| 4605 | +<HR> |
| 4606 | +<SMALL> |
| 4607 | +Last update: |
| 4608 | +Tue Nov 25 16:08:37 BRST 2003 |
| 4609 | +</SMALL> |
| 4613 | 4610 | |
| 4611 | +</BODY> |
| 4612 | +</HTML> |