| @@ -4,6 +4,7 @@ · 3 unmodified lines |
| 4 | 4 | <head> |
| 5 | 5 | <title>Lua 5.1 Reference Manual</title> |
| 6 | 6 | <link rel="stylesheet" href="lua.css"> |
| 7 | +<link rel="stylesheet" href="manual.css"> |
| 7 | 8 | </head> |
| 8 | 9 | |
| 9 | 10 | <body> |
| @@ -17,10 +18,16 @@ Lua 5.1 Reference Manual · 7 unmodified lines |
| 17 | 18 | by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes |
| 18 | 19 | <p> |
| 19 | 20 | <small> |
| 20 | | −<a href="http://www.lua.org/copyright.html">Copyright</a> |
| 21 | | −© 2006 Lua.org, PUC-Rio. All rights reserved. |
| 21 | +Copyright © 2006-2007 Lua.org, PUC-Rio. |
| 22 | +Freely available under the terms of the |
| 23 | +<a href="http://www.lua.org/license.html#5">Lua license</a>. |
| 22 | 24 | </small> |
| 23 | 25 | <hr> |
| 26 | +<p> |
| 27 | + |
| 28 | +<a href="contents.html#contents">contents</A> |
| 29 | +· |
| 30 | +<a href="contents.html#index">index</A> |
| 24 | 31 | |
| 25 | 32 | <!-- ====================================================================== --> |
| 26 | 33 | <p> |
| @@ -71,7 +78,7 @@ this document is dry in places. · 44 unmodified lines |
| 71 | 78 | For a discussion of the decisions behind the design of Lua, |
| 72 | 79 | see the technical papers available at Lua's web site. |
| 73 | 80 | For a detailed introduction to programming in Lua, |
| 74 | | −see Roberto's book, <em>Programming in Lua</em>. |
| 81 | +see Roberto's book, <em>Programming in Lua (Second Edition)</em>. |
| 75 | 82 | |
| 76 | 83 | |
| 77 | 84 | |
| @@ -390,8 +397,8 @@ Name denotes identifiers, as defined in <a href="#2.1">§2.1</a>. · 312 unmodified lines |
| 390 | 397 | |
| 391 | 398 | |
| 392 | 399 | <p> |
| 393 | | −Variables are assumed to be global unless explicitly declared local |
| 394 | | −(see <a href="#2.4.7">§2.4.7</a>). |
| 400 | +Any variable is assumed to be global unless explicitly declared |
| 401 | +as a local (see <a href="#2.4.7">§2.4.7</a>). |
| 395 | 402 | Local variables are <em>lexically scoped</em>: |
| 396 | 403 | local variables can be freely accessed by functions |
| 397 | 404 | defined inside their scope (see <a href="#2.6">§2.6</a>). |
| @@ -708,18 +715,18 @@ third <em>exp</em>. · 310 unmodified lines |
| 708 | 715 | More precisely, a <b>for</b> statement like |
| 709 | 716 | |
| 710 | 717 | <pre> |
| 711 | | − for var = e1, e2, e3 do block end |
| 718 | + for v = <em>e1</em>, <em>e2</em>, <em>e3</em> do <em>block</em> end |
| 712 | 719 | </pre><p> |
| 713 | 720 | is equivalent to the code: |
| 714 | 721 | |
| 715 | 722 | <pre> |
| 716 | 723 | do |
| 717 | | − local _var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3) |
| 718 | | − if not (_var and _limit and _step) then error() end |
| 719 | | − while (_step>0 and _var<=_limit) or (_step<=0 and _var>=_limit) do |
| 720 | | − local var = _var |
| 724 | + local <em>var</em>, <em>limit</em>, <em>step</em> = tonumber(<em>e1</em>), tonumber(<em>e2</em>), tonumber(<em>e3</em>) |
| 725 | + if not (<em>var</em> and <em>limit</em> and <em>step</em>) then error() end |
| 726 | + while (<em>step</em> > 0 and <em>var</em> <= <em>limit</em>) or (<em>step</em> <= 0 and <em>var</em> >= <em>limit</em>) do |
| 727 | + local v = <em>var</em> |
| 721 | 728 | <em>block</em> |
| 722 | | − _var = _var + _step |
| 729 | + <em>var</em> = <em>var</em> + <em>step</em> |
| 723 | 730 | end |
| 724 | 731 | end |
| 725 | 732 | </pre><p> |
| @@ -734,7 +741,7 @@ They must all result in numbers. · 8 unmodified lines |
| 734 | 741 | </li> |
| 735 | 742 | |
| 736 | 743 | <li> |
| 737 | | −<code>_var</code>, <code>_limit</code>, and <code>_step</code> are invisible variables. |
| 744 | +<code><em>var</em></code>, <code><em>limit</em></code>, and <code><em>step</em></code> are invisible variables. |
| 738 | 745 | The names are here for explanatory purposes only. |
| 739 | 746 | </li> |
| 740 | 747 | |
| @@ -748,10 +755,10 @@ You can use <b>break</b> to exit a <b>for</b> loop. · 7 unmodified lines |
| 748 | 755 | </li> |
| 749 | 756 | |
| 750 | 757 | <li> |
| 751 | | −The loop variable <code>var</code> is local to the loop; |
| 758 | +The loop variable <code>v</code> is local to the loop; |
| 752 | 759 | you cannot use its value after the <b>for</b> ends or is broken. |
| 753 | | −If you need the value of the loop variable <code>var</code>, |
| 754 | | −then assign it to another variable before breaking or exiting the loop. |
| 760 | +If you need this value, |
| 761 | +assign it to another variable before breaking or exiting the loop. |
| 755 | 762 | </li> |
| 756 | 763 | |
| 757 | 764 | </ul> |
| @@ -770,18 +777,18 @@ The generic <b>for</b> loop has the following syntax: · 12 unmodified lines |
| 770 | 777 | A <b>for</b> statement like |
| 771 | 778 | |
| 772 | 779 | <pre> |
| 773 | | − for var_1, ···, var_n in explist do block end |
| 780 | + for <em>var_1</em>, ···, <em>var_n</em> in <em>explist</em> do <em>block</em> end |
| 774 | 781 | </pre><p> |
| 775 | 782 | is equivalent to the code: |
| 776 | 783 | |
| 777 | 784 | <pre> |
| 778 | 785 | do |
| 779 | | − local _f, _s, _var = explist |
| 786 | + local <em>f</em>, <em>s</em>, <em>var</em> = <em>explist</em> |
| 780 | 787 | while true do |
| 781 | | − local var_1, ···, var_n = _f(_s, _var) |
| 782 | | − _var = var_1 |
| 783 | | − if _var == nil then break end |
| 784 | | − block |
| 788 | + local <em>var_1</em>, ···, <em>var_n</em> = <em>f</em>(<em>s</em>, <em>var</em>) |
| 789 | + <em>var</em> = <em>var_1</em> |
| 790 | + if <em>var</em> == nil then break end |
| 791 | + <em>block</em> |
| 785 | 792 | end |
| 786 | 793 | end |
| 787 | 794 | </pre><p> |
| @@ -790,13 +797,14 @@ Note the following: · 2 unmodified lines |
| 790 | 797 | <ul> |
| 791 | 798 | |
| 792 | 799 | <li> |
| 793 | | −<code>explist</code> is evaluated only once. |
| 800 | +<code><em>explist</em></code> is evaluated only once. |
| 794 | 801 | Its results are an <em>iterator</em> function, |
| 795 | | −a <em>state</em>, and an initial value for the first <em>iterator variable</em>. |
| 802 | +a <em>state</em>, |
| 803 | +and an initial value for the first <em>iterator variable</em>. |
| 796 | 804 | </li> |
| 797 | 805 | |
| 798 | 806 | <li> |
| 799 | | −<code>_f</code>, <code>_s</code>, and <code>_var</code> are invisible variables. |
| 807 | +<code><em>f</em></code>, <code><em>s</em></code>, and <code><em>var</em></code> are invisible variables. |
| 800 | 808 | The names are here for explanatory purposes only. |
| 801 | 809 | </li> |
| 802 | 810 | |
| @@ -805,7 +813,7 @@ You can use <b>break</b> to exit a <b>for</b> loop. · 2 unmodified lines |
| 805 | 813 | </li> |
| 806 | 814 | |
| 807 | 815 | <li> |
| 808 | | −The loop variables <code>var_i</code> are local to the loop; |
| 816 | +The loop variables <code><em>var_i</em></code> are local to the loop; |
| 809 | 817 | you cannot use their values after the <b>for</b> ends. |
| 810 | 818 | If you need these values, |
| 811 | 819 | then assign them to other variables before breaking or exiting the loop. |
| @@ -902,13 +910,13 @@ If the expression is used as a statement (see <a href="#2.4.6">§2.4.6</a>) · 90 unmodified lines |
| 902 | 910 | (only possible for function calls), |
| 903 | 911 | then its return list is adjusted to zero elements, |
| 904 | 912 | thus discarding all returned values. |
| 905 | | −If the expression is used inside another expression |
| 906 | | −or in the middle of a list of expressions, |
| 907 | | −then its result list is adjusted to one element, |
| 908 | | −thus discarding all values except the first one. |
| 909 | | −If the expression is used as the last element of a list of expressions, |
| 910 | | −then no adjustment is made, |
| 911 | | −unless the call is enclosed in parentheses. |
| 913 | +If the expression is used as the last (or the only) element |
| 914 | +of a list of expressions, |
| 915 | +then no adjustment is made |
| 916 | +(unless the call is enclosed in parentheses). |
| 917 | +In all other contexts, |
| 918 | +Lua adjusts the result list to one element, |
| 919 | +discarding all values except the first one. |
| 912 | 920 | |
| 913 | 921 | |
| 914 | 922 | <p> |
| @@ -917,17 +925,18 @@ Here are some examples: · 2 unmodified lines |
| 917 | 925 | <pre> |
| 918 | 926 | f() -- adjusted to 0 results |
| 919 | 927 | g(f(), x) -- f() is adjusted to 1 result |
| 920 | | − g(x, f()) -- g gets x plus all values returned by f() |
| 928 | + g(x, f()) -- g gets x plus all results from f() |
| 921 | 929 | a,b,c = f(), x -- f() is adjusted to 1 result (c gets nil) |
| 922 | 930 | a,b = ... -- a gets the first vararg parameter, b gets |
| 923 | | − -- the second (both a and b may get nil if there is |
| 924 | | − -- no corresponding vararg parameter) |
| 931 | + -- the second (both a and b may get nil if there |
| 932 | + -- is no corresponding vararg parameter) |
| 933 | + |
| 925 | 934 | a,b,c = x, f() -- f() is adjusted to 2 results |
| 926 | 935 | a,b,c = f() -- f() is adjusted to 3 results |
| 927 | | − return f() -- returns all values returned by f() |
| 936 | + return f() -- returns all results from f() |
| 928 | 937 | return ... -- returns all received vararg parameters |
| 929 | | − return x,y,f() -- returns x, y, and all values returned by f() |
| 930 | | − {f()} -- creates a list with all values returned by f() |
| 938 | + return x,y,f() -- returns x, y, and all results from f() |
| 939 | + {f()} -- creates a list with all results from f() |
| 931 | 940 | {...} -- creates a list with all vararg parameters |
| 932 | 941 | {f(), nil} -- f() is adjusted to 1 result |
| 933 | 942 | </pre> |
| @@ -1543,8 +1552,7 @@ you must use the C API for that. · 609 unmodified lines |
| 1543 | 1552 | |
| 1544 | 1553 | <p> |
| 1545 | 1554 | Tables and userdata have individual metatables |
| 1546 | | −(although multiple tables and userdata can share |
| 1547 | | −a same table as their metatable); |
| 1555 | +(although multiple tables and userdata can share their metatables); |
| 1548 | 1556 | values of all other types share one single metatable per type. |
| 1549 | 1557 | So, there is one single metatable for all numbers, |
| 1550 | 1558 | and for all strings, etc. |
| @@ -1592,6 +1600,7 @@ This should be read as · 41 unmodified lines |
| 1592 | 1600 | <pre> |
| 1593 | 1601 | rawget(getmetatable(obj) or {}, event) |
| 1594 | 1602 | </pre><p> |
| 1603 | + |
| 1595 | 1604 | That is, the access to a metamethod does not invoke other metamethods, |
| 1596 | 1605 | and the access to objects with no metatables does not fail |
| 1597 | 1606 | (it simply results in <b>nil</b>). |
| @@ -2077,7 +2086,7 @@ A table with both weak keys and weak values allows the collection of · 479 unmodified lines |
| 2077 | 2086 | both keys and values. |
| 2078 | 2087 | In any case, if either the key or the value is collected, |
| 2079 | 2088 | the whole pair is removed from the table. |
| 2080 | | −The weakness of a table is controlled by the value of the |
| 2089 | +The weakness of a table is controlled by the |
| 2081 | 2090 | <code>__mode</code> field of its metatable. |
| 2082 | 2091 | If the <code>__mode</code> field is a string containing the character '<code>k</code>', |
| 2083 | 2092 | the keys in the table are weak. |
| @@ -2156,8 +2165,8 @@ arguments passed to <a href="#pdf-coroutine.resume"><code>coroutine.resume</code · 72 unmodified lines |
| 2156 | 2165 | |
| 2157 | 2166 | |
| 2158 | 2167 | <p> |
| 2159 | | −The <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function creates a coroutine, |
| 2160 | | −just like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>, |
| 2168 | +Like <a href="#pdf-coroutine.create"><code>coroutine.create</code></a>, |
| 2169 | +the <a href="#pdf-coroutine.wrap"><code>coroutine.wrap</code></a> function also creates a coroutine, |
| 2161 | 2170 | but instead of returning the coroutine itself, |
| 2162 | 2171 | it returns a function that, when called, resumes the coroutine. |
| 2163 | 2172 | Any arguments passed to this function |
| @@ -2198,6 +2207,7 @@ When you run it, it produces the following output: · 34 unmodified lines |
| 2198 | 2207 | <pre> |
| 2199 | 2208 | co-body 1 10 |
| 2200 | 2209 | foo 2 |
| 2210 | + |
| 2201 | 2211 | main true 4 |
| 2202 | 2212 | co-body r |
| 2203 | 2213 | main true 11 -9 |
| @@ -2268,7 +2278,7 @@ then index 1 represents the first element · 64 unmodified lines |
| 2268 | 2278 | and |
| 2269 | 2279 | index <em>n</em> represents the last element; |
| 2270 | 2280 | index -1 also represents the last element |
| 2271 | | −(that is, the element at the top) |
| 2281 | +(that is, the element at the top) |
| 2272 | 2282 | and index <em>-n</em> represents the first element. |
| 2273 | 2283 | We say that an index is <em>valid</em> |
| 2274 | 2284 | if it lies between 1 and the stack top |
| @@ -2473,21 +2483,25 @@ Lua assumes that the allocator never fails when · 198 unmodified lines |
| 2473 | 2483 | |
| 2474 | 2484 | <p> |
| 2475 | 2485 | Here is a simple implementation for the allocator function. |
| 2476 | | −It is used in the auxiliary library by <a href="#lua_newstate"><code>lua_newstate</code></a>. |
| 2486 | +It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newstate</code></a>. |
| 2477 | 2487 | |
| 2478 | 2488 | <pre> |
| 2479 | | − static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { |
| 2480 | | − (void)ud; /* not used */ |
| 2481 | | − (void)osize; /* not used */ |
| 2489 | + static void *l_alloc (void *ud, void *ptr, size_t osize, |
| 2490 | + size_t nsize) { |
| 2491 | + (void)ud; (void)osize; /* not used */ |
| 2482 | 2492 | if (nsize == 0) { |
| 2483 | | − free(ptr); /* ANSI requires that free(NULL) has no effect */ |
| 2493 | + free(ptr); |
| 2484 | 2494 | return NULL; |
| 2485 | 2495 | } |
| 2486 | 2496 | else |
| 2487 | | − /* ANSI requires that realloc(NULL, size) == malloc(size) */ |
| 2488 | 2497 | return realloc(ptr, nsize); |
| 2489 | 2498 | } |
| 2490 | | −</pre> |
| 2499 | +</pre><p> |
| 2500 | +This code assumes |
| 2501 | +that <code>free(NULL)</code> has no effect and that |
| 2502 | +<code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>. |
| 2503 | +ANSI C ensures both behaviors. |
| 2504 | + |
| 2491 | 2505 | |
| 2492 | 2506 | |
| 2493 | 2507 | |
| @@ -2557,14 +2571,14 @@ equivalent to this Lua code: · 63 unmodified lines |
| 2557 | 2571 | Here it is in C: |
| 2558 | 2572 | |
| 2559 | 2573 | <pre> |
| 2560 | | − lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */ |
| 2561 | | − lua_pushstring(L, "how"); /* 1st argument */ |
| 2562 | | − lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */ |
| 2563 | | − lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */ |
| 2564 | | − lua_remove(L, -2); /* remove 't' from the stack */ |
| 2565 | | − lua_pushinteger(L, 14); /* 3rd argument */ |
| 2566 | | − lua_call(L, 3, 1); /* call function with 3 arguments and 1 result */ |
| 2567 | | − lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable 'a' */ |
| 2574 | + lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */ |
| 2575 | + lua_pushstring(L, "how"); /* 1st argument */ |
| 2576 | + lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */ |
| 2577 | + lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */ |
| 2578 | + lua_remove(L, -2); /* remove 't' from the stack */ |
| 2579 | + lua_pushinteger(L, 14); /* 3rd argument */ |
| 2580 | + lua_call(L, 3, 1); /* call 'f' with 3 arguments and 1 result */ |
| 2581 | + lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global 'a' */ |
| 2568 | 2582 | </pre><p> |
| 2569 | 2583 | Note that the code above is "balanced": |
| 2570 | 2584 | at its end, the stack is back to its original configuration. |
| @@ -2611,7 +2625,7 @@ of numerical arguments and returns their average and sum: · 40 unmodified lines |
| 2611 | 2625 | int i; |
| 2612 | 2626 | for (i = 1; i <= n; i++) { |
| 2613 | 2627 | if (!lua_isnumber(L, i)) { |
| 2614 | | − lua_pushstring(L, "incorrect argument to function 'average'"); |
| 2628 | + lua_pushstring(L, "incorrect argument"); |
| 2615 | 2629 | lua_error(L); |
| 2616 | 2630 | } |
| 2617 | 2631 | sum += lua_tonumber(L, i); |
| @@ -2723,7 +2737,7 @@ to write them. · 105 unmodified lines |
| 2723 | 2737 | <p> |
| 2724 | 2738 | The value returned is the error code returned by the last |
| 2725 | 2739 | call to the writer; |
| 2726 | | −0 means no errors. |
| 2740 | +0 means no errors. |
| 2727 | 2741 | |
| 2728 | 2742 | |
| 2729 | 2743 | <p> |
| @@ -2814,7 +2828,7 @@ The function returns the previous value of the pause. · 84 unmodified lines |
| 2814 | 2828 | </li> |
| 2815 | 2829 | |
| 2816 | 2830 | <li><b><code>LUA_GCSETSTEPMUL</code>:</b> |
| 2817 | | −sets <code>arg</code>/100 as the new value for the <em>step multiplier</em> of |
| 2831 | +sets <code>data</code>/100 as the new value for the <em>step multiplier</em> of |
| 2818 | 2832 | the collector (see <a href="#2.10">§2.10</a>). |
| 2819 | 2833 | The function returns the previous value of the step multiplier. |
| 2820 | 2834 | </li> |
| @@ -2942,7 +2956,7 @@ The type used by the Lua API to represent integral values. · 121 unmodified lines |
| 2942 | 2956 | |
| 2943 | 2957 | <p> |
| 2944 | 2958 | By default it is a <code>ptrdiff_t</code>, |
| 2945 | | −which is usually the largest integral type the machine handles |
| 2959 | +which is usually the largest signed integral type the machine handles |
| 2946 | 2960 | "comfortably". |
| 2947 | 2961 | |
| 2948 | 2962 | |
| @@ -2954,7 +2968,7 @@ which is usually the largest integral type the machine handles · 5 unmodified lines |
| 2954 | 2968 | |
| 2955 | 2969 | <p> |
| 2956 | 2970 | Returns 1 if the value at the given acceptable index has type boolean, |
| 2957 | | −and 0 otherwise. |
| 2971 | +and 0 otherwise. |
| 2958 | 2972 | |
| 2959 | 2973 | |
| 2960 | 2974 | |
| @@ -2965,7 +2979,7 @@ and 0 otherwise. · 4 unmodified lines |
| 2965 | 2979 | |
| 2966 | 2980 | <p> |
| 2967 | 2981 | Returns 1 if the value at the given acceptable index is a C function, |
| 2968 | | −and 0 otherwise. |
| 2982 | +and 0 otherwise. |
| 2969 | 2983 | |
| 2970 | 2984 | |
| 2971 | 2985 | |
| @@ -2976,7 +2990,7 @@ and 0 otherwise. · 4 unmodified lines |
| 2976 | 2990 | |
| 2977 | 2991 | <p> |
| 2978 | 2992 | Returns 1 if the value at the given acceptable index is a function |
| 2979 | | −(either C or Lua), and 0 otherwise. |
| 2993 | +(either C or Lua), and 0 otherwise. |
| 2980 | 2994 | |
| 2981 | 2995 | |
| 2982 | 2996 | |
| @@ -2987,7 +3001,7 @@ Returns 1 if the value at the given acceptable index is a function · 4 unmodified lines |
| 2987 | 3001 | |
| 2988 | 3002 | <p> |
| 2989 | 3003 | Returns 1 if the value at the given acceptable index is a light userdata, |
| 2990 | | −and 0 otherwise. |
| 3004 | +and 0 otherwise. |
| 2991 | 3005 | |
| 2992 | 3006 | |
| 2993 | 3007 | |
| @@ -2998,7 +3012,32 @@ and 0 otherwise. · 4 unmodified lines |
| 2998 | 3012 | |
| 2999 | 3013 | <p> |
| 3000 | 3014 | Returns 1 if the value at the given acceptable index is <b>nil</b>, |
| 3001 | | −and 0 otherwise. |
| 3015 | +and 0 otherwise. |
| 3016 | + |
| 3017 | + |
| 3018 | + |
| 3019 | + |
| 3020 | + |
| 3021 | +<hr><h3><a name="lua_isnone"><code>lua_isnone</code></a></h3> |
| 3022 | +<pre>int lua_isnone (lua_State *L, int index);</pre> |
| 3023 | + |
| 3024 | +<p> |
| 3025 | +Returns 1 if the the given acceptable index is not valid |
| 3026 | +(that is, it refers to an element outside the current stack), |
| 3027 | +and 0 otherwise. |
| 3028 | + |
| 3029 | + |
| 3030 | + |
| 3031 | + |
| 3032 | + |
| 3033 | +<hr><h3><a name="lua_isnoneornil"><code>lua_isnoneornil</code></a></h3> |
| 3034 | +<pre>int lua_isnoneornil (lua_State *L, int index);</pre> |
| 3035 | + |
| 3036 | +<p> |
| 3037 | +Returns 1 if the the given acceptable index is not valid |
| 3038 | +(that is, it refers to an element outside the current stack) |
| 3039 | +or if the value at this index is <b>nil</b>, |
| 3040 | +and 0 otherwise. |
| 3002 | 3041 | |
| 3003 | 3042 | |
| 3004 | 3043 | |
| @@ -3010,7 +3049,7 @@ and 0 otherwise. · 5 unmodified lines |
| 3010 | 3049 | <p> |
| 3011 | 3050 | Returns 1 if the value at the given acceptable index is a number |
| 3012 | 3051 | or a string convertible to a number, |
| 3013 | | −and 0 otherwise. |
| 3052 | +and 0 otherwise. |
| 3014 | 3053 | |
| 3015 | 3054 | |
| 3016 | 3055 | |
| @@ -3022,7 +3061,7 @@ and 0 otherwise. · 5 unmodified lines |
| 3022 | 3061 | <p> |
| 3023 | 3062 | Returns 1 if the value at the given acceptable index is a string |
| 3024 | 3063 | or a number (which is always convertible to a string), |
| 3025 | | −and 0 otherwise. |
| 3064 | +and 0 otherwise. |
| 3026 | 3065 | |
| 3027 | 3066 | |
| 3028 | 3067 | |
| @@ -3033,7 +3072,7 @@ and 0 otherwise. · 4 unmodified lines |
| 3033 | 3072 | |
| 3034 | 3073 | <p> |
| 3035 | 3074 | Returns 1 if the value at the given acceptable index is a table, |
| 3036 | | −and 0 otherwise. |
| 3075 | +and 0 otherwise. |
| 3037 | 3076 | |
| 3038 | 3077 | |
| 3039 | 3078 | |
| @@ -3044,7 +3083,7 @@ and 0 otherwise. · 4 unmodified lines |
| 3044 | 3083 | |
| 3045 | 3084 | <p> |
| 3046 | 3085 | Returns 1 if the value at the given acceptable index is a thread, |
| 3047 | | −and 0 otherwise. |
| 3086 | +and 0 otherwise. |
| 3048 | 3087 | |
| 3049 | 3088 | |
| 3050 | 3089 | |
| @@ -3055,7 +3094,7 @@ and 0 otherwise. · 4 unmodified lines |
| 3055 | 3094 | |
| 3056 | 3095 | <p> |
| 3057 | 3096 | Returns 1 if the value at the given acceptable index is a userdata |
| 3058 | | −(either full or light), and 0 otherwise. |
| 3097 | +(either full or light), and 0 otherwise. |
| 3059 | 3098 | |
| 3060 | 3099 | |
| 3061 | 3100 | |
| @@ -3113,8 +3152,8 @@ and loads it accordingly (see program <code>luac</code>). · 51 unmodified lines |
| 3113 | 3152 | |
| 3114 | 3153 | |
| 3115 | 3154 | <p> |
| 3116 | | −<a href="#lua_load"><code>lua_load</code></a> uses a user-supplied <code>reader</code> function to read the chunk |
| 3117 | | −(see <a href="#lua_Reader"><code>lua_Reader</code></a>). |
| 3155 | +The <a href="#lua_load"><code>lua_load</code></a> function uses a user-supplied <code>reader</code> function |
| 3156 | +to read the chunk (see <a href="#lua_Reader"><code>lua_Reader</code></a>). |
| 3118 | 3157 | The <code>data</code> argument is an opaque value passed to the reader function. |
| 3119 | 3158 | |
| 3120 | 3159 | |
| @@ -3219,10 +3258,12 @@ A typical traversal looks like this: · 98 unmodified lines |
| 3219 | 3258 | /* table is in the stack at index 't' */ |
| 3220 | 3259 | lua_pushnil(L); /* first key */ |
| 3221 | 3260 | while (lua_next(L, t) != 0) { |
| 3222 | | − /* 'key' is at index -2 and 'value' at index -1 */ |
| 3261 | + /* uses 'key' (at index -2) and 'value' (at index -1) */ |
| 3223 | 3262 | printf("%s - %s\n", |
| 3224 | | − lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1))); |
| 3225 | | − lua_pop(L, 1); /* removes 'value'; keeps 'key' for next iteration */ |
| 3263 | + lua_typename(L, lua_type(L, -2)), |
| 3264 | + lua_typename(L, lua_type(L, -1))); |
| 3265 | + /* removes 'value'; keeps 'key' for next iteration */ |
| 3266 | + lua_pop(L, 1); |
| 3226 | 3267 | } |
| 3227 | 3268 | </pre> |
| 3228 | 3269 | |
| @@ -3270,7 +3311,7 @@ for other values, it is 0. · 41 unmodified lines |
| 3270 | 3311 | |
| 3271 | 3312 | |
| 3272 | 3313 | <hr><h3><a name="lua_pcall"><code>lua_pcall</code></a></h3> |
| 3273 | | −<pre>lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);</pre> |
| 3314 | +<pre>int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);</pre> |
| 3274 | 3315 | |
| 3275 | 3316 | <p> |
| 3276 | 3317 | Calls a function in protected mode. |
| @@ -3396,9 +3437,11 @@ and return its results (see <a href="#lua_CFunction"><code>lua_CFunction</code>< · 119 unmodified lines |
| 3396 | 3437 | |
| 3397 | 3438 | |
| 3398 | 3439 | <p> |
| 3399 | | −The call <code>lua_pushcfunction(L, f)</code> is equivalent to |
| 3400 | | −<code>lua_pushcclosure(L, f, 0)</code>. |
| 3440 | +<code>lua_pushcfunction</code> is defined as a macro: |
| 3401 | 3441 | |
| 3442 | +<pre> |
| 3443 | + #define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0) |
| 3444 | +</pre> |
| 3402 | 3445 | |
| 3403 | 3446 | |
| 3404 | 3447 | |
| @@ -3642,14 +3685,17 @@ The reader function may return pieces of any size greater than zero. · 237 unmodified lines |
| 3642 | 3685 | |
| 3643 | 3686 | |
| 3644 | 3687 | <hr><h3><a name="lua_register"><code>lua_register</code></a></h3> |
| 3645 | | −<pre>void lua_register (lua_State *L, const char *name, lua_CFunction f);</pre> |
| 3688 | +<pre>void lua_register (lua_State *L, |
| 3689 | + const char *name, |
| 3690 | + lua_CFunction f);</pre> |
| 3646 | 3691 | |
| 3647 | 3692 | <p> |
| 3648 | 3693 | Sets the C function <code>f</code> as the new value of global <code>name</code>. |
| 3649 | 3694 | It is defined as a macro: |
| 3650 | 3695 | |
| 3651 | 3696 | <pre> |
| 3652 | | − #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n)) |
| 3697 | + #define lua_register(L,n,f) \ |
| 3698 | + (lua_pushcfunction(L, f), lua_setglobal(L, n)) |
| 3653 | 3699 | </pre> |
| 3654 | 3700 | |
| 3655 | 3701 | |
| @@ -3905,8 +3951,7 @@ it is truncated in some non-specified way. · 249 unmodified lines |
| 3905 | 3951 | <pre>const char *lua_tolstring (lua_State *L, int index, size_t *len);</pre> |
| 3906 | 3952 | |
| 3907 | 3953 | <p> |
| 3908 | | −Converts the Lua value at the given acceptable index to a string |
| 3909 | | −(<code>const char*</code>). |
| 3954 | +Converts the Lua value at the given acceptable index to a C string. |
| 3910 | 3955 | If <code>len</code> is not <code>NULL</code>, |
| 3911 | 3956 | it also sets <code>*len</code> with the string length. |
| 3912 | 3957 | The Lua value must be a string or a number; |
| @@ -3937,7 +3982,7 @@ will be valid after the corresponding value is removed from the stack. · 24 unmodified lines |
| 3937 | 3982 | |
| 3938 | 3983 | <p> |
| 3939 | 3984 | Converts the Lua value at the given acceptable index |
| 3940 | | −to a number (see <a href="#lua_Number"><code>lua_Number</code></a>). |
| 3985 | +to the C type <a href="#lua_Number"><code>lua_Number</code></a> (see <a href="#lua_Number"><code>lua_Number</code></a>). |
| 3941 | 3986 | The Lua value must be a number or a string convertible to a number |
| 3942 | 3987 | (see <a href="#2.2.1">§2.2.1</a>); |
| 3943 | 3988 | otherwise, <a href="#lua_tonumber"><code>lua_tonumber</code></a> returns 0. |
| @@ -4054,7 +4099,7 @@ and the <code>data</code> parameter supplied to <a href="#lua_dump"><code>lua_du · 110 unmodified lines |
| 4054 | 4099 | |
| 4055 | 4100 | <p> |
| 4056 | 4101 | The writer returns an error code: |
| 4057 | | −0 means no errors; |
| 4102 | +0 means no errors; |
| 4058 | 4103 | any other value means an error and stops <a href="#lua_dump"><code>lua_dump</code></a> from |
| 4059 | 4104 | calling the writer again. |
| 4060 | 4105 | |
| @@ -4279,8 +4324,8 @@ a value to be pushed on the stack: · 218 unmodified lines |
| 4279 | 4324 | </li> |
| 4280 | 4325 | |
| 4281 | 4326 | <li><b>'<code>S</code>':</b> |
| 4282 | | −fills in the fields <code>source</code>, <code>linedefined</code>, |
| 4283 | | −<code>lastlinedefined</code>, <code>what</code>, and <code>short_src</code>; |
| 4327 | +fills in the fields <code>source</code>, <code>short_src</code>, |
| 4328 | +<code>linedefined</code>, <code>lastlinedefined</code>, and <code>what</code>; |
| 4284 | 4329 | </li> |
| 4285 | 4330 | |
| 4286 | 4331 | <li><b>'<code>l</code>':</b> fills in the field <code>currentline</code>; |
| @@ -4313,7 +4358,7 @@ This function returns 0 on error · 26 unmodified lines |
| 4313 | 4358 | |
| 4314 | 4359 | |
| 4315 | 4360 | <hr><h3><a name="lua_getlocal"><code>lua_getlocal</code></a></h3> |
| 4316 | | −<pre>const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);</pre> |
| 4361 | +<pre>const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);</pre> |
| 4317 | 4362 | |
| 4318 | 4363 | <p> |
| 4319 | 4364 | Gets information about a local variable of a given activation record. |
| @@ -4424,14 +4469,14 @@ this execution occurs without any calls to hooks. · 104 unmodified lines |
| 4424 | 4469 | |
| 4425 | 4470 | |
| 4426 | 4471 | <hr><h3><a name="lua_sethook"><code>lua_sethook</code></a></h3> |
| 4427 | | −<pre>int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);</pre> |
| 4472 | +<pre>int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);</pre> |
| 4428 | 4473 | |
| 4429 | 4474 | <p> |
| 4430 | 4475 | Sets the debugging hook function. |
| 4431 | 4476 | |
| 4432 | 4477 | |
| 4433 | 4478 | <p> |
| 4434 | | −<code>func</code> is the hook function. |
| 4479 | +Argument <code>f</code> is the hook function. |
| 4435 | 4480 | <code>mask</code> specifies on which events the hook will be called: |
| 4436 | 4481 | it is formed by a bitwise or of the constants |
| 4437 | 4482 | <a name="pdf-LUA_MASKCALL"><code>LUA_MASKCALL</code></a>, |
| @@ -4475,7 +4520,7 @@ A hook is disabled by setting <code>mask</code> to zero. · 37 unmodified lines |
| 4475 | 4520 | |
| 4476 | 4521 | |
| 4477 | 4522 | <hr><h3><a name="lua_setlocal"><code>lua_setlocal</code></a></h3> |
| 4478 | | −<pre>const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);</pre> |
| 4523 | +<pre>const char *lua_setlocal (lua_State *L, lua_Debug *ar, int n);</pre> |
| 4479 | 4524 | |
| 4480 | 4525 | <p> |
| 4481 | 4526 | Sets the value of a local variable of a given activation record. |
| @@ -4500,11 +4545,11 @@ the number of active local variables. · 18 unmodified lines |
| 4500 | 4545 | |
| 4501 | 4546 | <p> |
| 4502 | 4547 | Sets the value of a closure's upvalue. |
| 4503 | | −Parameters <code>funcindex</code> and <code>n</code> are as in <a href="#lua_getupvalue"><code>lua_getupvalue</code></a> |
| 4504 | | −(see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>). |
| 4505 | 4548 | It assigns the value at the top of the stack |
| 4506 | 4549 | to the upvalue and returns its name. |
| 4507 | 4550 | It also pops the value from the stack. |
| 4551 | +Parameters <code>funcindex</code> and <code>n</code> are as in the <a href="#lua_getupvalue"><code>lua_getupvalue</code></a> |
| 4552 | +(see <a href="#lua_getupvalue"><code>lua_getupvalue</code></a>). |
| 4508 | 4553 | |
| 4509 | 4554 | |
| 4510 | 4555 | <p> |
| @@ -4588,9 +4633,9 @@ The string may contain embedded zeros. · 77 unmodified lines |
| 4588 | 4633 | <pre>void luaL_addsize (luaL_Buffer *B, size_t n);</pre> |
| 4589 | 4634 | |
| 4590 | 4635 | <p> |
| 4591 | | −Adds a string of length <code>n</code> previously copied to the |
| 4592 | | −buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>) to the buffer <code>B</code> |
| 4593 | | −(see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>). |
| 4636 | +Adds to the buffer <code>B</code> (see <a href="#luaL_Buffer"><code>luaL_Buffer</code></a>) |
| 4637 | +a string of length <code>n</code> previously copied to the |
| 4638 | +buffer area (see <a href="#luaL_prepbuffer"><code>luaL_prepbuffer</code></a>). |
| 4594 | 4639 | |
| 4595 | 4640 | |
| 4596 | 4641 | |
| @@ -4631,7 +4676,7 @@ which is the value to be added to the buffer. · 34 unmodified lines |
| 4631 | 4676 | <hr><h3><a name="luaL_argcheck"><code>luaL_argcheck</code></a></h3> |
| 4632 | 4677 | <pre>void luaL_argcheck (lua_State *L, |
| 4633 | 4678 | int cond, |
| 4634 | | − int numarg, |
| 4679 | + int narg, |
| 4635 | 4680 | const char *extramsg);</pre> |
| 4636 | 4681 | |
| 4637 | 4682 | <p> |
| @@ -4640,21 +4685,21 @@ If not, raises an error with the following message, · 2 unmodified lines |
| 4640 | 4685 | where <code>func</code> is retrieved from the call stack: |
| 4641 | 4686 | |
| 4642 | 4687 | <pre> |
| 4643 | | − bad argument #<numarg> to <func> (<extramsg>) |
| 4688 | + bad argument #<narg> to <func> (<extramsg>) |
| 4644 | 4689 | </pre> |
| 4645 | 4690 | |
| 4646 | 4691 | |
| 4647 | 4692 | |
| 4648 | 4693 | |
| 4649 | 4694 | <hr><h3><a name="luaL_argerror"><code>luaL_argerror</code></a></h3> |
| 4650 | | −<pre>int luaL_argerror (lua_State *L, int numarg, const char *extramsg);</pre> |
| 4695 | +<pre>int luaL_argerror (lua_State *L, int narg, const char *extramsg);</pre> |
| 4651 | 4696 | |
| 4652 | 4697 | <p> |
| 4653 | 4698 | Raises an error with the following message, |
| 4654 | 4699 | where <code>func</code> is retrieved from the call stack: |
| 4655 | 4700 | |
| 4656 | 4701 | <pre> |
| 4657 | | − bad argument #<numarg> to <func> (<extramsg>) |
| 4702 | + bad argument #<narg> to <func> (<extramsg>) |
| 4658 | 4703 | </pre> |
| 4659 | 4704 | |
| 4660 | 4705 | <p> |
| @@ -5079,9 +5124,10 @@ with <code>tname</code> in the registry. · 418 unmodified lines |
| 5079 | 5124 | <pre>lua_State *luaL_newstate (void);</pre> |
| 5080 | 5125 | |
| 5081 | 5126 | <p> |
| 5082 | | −Creates a new Lua state, calling <a href="#lua_newstate"><code>lua_newstate</code></a> with an |
| 5083 | | −allocation function based on the standard C <code>realloc</code> function |
| 5084 | | −and setting a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints |
| 5127 | +Creates a new Lua state. |
| 5128 | +It calls <a href="#lua_newstate"><code>lua_newstate</code></a> with an |
| 5129 | +allocator based on the standard C <code>realloc</code> function |
| 5130 | +and then sets a panic function (see <a href="#lua_atpanic"><code>lua_atpanic</code></a>) that prints |
| 5085 | 5131 | an error message to the standard error output in case of fatal |
| 5086 | 5132 | errors. |
| 5087 | 5133 | |
| @@ -5119,7 +5165,9 @@ Otherwise, raises an error. · 31 unmodified lines |
| 5119 | 5165 | |
| 5120 | 5166 | |
| 5121 | 5167 | <hr><h3><a name="luaL_optinteger"><code>luaL_optinteger</code></a></h3> |
| 5122 | | −<pre>lua_Integer luaL_optinteger (lua_State *L, int narg, lua_Integer d);</pre> |
| 5168 | +<pre>lua_Integer luaL_optinteger (lua_State *L, |
| 5169 | + int narg, |
| 5170 | + lua_Integer d);</pre> |
| 5123 | 5171 | |
| 5124 | 5172 | <p> |
| 5125 | 5173 | If the function argument <code>narg</code> is a number, |
| @@ -5183,7 +5231,9 @@ Otherwise, raises an error. · 57 unmodified lines |
| 5183 | 5231 | |
| 5184 | 5232 | |
| 5185 | 5233 | <hr><h3><a name="luaL_optstring"><code>luaL_optstring</code></a></h3> |
| 5186 | | −<pre>const char *luaL_optstring (lua_State *L, int narg, const char *d);</pre> |
| 5234 | +<pre>const char *luaL_optstring (lua_State *L, |
| 5235 | + int narg, |
| 5236 | + const char *d);</pre> |
| 5187 | 5237 | |
| 5188 | 5238 | <p> |
| 5189 | 5239 | If the function argument <code>narg</code> is a string, |
| @@ -5285,7 +5335,7 @@ it simply registers all functions in the list <code>l</code> · 95 unmodified lines |
| 5285 | 5335 | |
| 5286 | 5336 | <p> |
| 5287 | 5337 | When called with a non-null <code>libname</code>, |
| 5288 | | −creates a new table <code>t</code>, |
| 5338 | +<code>luaL_register</code> creates a new table <code>t</code>, |
| 5289 | 5339 | sets it as the value of the global variable <code>libname</code>, |
| 5290 | 5340 | sets it as the value of <code>package.loaded[libname]</code>, |
| 5291 | 5341 | and registers on it all functions in the list <code>l</code>. |
| @@ -5316,14 +5366,14 @@ Returns the name of the type of the value at index <code>idx</code>. · 24 unmodified lines |
| 5316 | 5366 | <pre>int luaL_typerror (lua_State *L, int narg, const char *tname);</pre> |
| 5317 | 5367 | |
| 5318 | 5368 | <p> |
| 5319 | | −Generates an error with a message like |
| 5369 | +Generates an error with a message like the following: |
| 5320 | 5370 | |
| 5321 | 5371 | <pre> |
| 5322 | | − <location>: bad argument <narg> to <function> (<tname> expected, got <realt>) |
| 5372 | + <em>location</em>: bad argument <em>narg</em> to '<em>func</em>' (<em>tname</em> expected, got <em>rt</em>) |
| 5323 | 5373 | </pre><p> |
| 5324 | | −where <code><location></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>, |
| 5325 | | −<code><function></code> is the name of the current function, |
| 5326 | | −and <code><realt></code> is the type name of the actual argument. |
| 5374 | +where <code><em>location</em></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>, |
| 5375 | +<code><em>func</em></code> is the name of the current function, |
| 5376 | +and <code><em>rt</em></code> is the type name of the actual argument. |
| 5327 | 5377 | |
| 5328 | 5378 | |
| 5329 | 5379 | |
| @@ -5354,7 +5404,11 @@ If <code>ref</code> is <a href="#pdf-LUA_NOREF"><code>LUA_NOREF</code></a> or <a · 24 unmodified lines |
| 5354 | 5404 | <p> |
| 5355 | 5405 | Pushes onto the stack a string identifying the current position |
| 5356 | 5406 | of the control at level <code>lvl</code> in the call stack. |
| 5357 | | −Typically this string has the format <code><chunkname>:<currentline>:</code>. |
| 5407 | +Typically this string has the following format: |
| 5408 | + |
| 5409 | +<pre> |
| 5410 | + <em>chunkname</em>:<em>currentline</em>: |
| 5411 | +</pre><p> |
| 5358 | 5412 | Level 0 is the running function, |
| 5359 | 5413 | level 1 is the function that called the running function, |
| 5360 | 5414 | etc. |
| @@ -5413,9 +5467,8 @@ or as methods of its objects. · 52 unmodified lines |
| 5413 | 5467 | |
| 5414 | 5468 | <p> |
| 5415 | 5469 | To have access to these libraries, |
| 5416 | | −the C host program must call |
| 5417 | | −<a href="#luaL_openlibs"><code>luaL_openlibs</code></a>, |
| 5418 | | −which open all standard libraries. |
| 5470 | +the C host program should call the <a href="#luaL_openlibs"><code>luaL_openlibs</code></a> function, |
| 5471 | +which opens all standard libraries. |
| 5419 | 5472 | Alternatively, |
| 5420 | 5473 | it can open them individually by calling |
| 5421 | 5474 | <a name="pdf-luaopen_base"><code>luaopen_base</code></a> (for the basic library), |
| @@ -5547,7 +5600,7 @@ nor vice-versa. · 125 unmodified lines |
| 5547 | 5600 | |
| 5548 | 5601 | |
| 5549 | 5602 | <p> |
| 5550 | | −<hr><h3><a name="pdf-getfenv"><code>getfenv (f)</code></a></h3> |
| 5603 | +<hr><h3><a name="pdf-getfenv"><code>getfenv ([f])</code></a></h3> |
| 5551 | 5604 | Returns the current environment in use by the function. |
| 5552 | 5605 | <code>f</code> can be a Lua function or a number |
| 5553 | 5606 | that specifies the function at that stack level: |
| @@ -5589,10 +5642,6 @@ will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), &middo · 35 unmodified lines |
| 5589 | 5642 | up to the first integer key absent from the table. |
| 5590 | 5643 | |
| 5591 | 5644 | |
| 5592 | | −<p> |
| 5593 | | −See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal. |
| 5594 | | − |
| 5595 | | − |
| 5596 | 5645 | |
| 5597 | 5646 | |
| 5598 | 5647 | <p> |
| @@ -5704,7 +5753,8 @@ will iterate over all key–value pairs of table <code>t</code>. · 105 unmodified lines |
| 5704 | 5753 | |
| 5705 | 5754 | |
| 5706 | 5755 | <p> |
| 5707 | | −See <a href="#pdf-next"><code>next</code></a> for the caveats of modifying the table during its traversal. |
| 5756 | +See function <a href="#pdf-next"><code>next</code></a> for the caveats of modifying |
| 5757 | +the table during its traversal. |
| 5708 | 5758 | |
| 5709 | 5759 | |
| 5710 | 5760 | |
| @@ -5911,7 +5961,7 @@ The current contents of this variable is "<code>Lua 5.1</code>". · 200 unmodified lines |
| 5911 | 5961 | |
| 5912 | 5962 | |
| 5913 | 5963 | <p> |
| 5914 | | −This function is similar to <code>pcall</code>, |
| 5964 | +This function is similar to <a href="#pdf-pcall"><code>pcall</code></a>, |
| 5915 | 5965 | except that you can set a new error handler. |
| 5916 | 5966 | |
| 5917 | 5967 | |
| @@ -6101,7 +6151,7 @@ where each option is a function to be applied over the module. · 183 unmodified lines |
| 6101 | 6151 | |
| 6102 | 6152 | <p> |
| 6103 | 6153 | Loads the given module. |
| 6104 | | −The function starts by looking into the table <a href="#pdf-package.loaded"><code>package.loaded</code></a> |
| 6154 | +The function starts by looking into the <a href="#pdf-package.loaded"><code>package.loaded</code></a> table |
| 6105 | 6155 | to determine whether <code>modname</code> is already loaded. |
| 6106 | 6156 | If it is, then <code>require</code> returns the value stored |
| 6107 | 6157 | at <code>package.loaded[modname]</code>. |
| @@ -6156,7 +6206,7 @@ with each submodule keeping its original open function. · 48 unmodified lines |
| 6156 | 6206 | Once a loader is found, |
| 6157 | 6207 | <code>require</code> calls the loader with a single argument, <code>modname</code>. |
| 6158 | 6208 | If the loader returns any value, |
| 6159 | | −<code>require</code> assigns it to <code>package.loaded[modname]</code>. |
| 6209 | +<code>require</code> assigns the returned value to <code>package.loaded[modname]</code>. |
| 6160 | 6210 | If the loader returns no value and |
| 6161 | 6211 | has not assigned any value to <code>package.loaded[modname]</code>, |
| 6162 | 6212 | then <code>require</code> assigns <b>true</b> to this entry. |
| @@ -6190,6 +6240,7 @@ using the environment variable <a name="pdf-LUA_CPATH"><code>LUA_CPATH</code></a · 27 unmodified lines |
| 6190 | 6240 | |
| 6191 | 6241 | |
| 6192 | 6242 | <p> |
| 6243 | + |
| 6193 | 6244 | <hr><h3><a name="pdf-package.loaded"><code>package.loaded</code></a></h3> |
| 6194 | 6245 | |
| 6195 | 6246 | |
| @@ -6426,7 +6477,8 @@ whereas <code>q</code> and <code>s</code> expect a string. · 230 unmodified lines |
| 6426 | 6477 | |
| 6427 | 6478 | <p> |
| 6428 | 6479 | This function does not accept string values |
| 6429 | | −containing embedded zeros. |
| 6480 | +containing embedded zeros, |
| 6481 | +except as arguments to the <code>q</code> option. |
| 6430 | 6482 | |
| 6431 | 6483 | |
| 6432 | 6484 | |
| @@ -6436,9 +6488,6 @@ containing embedded zeros. · 3 unmodified lines |
| 6436 | 6488 | Returns an iterator function that, |
| 6437 | 6489 | each time it is called, |
| 6438 | 6490 | returns the next captures from <code>pattern</code> over string <code>s</code>. |
| 6439 | | − |
| 6440 | | − |
| 6441 | | −<p> |
| 6442 | 6491 | If <code>pattern</code> specifies no captures, |
| 6443 | 6492 | then the whole match is produced in each call. |
| 6444 | 6493 | |
| @@ -6465,6 +6514,11 @@ given string into a table: · 20 unmodified lines |
| 6465 | 6514 | end |
| 6466 | 6515 | </pre> |
| 6467 | 6516 | |
| 6517 | +<p> |
| 6518 | +For this function, a '<code>^</code>' at the start of a pattern does not |
| 6519 | +work as an anchor, as this would prevent the iteration. |
| 6520 | + |
| 6521 | + |
| 6468 | 6522 | |
| 6469 | 6523 | |
| 6470 | 6524 | <p> |
| @@ -6540,7 +6594,7 @@ Here are some examples: · 69 unmodified lines |
| 6540 | 6594 | --> x="4+5 = 9" |
| 6541 | 6595 | |
| 6542 | 6596 | local t = {name="lua", version="5.1"} |
| 6543 | | − x = string.gsub("$name%-$version.tar.gz", "%$(%w+)", t) |
| 6597 | + x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t) |
| 6544 | 6598 | --> x="lua-5.1.tar.gz" |
| 6545 | 6599 | </pre> |
| 6546 | 6600 | |
| @@ -6824,7 +6878,8 @@ we mean the result of the length operator. · 277 unmodified lines |
| 6824 | 6878 | |
| 6825 | 6879 | <p> |
| 6826 | 6880 | <hr><h3><a name="pdf-table.concat"><code>table.concat (table [, sep [, i [, j]]])</code></a></h3> |
| 6827 | | −Returns <code>table[i]..sep..table[i+1] ··· sep..table[j]</code>. |
| 6881 | +Given an array where all elements are strings or numbers, |
| 6882 | +returns <code>table[i]..sep..table[i+1] ··· sep..table[j]</code>. |
| 6828 | 6883 | The default value for <code>sep</code> is the empty string, |
| 6829 | 6884 | the default for <code>i</code> is 1, |
| 6830 | 6885 | and the default for <code>j</code> is the length of the table. |
| @@ -7122,7 +7177,7 @@ the integral part of <code>x</code> and the fractional part of <code>x</code>. · 291 unmodified lines |
| 7122 | 7177 | |
| 7123 | 7178 | |
| 7124 | 7179 | <p> |
| 7125 | | −The value PI. |
| 7180 | +The value of <em>pi</em>. |
| 7126 | 7181 | |
| 7127 | 7182 | |
| 7128 | 7183 | |
| @@ -7266,7 +7321,8 @@ three predefined file descriptors with their usual meanings from C: · 137 unmodified lines |
| 7266 | 7321 | <p> |
| 7267 | 7322 | Unless otherwise stated, |
| 7268 | 7323 | all I/O functions return <b>nil</b> on failure |
| 7269 | | −(plus an error message as a second result) |
| 7324 | +(plus an error message as a second result and |
| 7325 | +a system-dependent error code as a third result) |
| 7270 | 7326 | and some value different from <b>nil</b> on success. |
| 7271 | 7327 | |
| 7272 | 7328 | |
| @@ -7331,7 +7387,7 @@ it returns <b>nil</b> (to finish the loop) and automatically closes the file. · 58 unmodified lines |
| 7331 | 7387 | |
| 7332 | 7388 | |
| 7333 | 7389 | <p> |
| 7334 | | −The call <code>io.lines()</code> (without a file name) is equivalent |
| 7390 | +The call <code>io.lines()</code> (with no file name) is equivalent |
| 7335 | 7391 | to <code>io.input():lines()</code>; |
| 7336 | 7392 | that is, it iterates over the lines of the default input file. |
| 7337 | 7393 | In this case it does not close the file when the loop ends. |
| @@ -7381,7 +7437,7 @@ Similar to <a href="#pdf-io.input"><code>io.input</code></a>, but operates over · 43 unmodified lines |
| 7381 | 7437 | |
| 7382 | 7438 | |
| 7383 | 7439 | <p> |
| 7384 | | −<hr><h3><a name="pdf-io.popen"><code>io.popen ([prog [, mode]])</code></a></h3> |
| 7440 | +<hr><h3><a name="pdf-io.popen"><code>io.popen (prog [, mode])</code></a></h3> |
| 7385 | 7441 | |
| 7386 | 7442 | |
| 7387 | 7443 | <p> |
| @@ -7596,7 +7652,7 @@ or there is any input from some special files · 208 unmodified lines |
| 7596 | 7652 | </li> |
| 7597 | 7653 | |
| 7598 | 7654 | </ul><p> |
| 7599 | | −For the last two cases, <code>sizes</code> |
| 7655 | +For the last two cases, <code>size</code> |
| 7600 | 7656 | specifies the size of the buffer, in bytes. |
| 7601 | 7657 | The default is an appropriate size. |
| 7602 | 7658 | |
| @@ -7657,7 +7713,7 @@ Otherwise, <code>date</code> formats the current time. · 54 unmodified lines |
| 7657 | 7713 | If <code>format</code> starts with '<code>!</code>', |
| 7658 | 7714 | then the date is formatted in Coordinated Universal Time. |
| 7659 | 7715 | After this optional character, |
| 7660 | | −if <code>format</code> is <code>*t</code>, |
| 7716 | +if <code>format</code> is the string "<code>*t</code>", |
| 7661 | 7717 | then <code>date</code> returns a table with the following fields: |
| 7662 | 7718 | <code>year</code> (four digits), <code>month</code> (1--12), <code>day</code> (1--31), |
| 7663 | 7719 | <code>hour</code> (0--23), <code>min</code> (0--59), <code>sec</code> (0--61), |
| @@ -7667,7 +7723,7 @@ and <code>isdst</code> (daylight saving flag, a boolean). · 3 unmodified lines |
| 7667 | 7723 | |
| 7668 | 7724 | |
| 7669 | 7725 | <p> |
| 7670 | | −If <code>format</code> is not <code>*t</code>, |
| 7726 | +If <code>format</code> is not "<code>*t</code>", |
| 7671 | 7727 | then <code>date</code> returns the date as a string, |
| 7672 | 7728 | formatted according to the same rules as the C function <code>strftime</code>. |
| 7673 | 7729 | |
| @@ -7771,6 +7827,13 @@ The function returns the name of the new locale, · 97 unmodified lines |
| 7771 | 7827 | or <b>nil</b> if the request cannot be honored. |
| 7772 | 7828 | |
| 7773 | 7829 | |
| 7830 | +<p> |
| 7831 | +If <code>locale</code> is the empty string, |
| 7832 | +the current locate is set to an implementation-defined native locale. |
| 7833 | +If <code>locate</code> is the string "<code>C</code>", |
| 7834 | +the current locate is set to the standard C locale. |
| 7835 | + |
| 7836 | + |
| 7774 | 7837 | <p> |
| 7775 | 7838 | When called with <b>nil</b> as the first argument, |
| 7776 | 7839 | this function only returns the name of the current locale |
| @@ -7921,7 +7984,8 @@ valid lines. · 144 unmodified lines |
| 7921 | 7984 | <p> |
| 7922 | 7985 | For instance, the expression <code>debug.getinfo(1,"n").name</code> returns |
| 7923 | 7986 | a name of the current function, if a reasonable name can be found, |
| 7924 | | −and <code>debug.getinfo(print)</code> returns a table with all available information |
| 7987 | +and the expression <code>debug.getinfo(print)</code> |
| 7988 | +returns a table with all available information |
| 7925 | 7989 | about the <a href="#pdf-print"><code>print</code></a> function. |
| 7926 | 7990 | |
| 7927 | 7991 | |
| @@ -8080,15 +8144,16 @@ Otherwise, it returns the name of the upvalue. · 152 unmodified lines |
| 8080 | 8144 | |
| 8081 | 8145 | |
| 8082 | 8146 | <p> |
| 8083 | | −<hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message])</code></a></h3> |
| 8147 | +<hr><h3><a name="pdf-debug.traceback"><code>debug.traceback ([thread,] [message] [, level])</code></a></h3> |
| 8084 | 8148 | |
| 8085 | 8149 | |
| 8086 | 8150 | <p> |
| 8087 | 8151 | Returns a string with a traceback of the call stack. |
| 8088 | 8152 | An optional <code>message</code> string is appended |
| 8089 | | −at the beginning of the traceback. |
| 8090 | | −This function is typically used with <a href="#pdf-xpcall"><code>xpcall</code></a> to produce |
| 8091 | | −better error messages. |
| 8153 | +at the beginning of the traceback. |
| 8154 | +An optional <code>level</code> number tells at which level |
| 8155 | +to start the traceback |
| 8156 | +(default is 1, the function calling <code>traceback</code>). |
| 8092 | 8157 | |
| 8093 | 8158 | |
| 8094 | 8159 | |
| @@ -8232,7 +8297,7 @@ is a more portable solution.) · 137 unmodified lines |
| 8232 | 8297 | <h1>7 - <a name="7">Incompatibilities with the Previous Version</a></h1> |
| 8233 | 8298 | |
| 8234 | 8299 | <p> |
| 8235 | | −Here we list the incompatibilities that may be found when moving a program |
| 8300 | +Here we list the incompatibilities that you may found when moving a program |
| 8236 | 8301 | from Lua 5.0 to Lua 5.1. |
| 8237 | 8302 | You can avoid most of the incompatibilities compiling Lua with |
| 8238 | 8303 | appropriate options (see file <code>luaconf.h</code>). |
| @@ -8247,7 +8312,7 @@ all these compatibility options will be removed in the next version of Lua. · 8 unmodified lines |
| 8247 | 8312 | <li> |
| 8248 | 8313 | The vararg system changed from the pseudo-argument <code>arg</code> with a |
| 8249 | 8314 | table with the extra arguments to the vararg expression. |
| 8250 | | −(Option <code>LUA_COMPAT_VARARG</code> in <code>luaconf.h</code>.) |
| 8315 | +(See compile-time option <code>LUA_COMPAT_VARARG</code> in <code>luaconf.h</code>.) |
| 8251 | 8316 | </li> |
| 8252 | 8317 | |
| 8253 | 8318 | <li> |
| @@ -8259,7 +8324,7 @@ variables of the <b>for</b> statement and for the <b>repeat</b> statement. · 5 unmodified lines |
| 8259 | 8324 | The long string/long comment syntax (<code>[[<em>string</em>]]</code>) |
| 8260 | 8325 | does not allow nesting. |
| 8261 | 8326 | You can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases. |
| 8262 | | −(Option <code>LUA_COMPAT_LSTR</code> in <code>luaconf.h</code>.) |
| 8327 | +(See compile-time option <code>LUA_COMPAT_LSTR</code> in <code>luaconf.h</code>.) |
| 8263 | 8328 | </li> |
| 8264 | 8329 | |
| 8265 | 8330 | </ul> |
| @@ -8272,7 +8337,7 @@ You can use the new syntax (<code>[=[<em>string</em>]=]</code>) in these cases. · 6 unmodified lines |
| 8272 | 8337 | |
| 8273 | 8338 | <li> |
| 8274 | 8339 | Function <code>string.gfind</code> was renamed <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>. |
| 8275 | | −(Option <code>LUA_COMPAT_GFIND</code>) |
| 8340 | +(See compile-time option <code>LUA_COMPAT_GFIND</code> in <code>luaconf.h</code>.) |
| 8276 | 8341 | </li> |
| 8277 | 8342 | |
| 8278 | 8343 | <li> |
| @@ -8288,17 +8353,17 @@ Function <code>table.setn</code> was deprecated. · 9 unmodified lines |
| 8288 | 8353 | Function <code>table.getn</code> corresponds |
| 8289 | 8354 | to the new length operator (<code>#</code>); |
| 8290 | 8355 | use the operator instead of the function. |
| 8291 | | −(Option <code>LUA_COMPAT_GETN</code>) |
| 8356 | +(See compile-time option <code>LUA_COMPAT_GETN</code> in <code>luaconf.h</code>.) |
| 8292 | 8357 | </li> |
| 8293 | 8358 | |
| 8294 | 8359 | <li> |
| 8295 | 8360 | Function <code>loadlib</code> was renamed <a href="#pdf-package.loadlib"><code>package.loadlib</code></a>. |
| 8296 | | −(Option <code>LUA_COMPAT_LOADLIB</code>) |
| 8361 | +(See compile-time option <code>LUA_COMPAT_LOADLIB</code> in <code>luaconf.h</code>.) |
| 8297 | 8362 | </li> |
| 8298 | 8363 | |
| 8299 | 8364 | <li> |
| 8300 | 8365 | Function <code>math.mod</code> was renamed <a href="#pdf-math.fmod"><code>math.fmod</code></a>. |
| 8301 | | −(Option <code>LUA_COMPAT_MOD</code>) |
| 8366 | +(See compile-time option <code>LUA_COMPAT_MOD</code> in <code>luaconf.h</code>.) |
| 8302 | 8367 | </li> |
| 8303 | 8368 | |
| 8304 | 8369 | <li> |
| @@ -8446,10 +8511,10 @@ Here is the complete syntax of Lua in extended BNF. · 141 unmodified lines |
| 8446 | 8511 | <HR> |
| 8447 | 8512 | <SMALL> |
| 8448 | 8513 | Last update: |
| 8449 | | −Mon Jun 5 17:05:27 BRT 2006 |
| 8514 | +Fri Mar 23 14:37:09 BRT 2007 |
| 8450 | 8515 | </SMALL> |
| 8451 | 8516 | <!-- |
| 8452 | | −Last change: ready for Lua 5.1.1 |
| 8517 | +Last change: ready for Lua 5.1.2 |
| 8453 | 8518 | --> |
| 8454 | 8519 | |
| 8455 | 8520 | </body></html> |