Unified · Split
| @@ -1,5 +1,5 @@ | |||
| 1 | 1 | ||
| 2 | This is Lua 5.2 (work5), released on 30 Oct 2010. | 2 | This is Lua 5.2 (alpha), released on 16 Nov 2010. |
| 3 | 3 | ||
| 4 | For installation instructions, license details, and | 4 | For installation instructions, license details, and |
| 5 | further information about Lua, see doc/readme.html. | 5 | further information about Lua, see doc/readme.html. |
| @@ -22,8 +22,8 @@ Lua 5.2 Reference Manual · 21 unmodified lines | |||
| 22 | 22 | ||
| 23 | <P> | 23 | <P> |
| 24 | <IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]"> | 24 | <IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]"> |
| 25 | <EM>This is a work version of Lua 5.2. | 25 | <EM>This is an alpha version of Lua 5.2. |
| 26 | Everything may change in the final version.</EM> | 26 | Some details may change in the final version.</EM> |
| 27 | 27 | ||
| 28 | <P> | 28 | <P> |
| 29 | The reference manual is the official definition of the Lua language. | 29 | The reference manual is the official definition of the Lua language. |
| @@ -52,7 +52,7 @@ Freely available under the terms of the · 22 unmodified lines | |||
| 52 | <LI><A HREF="manual.html#2.1">2.1 – Values and Types</A> | 52 | <LI><A HREF="manual.html#2.1">2.1 – Values and Types</A> |
| 53 | <LI><A HREF="manual.html#2.2">2.2 – Environments and the Global Environment</A> | 53 | <LI><A HREF="manual.html#2.2">2.2 – Environments and the Global Environment</A> |
| 54 | <LI><A HREF="manual.html#2.3">2.3 – Error Handling</A> | 54 | <LI><A HREF="manual.html#2.3">2.3 – Error Handling</A> |
| 55 | <LI><A HREF="manual.html#2.4">2.4 – Metatables</A> | 55 | <LI><A HREF="manual.html#2.4">2.4 – Metatables and Metamethods</A> |
| 56 | <LI><A HREF="manual.html#2.5">2.5 – Garbage Collection</A> | 56 | <LI><A HREF="manual.html#2.5">2.5 – Garbage Collection</A> |
| 57 | <UL> | 57 | <UL> |
| 58 | <LI><A HREF="manual.html#2.5.1">2.5.1 – Garbage-Collection Metamethods</A> | 58 | <LI><A HREF="manual.html#2.5.1">2.5.1 – Garbage-Collection Metamethods</A> |
| @@ -484,7 +484,6 @@ Freely available under the terms of the · 425 unmodified lines | |||
| 484 | <A HREF="manual.html#luaL_newlib">luaL_newlib</A><BR> | 484 | <A HREF="manual.html#luaL_newlib">luaL_newlib</A><BR> |
| 485 | <A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR> | 485 | <A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR> |
| 486 | <A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR> | 486 | <A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR> |
| 487 | <A HREF="manual.html#luaL_setfuncs">luaL_setfuncs</A><BR> | ||
| 488 | <A HREF="manual.html#luaL_openlibs">luaL_openlibs</A><BR> | 487 | <A HREF="manual.html#luaL_openlibs">luaL_openlibs</A><BR> |
| 489 | <A HREF="manual.html#luaL_optint">luaL_optint</A><BR> | 488 | <A HREF="manual.html#luaL_optint">luaL_optint</A><BR> |
| 490 | <A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR> | 489 | <A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR> |
| @@ -497,11 +496,12 @@ Freely available under the terms of the · 6 unmodified lines | |||
| 497 | <A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR> | 496 | <A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR> |
| 498 | <A HREF="manual.html#luaL_ref">luaL_ref</A><BR> | 497 | <A HREF="manual.html#luaL_ref">luaL_ref</A><BR> |
| 499 | <A HREF="manual.html#luaL_requiref">luaL_requiref</A><BR> | 498 | <A HREF="manual.html#luaL_requiref">luaL_requiref</A><BR> |
| 499 | <A HREF="manual.html#luaL_setfuncs">luaL_setfuncs</A><BR> | ||
| 500 | <A HREF="manual.html#luaL_setmetatable">luaL_setmetatable</A><BR> | ||
| 500 | <A HREF="manual.html#luaL_testudata">luaL_testudata</A><BR> | 501 | <A HREF="manual.html#luaL_testudata">luaL_testudata</A><BR> |
| 501 | <A HREF="manual.html#luaL_tolstring">luaL_tolstring</A><BR> | 502 | <A HREF="manual.html#luaL_tolstring">luaL_tolstring</A><BR> |
| 502 | <A HREF="manual.html#luaL_traceback">luaL_traceback</A><BR> | 503 | <A HREF="manual.html#luaL_traceback">luaL_traceback</A><BR> |
| 503 | <A HREF="manual.html#luaL_typename">luaL_typename</A><BR> | 504 | <A HREF="manual.html#luaL_typename">luaL_typename</A><BR> |
| 504 | <A HREF="manual.html#luaL_typeerror">luaL_typeerror</A><BR> | ||
| 505 | <A HREF="manual.html#luaL_unref">luaL_unref</A><BR> | 505 | <A HREF="manual.html#luaL_unref">luaL_unref</A><BR> |
| 506 | <A HREF="manual.html#luaL_where">luaL_where</A><BR> | 506 | <A HREF="manual.html#luaL_where">luaL_where</A><BR> |
| 507 | 507 | ||
| @@ -512,10 +512,10 @@ Freely available under the terms of the · 4 unmodified lines | |||
| 512 | <HR> | 512 | <HR> |
| 513 | <SMALL> | 513 | <SMALL> |
| 514 | Last update: | 514 | Last update: |
| 515 | Sat Oct 30 21:34:44 BRST 2010 | 515 | Tue Nov 16 09:56:07 BRST 2010 |
| 516 | </SMALL> | 516 | </SMALL> |
| 517 | <!-- | 517 | <!-- |
| 518 | Last change: revised for Lua 5.2.0 (work5) | 518 | Last change: revised for Lua 5.2.0 (alpha) |
| 519 | --> | 519 | --> |
| 520 | 520 | ||
| 521 | </BODY> | 521 | </BODY> |
| @@ -17,8 +17,8 @@ Lua 5.2 Reference Manual · 16 unmodified lines | |||
| 17 | </h1> | 17 | </h1> |
| 18 | 18 | ||
| 19 | <IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]"> | 19 | <IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]"> |
| 20 | <EM>This is a work version of Lua 5.2. | 20 | <EM>This is an alpha version of Lua 5.2. |
| 21 | Everything may change in the final version.</EM> | 21 | Some details may change in the final version.</EM> |
| 22 | <P> | 22 | <P> |
| 23 | 23 | ||
| 24 | by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes | 24 | by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes |
| @@ -38,7 +38,7 @@ Freely available under the terms of the · 13 unmodified lines | |||
| 38 | <!-- ====================================================================== --> | 38 | <!-- ====================================================================== --> |
| 39 | <p> | 39 | <p> |
| 40 | 40 | ||
| 41 | <!-- $Id: manual.of,v 1.61 2010/10/29 12:51:39 roberto Exp $ --> | 41 | <!-- $Id: manual.of,v 1.62 2010/11/16 11:38:25 roberto Exp $ --> |
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | 44 | ||
| @@ -287,7 +287,7 @@ you can use the <a href="#pdf-pcall"><code>pcall</code></a> function. · 242 unmodified lines | |||
| 287 | 287 | ||
| 288 | 288 | ||
| 289 | 289 | ||
| 290 | <h2>2.4 – <a name="2.4">Metatables</a></h2> | 290 | <h2>2.4 – <a name="2.4">Metatables and Metamethods</a></h2> |
| 291 | 291 | ||
| 292 | <p> | 292 | <p> |
| 293 | Every value in Lua can have a <em>metatable</em>. | 293 | Every value in Lua can have a <em>metatable</em>. |
| @@ -305,7 +305,7 @@ Lua calls this function to perform the addition. · 11 unmodified lines | |||
| 305 | <p> | 305 | <p> |
| 306 | We call the keys in a metatable <em>events</em> | 306 | We call the keys in a metatable <em>events</em> |
| 307 | and the values <em>metamethods</em>. | 307 | and the values <em>metamethods</em>. |
| 308 | In the previous example, the event is <code>"add"</code> | 308 | In the previous example, the event is <code>"__add"</code> |
| 309 | and the metamethod is the function that performs the addition. | 309 | and the metamethod is the function that performs the addition. |
| 310 | 310 | ||
| 311 | 311 | ||
| @@ -383,7 +383,7 @@ and the access to objects with no metatables does not fail · 71 unmodified lines | |||
| 383 | 383 | ||
| 384 | <p> | 384 | <p> |
| 385 | For the unary <code>-</code> and <code>#</code> operators, | 385 | For the unary <code>-</code> and <code>#</code> operators, |
| 386 | the metamethod is called repeating the first argument as a second argument. | 386 | the metamethod is called with a dummy second argument. |
| 387 | This extra argument is only to simplify Lua's internals; | 387 | This extra argument is only to simplify Lua's internals; |
| 388 | it may be removed in future versions and therefore it is not present | 388 | it may be removed in future versions and therefore it is not present |
| 389 | in the following code. | 389 | in the following code. |
| @@ -2731,13 +2731,12 @@ It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newst · 2341 unmodified lines | |||
| 2731 | return realloc(ptr, nsize); | 2731 | return realloc(ptr, nsize); |
| 2732 | } | 2732 | } |
| 2733 | </pre><p> | 2733 | </pre><p> |
| 2734 | This code assumes | 2734 | Note that ANSI C ensures |
| 2735 | that <code>free(NULL)</code> has no effect and that | 2735 | that <code>free(NULL)</code> has no effect and that |
| 2736 | <code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>. | 2736 | <code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>. |
| 2737 | ANSI C ensures both behaviors. | 2737 | This code assumes that <code>realloc</code> does not fail when shrinking a block. |
| 2738 | It also assumes that <code>realloc</code> does not fail when shrinking a block. | 2738 | ANSI C does not ensure this behavior, |
| 2739 | (ANSI C does not ensure this behavior, | 2739 | but it seems a safe assumption. |
| 2740 | but it seems a safe assumption.) | ||
| 2741 | 2740 | ||
| 2742 | 2741 | ||
| 2743 | 2742 | ||
| @@ -5989,6 +5988,19 @@ These values are popped from the stack after the registration. · 3245 unmodified lines | |||
| 5989 | 5988 | ||
| 5990 | 5989 | ||
| 5991 | 5990 | ||
| 5991 | <hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p> | ||
| 5992 | <span class="apii">[-0, +0, <em>-</em>]</span> | ||
| 5993 | <pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre> | ||
| 5994 | |||
| 5995 | <p> | ||
| 5996 | Sets the metatable of the object at the top of the stack | ||
| 5997 | as the metatable associated with name <code>tname</code> | ||
| 5998 | in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>). | ||
| 5999 | |||
| 6000 | |||
| 6001 | |||
| 6002 | |||
| 6003 | |||
| 5992 | <hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p> | 6004 | <hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p> |
| 5993 | <span class="apii">[-0, +0, <em>e</em>]</span> | 6005 | <span class="apii">[-0, +0, <em>e</em>]</span> |
| 5994 | <pre>void luaL_openlibs (lua_State *L);</pre> | 6006 | <pre>void luaL_openlibs (lua_State *L);</pre> |
| @@ -6280,24 +6292,6 @@ Returns the name of the type of the value at the given index. · 285 unmodified lines | |||
| 6280 | 6292 | ||
| 6281 | 6293 | ||
| 6282 | 6294 | ||
| 6283 | <hr><h3><a name="luaL_typeerror"><code>luaL_typeerror</code></a></h3><p> | ||
| 6284 | <span class="apii">[-0, +0, <em>v</em>]</span> | ||
| 6285 | <pre>int luaL_typeerror (lua_State *L, int narg, const char *tname);</pre> | ||
| 6286 | |||
| 6287 | <p> | ||
| 6288 | Generates an error with a message like the following: | ||
| 6289 | |||
| 6290 | <pre> | ||
| 6291 | <em>location</em>: bad argument <em>narg</em> to '<em>func</em>' (<em>tname</em> expected, got <em>rt</em>) | ||
| 6292 | </pre><p> | ||
| 6293 | where <code><em>location</em></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>, | ||
| 6294 | <code><em>func</em></code> is the name of the current function, | ||
| 6295 | and <code><em>rt</em></code> is the type name of the actual argument. | ||
| 6296 | |||
| 6297 | |||
| 6298 | |||
| 6299 | |||
| 6300 | |||
| 6301 | <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p> | 6295 | <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p> |
| 6302 | <span class="apii">[-0, +0, <em>-</em>]</span> | 6296 | <span class="apii">[-0, +0, <em>-</em>]</span> |
| 6303 | <pre>void luaL_unref (lua_State *L, int t, int ref);</pre> | 6297 | <pre>void luaL_unref (lua_State *L, int t, int ref);</pre> |
| @@ -7020,8 +7014,6 @@ In case of error, propagates the error. · 716 unmodified lines | |||
| 7020 | 7014 | ||
| 7021 | <p> | 7015 | <p> |
| 7022 | Suspends the execution of the calling coroutine. | 7016 | Suspends the execution of the calling coroutine. |
| 7023 | The coroutine cannot be running a C function, | ||
| 7024 | a metamethod, or an iterator. | ||
| 7025 | Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>. | 7017 | Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>. |
| 7026 | 7018 | ||
| 7027 | 7019 | ||
| @@ -8586,20 +8578,13 @@ instead of returning an error code. · 1558 unmodified lines | |||
| 8586 | 8578 | ||
| 8587 | 8579 | ||
| 8588 | <p> | 8580 | <p> |
| 8589 | <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename] [, keepNL])</code></a></h3> | 8581 | <hr><h3><a name="pdf-io.lines"><code>io.lines ([filename] ···)</code></a></h3> |
| 8590 | 8582 | ||
| 8591 | 8583 | ||
| 8592 | <p> | 8584 | <p> |
| 8593 | Opens the given file name in read mode | 8585 | Opens the given file name in read mode |
| 8594 | and returns an iterator function that, | 8586 | and returns an iterator function that |
| 8595 | each time it is called, | 8587 | works like <code>file:lines(···)</code> over the oppened file. |
| 8596 | returns a new line from the file. | ||
| 8597 | Therefore, the construction | ||
| 8598 | |||
| 8599 | <pre> | ||
| 8600 | for line in io.lines(filename) do <em>body</em> end | ||
| 8601 | </pre><p> | ||
| 8602 | will iterate over all lines of the file. | ||
| 8603 | When the iterator function detects the end of file, | 8588 | When the iterator function detects the end of file, |
| 8604 | it returns <b>nil</b> (to finish the loop) and automatically closes the file. | 8589 | it returns <b>nil</b> (to finish the loop) and automatically closes the file. |
| 8605 | 8590 | ||
| @@ -8611,11 +8596,6 @@ that is, it iterates over the lines of the default input file. · 5 unmodified lines | |||
| 8611 | In this case it does not close the file when the loop ends. | 8596 | In this case it does not close the file when the loop ends. |
| 8612 | 8597 | ||
| 8613 | 8598 | ||
| 8614 | <p> | ||
| 8615 | By default, <code>lines</code> removes the newline at the end of each line. | ||
| 8616 | If <code>keepNL</code> is <b>true</b>, it will keep the newlines. | ||
| 8617 | |||
| 8618 | |||
| 8619 | 8599 | ||
| 8620 | 8600 | ||
| 8621 | <p> | 8601 | <p> |
| @@ -8750,29 +8730,26 @@ Saves any written data to <code>file</code>. · 128 unmodified lines | |||
| 8750 | 8730 | ||
| 8751 | 8731 | ||
| 8752 | <p> | 8732 | <p> |
| 8753 | <hr><h3><a name="pdf-file:lines"><code>file:lines ([keepNL])</code></a></h3> | 8733 | <hr><h3><a name="pdf-file:lines"><code>file:lines (···)</code></a></h3> |
| 8754 | 8734 | ||
| 8755 | 8735 | ||
| 8756 | <p> | 8736 | <p> |
| 8757 | Returns an iterator function that, | 8737 | Returns an iterator function that, |
| 8758 | each time it is called, | 8738 | each time it is called, |
| 8759 | returns a new line from the file. | 8739 | reads the file according to the given formats. |
| 8740 | When no format is given, | ||
| 8741 | uses "*l" as a default. | ||
| 8760 | Therefore, the construction | 8742 | Therefore, the construction |
| 8761 | 8743 | ||
| 8762 | <pre> | 8744 | <pre> |
| 8763 | for line in file:lines() do <em>body</em> end | 8745 | for c in file:lines(1) do <em>body</em> end |
| 8764 | </pre><p> | 8746 | </pre><p> |
| 8765 | will iterate over all lines of the file, | 8747 | will iterate over all characters of the file, |
| 8766 | starting at the current position. | 8748 | starting at the current position. |
| 8767 | (Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file | 8749 | (Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file |
| 8768 | when the loop ends.) | 8750 | when the loop ends.) |
| 8769 | 8751 | ||
| 8770 | 8752 | ||
| 8771 | <p> | ||
| 8772 | By default, <code>lines</code> removes the newline at the end of each line. | ||
| 8773 | If <code>keepNL</code> is <b>true</b>, it will keep the newlines. | ||
| 8774 | |||
| 8775 | |||
| 8776 | 8753 | ||
| 8777 | 8754 | ||
| 8778 | <p> | 8755 | <p> |
| @@ -9673,11 +9650,6 @@ Modules are not expected to set global variables anymore, · 894 unmodified lines | |||
| 9673 | and it is easy to set up a module with regular Lua code. | 9650 | and it is easy to set up a module with regular Lua code. |
| 9674 | </li> | 9651 | </li> |
| 9675 | 9652 | ||
| 9676 | <li> | ||
| 9677 | The debug library is not loaded by default. | ||
| 9678 | You must explicitly require it. | ||
| 9679 | </li> | ||
| 9680 | |||
| 9681 | <li> | 9653 | <li> |
| 9682 | Functions <code>setfenv</code> and <code>getfenv</code> are deprecated. | 9654 | Functions <code>setfenv</code> and <code>getfenv</code> are deprecated. |
| 9683 | To set the environment of a Lua function, | 9655 | To set the environment of a Lua function, |
| @@ -9767,8 +9739,8 @@ even if it is set later. · 83 unmodified lines | |||
| 9767 | </li> | 9739 | </li> |
| 9768 | 9740 | ||
| 9769 | <li> | 9741 | <li> |
| 9770 | <code>luaL_typerror</code> was renamed <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>, | 9742 | <code>luaL_typerror</code> was deprecated. |
| 9771 | to have a correct spelling. | 9743 | Write your own version if you need it. |
| 9772 | </li> | 9744 | </li> |
| 9773 | 9745 | ||
| 9774 | <li> | 9746 | <li> |
| @@ -9873,10 +9845,10 @@ Here is the complete syntax of Lua in extended BNF. · 98 unmodified lines | |||
| 9873 | <HR> | 9845 | <HR> |
| 9874 | <SMALL> | 9846 | <SMALL> |
| 9875 | Last update: | 9847 | Last update: |
| 9876 | Sat Oct 30 21:36:20 BRST 2010 | 9848 | Tue Nov 16 09:52:41 BRST 2010 |
| 9877 | </SMALL> | 9849 | </SMALL> |
| 9878 | <!-- | 9850 | <!-- |
| 9879 | Last change: revised for Lua 5.2.0 (work5) | 9851 | Last change: revised for Lua 5.2.0 (alpha) |
| 9880 | --> | 9852 | --> |
| 9881 | 9853 | ||
| 9882 | </body></html> | 9854 | </body></html> |
| @@ -27,13 +27,13 @@ tt, kbd, code { · 26 unmodified lines | |||
| 27 | <HR> | 27 | <HR> |
| 28 | <H1> | 28 | <H1> |
| 29 | <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A> | 29 | <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A> |
| 30 | Welcome to Lua 5.2 (work5) | 30 | Welcome to Lua 5.2 (alpha) |
| 31 | </H1> | 31 | </H1> |
| 32 | 32 | ||
| 33 | <P> | 33 | <P> |
| 34 | <IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]"> | 34 | <IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]"> |
| 35 | <EM>This is a work version of Lua 5.2. | 35 | <EM>This is an alpha version of Lua 5.2. |
| 36 | Everything may change in the final version.</EM> | 36 | Some details may change in the final version.</EM> |
| 37 | 37 | ||
| 38 | <P> | 38 | <P> |
| 39 | <A HREF="#about">about</A> | 39 | <A HREF="#about">about</A> |
| @@ -323,12 +323,13 @@ Here are the other changes introduced in Lua 5.2: · 283 unmodified lines | |||
| 323 | <LI> new <CODE>lua_compare</CODE>, <CODE>lua_arith</CODE>, and <CODE>lua_len</CODE> | 323 | <LI> new <CODE>lua_compare</CODE>, <CODE>lua_arith</CODE>, and <CODE>lua_len</CODE> |
| 324 | <LI> new <CODE>lua_version</CODE> and <CODE>luaL_version</CODE> | 324 | <LI> new <CODE>lua_version</CODE> and <CODE>luaL_version</CODE> |
| 325 | <LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string | 325 | <LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string |
| 326 | <LI> new <CODE>luaL_testudata</CODE> | 326 | <LI> new <CODE>luaL_testudata</CODE> and <CODE>luaL_setmetatable</CODE> |
| 327 | <LI> new <CODE>luaL_tolstring</CODE> | 327 | <LI> new <CODE>luaL_tolstring</CODE> |
| 328 | <LI> new <CODE>lua_copy</CODE> | 328 | <LI> new <CODE>lua_copy</CODE> |
| 329 | <LI> new <CODE>lua_absindex</CODE> | 329 | <LI> new <CODE>lua_absindex</CODE> |
| 330 | <LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE> | 330 | <LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE> |
| 331 | <LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API | 331 | <LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API |
| 332 | <LI> new <CODE>lua_Unsigned</CODE> | ||
| 332 | </UL> | 333 | </UL> |
| 333 | 334 | ||
| 334 | <H3>Implementation</H3> | 335 | <H3>Implementation</H3> |
| @@ -337,7 +338,7 @@ Here are the other changes introduced in Lua 5.2: · 2 unmodified lines | |||
| 337 | <LI> internal (immutable) version of ctypes | 338 | <LI> internal (immutable) version of ctypes |
| 338 | <LI> simpler implementation for string buffers | 339 | <LI> simpler implementation for string buffers |
| 339 | <LI> udata with finalizers are kept in a separated list for the GC | 340 | <LI> udata with finalizers are kept in a separated list for the GC |
| 340 | <LI> <CODE>CallInfo</CODE>stack now is a linked list | 341 | <LI> <CODE>CallInfo</CODE> stack now is a linked list |
| 341 | <LI> parser uses much less C-stack space (no more auto arrays) | 342 | <LI> parser uses much less C-stack space (no more auto arrays) |
| 342 | <LI> new hash for floats | 343 | <LI> new hash for floats |
| 343 | <LI> handling of non-string error messages in the standalone interpreter | 344 | <LI> handling of non-string error messages in the standalone interpreter |
| @@ -390,10 +391,10 @@ THE SOFTWARE. · 46 unmodified lines | |||
| 390 | <HR> | 391 | <HR> |
| 391 | <SMALL> | 392 | <SMALL> |
| 392 | Last update: | 393 | Last update: |
| 393 | Sat Oct 30 21:36:38 BRST 2010 | 394 | Thu Nov 11 15:16:22 BRST 2010 |
| 394 | </SMALL> | 395 | </SMALL> |
| 395 | <!-- | 396 | <!-- |
| 396 | Last change: revised for Lua 5.2.0 (work5) | 397 | Last change: revised for Lua 5.2.0 (alpha) |
| 397 | --> | 398 | --> |
| 398 | 399 | ||
| 399 | </BODY> | 400 | </BODY> |
| @@ -7,7 +7,7 @@ · 6 unmodified lines | |||
| 7 | PLAT= none | 7 | PLAT= none |
| 8 | 8 | ||
| 9 | CC= gcc | 9 | CC= gcc |
| 10 | CFLAGS= -O2 -Wall $(MYCFLAGS) | 10 | CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(MYCFLAGS) |
| 11 | LIBS= -lm $(MYLIBS) | 11 | LIBS= -lm $(MYLIBS) |
| 12 | 12 | ||
| 13 | AR= ar rcu | 13 | AR= ar rcu |
| @@ -97,7 +97,7 @@ freebsd: · 83 unmodified lines | |||
| 97 | generic: $(ALL) | 97 | generic: $(ALL) |
| 98 | 98 | ||
| 99 | linux: | 99 | linux: |
| 100 | $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline -lncurses" | 100 | $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline" |
| 101 | 101 | ||
| 102 | macosx: | 102 | macosx: |
| 103 | $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_MACOSX" MYLIBS="-lreadline" | 103 | $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_MACOSX" MYLIBS="-lreadline" |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.139 2010/10/25 20:31:11 roberto Exp $ | 2 | ** $Id: lapi.c,v 2.140 2010/11/03 15:16:17 roberto Exp $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -353,7 +353,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) { · 347 unmodified lines | |||
| 353 | if (tonumber(o, &n)) { | 353 | if (tonumber(o, &n)) { |
| 354 | lua_Unsigned res; | 354 | lua_Unsigned res; |
| 355 | lua_Number num = nvalue(o); | 355 | lua_Number num = nvalue(o); |
| 356 | lua_number2uint(res, num); | 356 | lua_number2unsigned(res, num); |
| 357 | if (isnum) *isnum = 1; | 357 | if (isnum) *isnum = 1; |
| 358 | return res; | 358 | return res; |
| 359 | } | 359 | } |
| @@ -472,7 +472,7 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { · 112 unmodified lines | |||
| 472 | LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) { | 472 | LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) { |
| 473 | lua_Number n; | 473 | lua_Number n; |
| 474 | lua_lock(L); | 474 | lua_lock(L); |
| 475 | n = lua_uint2number(u); | 475 | n = lua_unsigned2number(u); |
| 476 | setnvalue(L->top, n); | 476 | setnvalue(L->top, n); |
| 477 | api_incr_top(L); | 477 | api_incr_top(L); |
| 478 | lua_unlock(L); | 478 | lua_unlock(L); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.224 2010/10/29 12:52:21 roberto Exp $ | 2 | ** $Id: lauxlib.c,v 1.227 2010/11/10 18:05:36 roberto Exp $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -168,7 +168,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { · 162 unmodified lines | |||
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | 170 | ||
| 171 | LUALIB_API int luaL_typeerror (lua_State *L, int narg, const char *tname) { | 171 | static int typeerror (lua_State *L, int narg, const char *tname) { |
| 172 | const char *msg = lua_pushfstring(L, "%s expected, got %s", | 172 | const char *msg = lua_pushfstring(L, "%s expected, got %s", |
| 173 | tname, luaL_typename(L, narg)); | 173 | tname, luaL_typename(L, narg)); |
| 174 | return luaL_argerror(L, narg, msg); | 174 | return luaL_argerror(L, narg, msg); |
| @@ -176,7 +176,7 @@ LUALIB_API int luaL_typeerror (lua_State *L, int narg, const char *tname) { · 1 unmodified line | |||
| 176 | 176 | ||
| 177 | 177 | ||
| 178 | static void tag_error (lua_State *L, int narg, int tag) { | 178 | static void tag_error (lua_State *L, int narg, int tag) { |
| 179 | luaL_typeerror(L, narg, lua_typename(L, tag)); | 179 | typeerror(L, narg, lua_typename(L, tag)); |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | 182 | ||
| @@ -224,6 +224,12 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { · 41 unmodified lines | |||
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | 226 | ||
| 227 | LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) { | ||
| 228 | luaL_getmetatable(L, tname); | ||
| 229 | lua_setmetatable(L, -2); | ||
| 230 | } | ||
| 231 | |||
| 232 | |||
| 227 | LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { | 233 | LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { |
| 228 | void *p = lua_touserdata(L, ud); | 234 | void *p = lua_touserdata(L, ud); |
| 229 | if (p != NULL) { /* value is a userdata? */ | 235 | if (p != NULL) { /* value is a userdata? */ |
| @@ -241,7 +247,7 @@ LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { · 11 unmodified lines | |||
| 241 | 247 | ||
| 242 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { | 248 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { |
| 243 | void *p = luaL_testudata(L, ud, tname); | 249 | void *p = luaL_testudata(L, ud, tname); |
| 244 | if (p == NULL) luaL_typeerror(L, ud, tname); | 250 | if (p == NULL) typeerror(L, ud, tname); |
| 245 | return p; | 251 | return p; |
| 246 | } | 252 | } |
| 247 | 253 | ||
| @@ -377,7 +383,7 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) { · 129 unmodified lines | |||
| 377 | if (newsize - B->n < sz) /* not bit enough? */ | 383 | if (newsize - B->n < sz) /* not bit enough? */ |
| 378 | newsize = B->n + sz; | 384 | newsize = B->n + sz; |
| 379 | if (newsize < B->n || newsize - B->n < sz) | 385 | if (newsize < B->n || newsize - B->n < sz) |
| 380 | luaL_error(L, "string too large"); | 386 | luaL_error(L, "buffer too large"); |
| 381 | newbuff = (char *)lua_newuserdata(L, newsize); /* create larger buffer */ | 387 | newbuff = (char *)lua_newuserdata(L, newsize); /* create larger buffer */ |
| 382 | memcpy(newbuff, B->b, B->n); /* move content to new buffer */ | 388 | memcpy(newbuff, B->b, B->n); /* move content to new buffer */ |
| 383 | if (buffonstack(B)) | 389 | if (buffonstack(B)) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.109 2010/10/25 20:31:11 roberto Exp $ | 2 | ** $Id: lauxlib.h,v 1.111 2010/11/10 18:05:36 roberto Exp $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -32,7 +32,6 @@ LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver); · 26 unmodified lines | |||
| 32 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); | 32 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); |
| 33 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); | 33 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); |
| 34 | LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); | 34 | LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); |
| 35 | LUALIB_API int (luaL_typeerror) (lua_State *L, int narg, const char *tname); | ||
| 36 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); | 35 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); |
| 37 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, | 36 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, |
| 38 | size_t *l); | 37 | size_t *l); |
| @@ -53,6 +52,7 @@ LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); · 14 unmodified lines | |||
| 53 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); | 52 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); |
| 54 | 53 | ||
| 55 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); | 54 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); |
| 55 | LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); | ||
| 56 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); | 56 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); |
| 57 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); | 57 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); |
| 58 | 58 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbitlib.c,v 1.10 2010/10/28 15:17:29 roberto Exp $ | 2 | ** $Id: lbitlib.c,v 1.11 2010/11/08 16:31:22 roberto Exp $ |
| 3 | ** Standard library for bitwise operations | 3 | ** Standard library for bitwise operations |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -108,7 +108,7 @@ static int b_rshift (lua_State *L) { · 102 unmodified lines | |||
| 108 | static int b_arshift (lua_State *L) { | 108 | static int b_arshift (lua_State *L) { |
| 109 | b_uint r = getuintarg(L, 1); | 109 | b_uint r = getuintarg(L, 1); |
| 110 | int i = luaL_checkint(L, 2); | 110 | int i = luaL_checkint(L, 2); |
| 111 | if (i < 0 || !(r & (1 << (NBITS - 1)))) | 111 | if (i < 0 || !(r & ((b_uint)1 << (NBITS - 1)))) |
| 112 | return b_shift(L, r, -i); | 112 | return b_shift(L, r, -i); |
| 113 | else { /* arithmetic shift for 'negative' number */ | 113 | else { /* arithmetic shift for 'negative' number */ |
| 114 | if (i >= NBITS) r = ALLONES; | 114 | if (i >= NBITS) r = ALLONES; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.124 2010/07/25 15:18:19 roberto Exp $ | 2 | ** $Id: ldblib.c,v 1.125 2010/11/10 18:06:10 roberto Exp $ |
| 3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -44,15 +44,22 @@ static int db_setmetatable (lua_State *L) { · 38 unmodified lines | |||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | static void checkudata (lua_State *L, int narg) { | ||
| 48 | if (lua_type(L, narg) == LUA_TLIGHTUSERDATA) | ||
| 49 | luaL_argerror(L, narg, "full userdata expected, got light userdata"); | ||
| 50 | luaL_checktype(L, narg, LUA_TUSERDATA); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 47 | static int db_getuservalue (lua_State *L) { | 54 | static int db_getuservalue (lua_State *L) { |
| 48 | luaL_checktype(L, 1, LUA_TUSERDATA); | 55 | checkudata(L, 1); |
| 49 | lua_getuservalue(L, 1); | 56 | lua_getuservalue(L, 1); |
| 50 | return 1; | 57 | return 1; |
| 51 | } | 58 | } |
| 52 | 59 | ||
| 53 | 60 | ||
| 54 | static int db_setuservalue (lua_State *L) { | 61 | static int db_setuservalue (lua_State *L) { |
| 55 | luaL_checktype(L, 1, LUA_TUSERDATA); | 62 | checkudata(L, 1); |
| 56 | if (!lua_isnoneornil(L, 2)) | 63 | if (!lua_isnoneornil(L, 2)) |
| 57 | luaL_checktype(L, 2, LUA_TTABLE); | 64 | luaL_checktype(L, 2, LUA_TTABLE); |
| 58 | lua_settop(L, 2); | 65 | lua_settop(L, 2); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: linit.c,v 1.29 2010/10/25 14:32:36 roberto Exp $ | 2 | ** $Id: linit.c,v 1.30 2010/11/12 15:48:30 roberto Exp $ |
| 3 | ** Initialization of libraries for lua.c and other clients | 3 | ** Initialization of libraries for lua.c and other clients |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -36,9 +36,7 @@ static const luaL_Reg loadedlibs[] = { · 30 unmodified lines | |||
| 36 | {LUA_STRLIBNAME, luaopen_string}, | 36 | {LUA_STRLIBNAME, luaopen_string}, |
| 37 | {LUA_BITLIBNAME, luaopen_bit32}, | 37 | {LUA_BITLIBNAME, luaopen_bit32}, |
| 38 | {LUA_MATHLIBNAME, luaopen_math}, | 38 | {LUA_MATHLIBNAME, luaopen_math}, |
| 39 | #if defined(LUA_COMPAT_DEBUGLIB) | ||
| 40 | {LUA_DBLIBNAME, luaopen_debug}, | 39 | {LUA_DBLIBNAME, luaopen_debug}, |
| 41 | #endif | ||
| 42 | {NULL, NULL} | 40 | {NULL, NULL} |
| 43 | }; | 41 | }; |
| 44 | 42 | ||
| @@ -47,7 +45,6 @@ static const luaL_Reg loadedlibs[] = { · 2 unmodified lines | |||
| 47 | ** these libs are preloaded and must be required before used | 45 | ** these libs are preloaded and must be required before used |
| 48 | */ | 46 | */ |
| 49 | static const luaL_Reg preloadedlibs[] = { | 47 | static const luaL_Reg preloadedlibs[] = { |
| 50 | {LUA_DBLIBNAME, luaopen_debug}, | ||
| 51 | {NULL, NULL} | 48 | {NULL, NULL} |
| 52 | }; | 49 | }; |
| 53 | 50 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.92 2010/10/25 19:01:37 roberto Exp $ | 2 | ** $Id: liolib.c,v 2.95 2010/11/10 18:05:36 roberto Exp $ |
| 3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -19,6 +19,9 @@ · 13 unmodified lines | |||
| 19 | #include "lualib.h" | 19 | #include "lualib.h" |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | #define MAX_SIZE_T (~(size_t)0) | ||
| 23 | |||
| 24 | |||
| 22 | /* | 25 | /* |
| 23 | ** lua_popen spawns a new process connected to the current one through | 26 | ** lua_popen spawns a new process connected to the current one through |
| 24 | ** the file streams. | 27 | ** the file streams. |
| @@ -111,8 +114,7 @@ static FILE *tofile (lua_State *L) { · 86 unmodified lines | |||
| 111 | static FILE **newprefile (lua_State *L) { | 114 | static FILE **newprefile (lua_State *L) { |
| 112 | FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); | 115 | FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); |
| 113 | *pf = NULL; /* file handle is currently `closed' */ | 116 | *pf = NULL; /* file handle is currently `closed' */ |
| 114 | luaL_getmetatable(L, LUA_FILEHANDLE); | 117 | luaL_setmetatable(L, LUA_FILEHANDLE); |
| 115 | lua_setmetatable(L, -2); | ||
| 116 | return pf; | 118 | return pf; |
| 117 | } | 119 | } |
| 118 | 120 | ||
| @@ -371,22 +373,32 @@ static int read_line (lua_State *L, FILE *f, int chop) { · 252 unmodified lines | |||
| 371 | } | 373 | } |
| 372 | 374 | ||
| 373 | 375 | ||
| 374 | static int read_chars (lua_State *L, FILE *f, size_t n) { | 376 | static void read_all (lua_State *L, FILE *f) { |
| 375 | size_t tbr = n; /* number of chars to be read */ | 377 | size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */ |
| 376 | size_t rlen; /* how much to read in each cycle */ | ||
| 377 | size_t nr; /* number of chars actually read in each cycle */ | ||
| 378 | luaL_Buffer b; | 378 | luaL_Buffer b; |
| 379 | luaL_buffinit(L, &b); | 379 | luaL_buffinit(L, &b); |
| 380 | rlen = LUAL_BUFFERSIZE; /* try to read that much each time */ | 380 | for (;;) { |
| 381 | do { | 381 | char *p = luaL_prepbuffsize(&b, rlen); |
| 382 | char *p = luaL_prepbuffer(&b); | 382 | size_t nr = fread(p, sizeof(char), rlen, f); |
| 383 | if (rlen > tbr) rlen = tbr; /* cannot read more than asked */ | ||
| 384 | nr = fread(p, sizeof(char), rlen, f); | ||
| 385 | luaL_addsize(&b, nr); | 383 | luaL_addsize(&b, nr); |
| 386 | tbr -= nr; /* still have to read 'tbr' chars */ | 384 | if (nr < rlen) break; /* eof? */ |
| 387 | } while (tbr > 0 && nr == rlen); /* until end of count or eof */ | 385 | else if (rlen <= (MAX_SIZE_T / 4)) /* avoid buffers too large */ |
| 386 | rlen *= 2; /* double buffer size at each iteration */ | ||
| 387 | } | ||
| 388 | luaL_pushresult(&b); /* close buffer */ | ||
| 389 | } | ||
| 390 | |||
| 391 | |||
| 392 | static int read_chars (lua_State *L, FILE *f, size_t n) { | ||
| 393 | size_t nr; /* number of chars actually read */ | ||
| 394 | char *p; | ||
| 395 | luaL_Buffer b; | ||
| 396 | luaL_buffinit(L, &b); | ||
| 397 | p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */ | ||
| 398 | nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */ | ||
| 399 | luaL_addsize(&b, nr); | ||
| 388 | luaL_pushresult(&b); /* close buffer */ | 400 | luaL_pushresult(&b); /* close buffer */ |
| 389 | return (tbr < n); /* true iff read something */ | 401 | return (nr > 0); /* true iff read something */ |
| 390 | } | 402 | } |
| 391 | 403 | ||
| 392 | 404 | ||
| @@ -421,7 +433,7 @@ static int g_read (lua_State *L, FILE *f, int first) { · 28 unmodified lines | |||
| 421 | success = read_line(L, f, 0); | 433 | success = read_line(L, f, 0); |
| 422 | break; | 434 | break; |
| 423 | case 'a': /* file */ | 435 | case 'a': /* file */ |
| 424 | read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */ | 436 | read_all(L, f); /* read entire file */ |
| 425 | success = 1; /* always success */ | 437 | success = 1; /* always success */ |
| 426 | break; | 438 | break; |
| 427 | default: | 439 | default: |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.82 2010/05/31 16:08:55 roberto Exp $ | 2 | ** $Id: llimits.h,v 1.84 2010/11/08 16:33:20 roberto Exp $ |
| 3 | ** Limits, basic types, and some other `installation-dependent' definitions | 3 | ** Limits, basic types, and some other `installation-dependent' definitions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -168,6 +168,96 @@ typedef lu_int32 Instruction; · 162 unmodified lines | |||
| 168 | #define luai_userstateyield(L,n) ((void)L) | 168 | #define luai_userstateyield(L,n) ((void)L) |
| 169 | #endif | 169 | #endif |
| 170 | 170 | ||
| 171 | /* | ||
| 172 | ** lua_number2int is a macro to convert lua_Number to int. | ||
| 173 | ** lua_number2integer is a macro to convert lua_Number to lua_Integer. | ||
| 174 | ** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned. | ||
| 175 | ** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number. | ||
| 176 | */ | ||
| 177 | |||
| 178 | #if defined(MS_ASMTRICK) /* { */ | ||
| 179 | /* trick with Microsoft assembler for X86 */ | ||
| 180 | |||
| 181 | #define lua_number2int(i,n) __asm {__asm fld n __asm fistp i} | ||
| 182 | #define lua_number2integer(i,n) lua_number2int(i, n) | ||
| 183 | #define lua_number2unsigned(i,n) \ | ||
| 184 | {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;} | ||
| 185 | |||
| 186 | |||
| 187 | #elif defined(LUA_IEEE754TRICK) /* }{ */ | ||
| 188 | /* the next trick should work on any machine using IEEE754 with | ||
| 189 | a 32-bit integer type */ | ||
| 190 | |||
| 191 | union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; | ||
| 192 | |||
| 193 | #if !defined(LUA_IEEEENDIAN) /* { */ | ||
| 194 | #define LUAI_EXTRAIEEE \ | ||
| 195 | static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)}; | ||
| 196 | #define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33) | ||
| 197 | #else | ||
| 198 | #define LUAI_EXTRAIEEE /* empty */ | ||
| 199 | #endif /* } */ | ||
| 200 | |||
| 201 | #define lua_number2int32(i,n,t) \ | ||
| 202 | { LUAI_EXTRAIEEE \ | ||
| 203 | volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \ | ||
| 204 | (i) = (t)u.l_p[LUA_IEEEENDIAN]; } | ||
| 205 | |||
| 206 | #define lua_number2int(i,n) lua_number2int32(i, n, int) | ||
| 207 | #define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer) | ||
| 208 | #define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned) | ||
| 209 | |||
| 210 | #endif /* } */ | ||
| 211 | |||
| 212 | |||
| 213 | /* the following definitions always work, but may be slow */ | ||
| 214 | |||
| 215 | #if !defined(lua_number2int) | ||
| 216 | #define lua_number2int(i,n) ((i)=(int)(n)) | ||
| 217 | #endif | ||
| 218 | |||
| 219 | #if !defined(lua_number2integer) | ||
| 220 | #define lua_number2integer(i,n) ((i)=(lua_Integer)(n)) | ||
| 221 | #endif | ||
| 222 | |||
| 223 | #if !defined(lua_number2unsigned) /* { */ | ||
| 224 | /* the following definition assures proper modulo behavior */ | ||
| 225 | #if defined(LUA_NUMBER_DOUBLE) | ||
| 226 | #include <math.h> | ||
| 227 | #define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1) | ||
| 228 | #define lua_number2unsigned(i,n) \ | ||
| 229 | ((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED)) | ||
| 230 | #else | ||
| 231 | #define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n)) | ||
| 232 | #endif | ||
| 233 | #endif /* } */ | ||
| 234 | |||
| 235 | |||
| 236 | #if !defined(lua_unsigned2number) | ||
| 237 | /* on several machines, coercion from unsigned to double is slow, | ||
| 238 | so it may be worth to avoid */ | ||
| 239 | #define lua_unsigned2number(u) \ | ||
| 240 | (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u)) | ||
| 241 | #endif | ||
| 242 | |||
| 243 | |||
| 244 | /* | ||
| 245 | ** luai_hashnum is a macro do hash a lua_Number value into an integer. | ||
| 246 | ** The hash must be deterministic and give reasonable values for | ||
| 247 | ** both small and large values (outside the range of integers). | ||
| 248 | ** It is used only in ltable.c. | ||
| 249 | */ | ||
| 250 | |||
| 251 | #if !defined(luai_hashnum) /* { */ | ||
| 252 | |||
| 253 | #include <float.h> | ||
| 254 | #include <math.h> | ||
| 255 | |||
| 256 | #define luai_hashnum(i,n) { int e; \ | ||
| 257 | n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \ | ||
| 258 | lua_number2int(i, n); i += e; } | ||
| 259 | |||
| 260 | #endif /* } */ | ||
| 171 | 261 | ||
| 172 | 262 | ||
| 173 | 263 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.76 2010/10/25 20:31:11 roberto Exp $ | 2 | ** $Id: lmathlib.c,v 1.78 2010/11/12 15:47:34 roberto Exp $ |
| 3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -22,92 +22,101 @@ · 16 unmodified lines | |||
| 22 | #define RADIANS_PER_DEGREE (PI/180.0) | 22 | #define RADIANS_PER_DEGREE (PI/180.0) |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | /* macro 'l_tg' allows the addition of an 'l' or 'f' to all math operations */ | ||
| 26 | #if !defined(l_tg) | ||
| 27 | #define l_tg(x) (x) | ||
| 28 | #endif | ||
| 29 | |||
| 30 | |||
| 25 | 31 | ||
| 26 | static int math_abs (lua_State *L) { | 32 | static int math_abs (lua_State *L) { |
| 27 | lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); | 33 | lua_pushnumber(L, l_tg(fabs)(luaL_checknumber(L, 1))); |
| 28 | return 1; | 34 | return 1; |
| 29 | } | 35 | } |
| 30 | 36 | ||
| 31 | static int math_sin (lua_State *L) { | 37 | static int math_sin (lua_State *L) { |
| 32 | lua_pushnumber(L, sin(luaL_checknumber(L, 1))); | 38 | lua_pushnumber(L, l_tg(sin)(luaL_checknumber(L, 1))); |
| 33 | return 1; | 39 | return 1; |
| 34 | } | 40 | } |
| 35 | 41 | ||
| 36 | static int math_sinh (lua_State *L) { | 42 | static int math_sinh (lua_State *L) { |
| 37 | lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); | 43 | lua_pushnumber(L, l_tg(sinh)(luaL_checknumber(L, 1))); |
| 38 | return 1; | 44 | return 1; |
| 39 | } | 45 | } |
| 40 | 46 | ||
| 41 | static int math_cos (lua_State *L) { | 47 | static int math_cos (lua_State *L) { |
| 42 | lua_pushnumber(L, cos(luaL_checknumber(L, 1))); | 48 | lua_pushnumber(L, l_tg(cos)(luaL_checknumber(L, 1))); |
| 43 | return 1; | 49 | return 1; |
| 44 | } | 50 | } |
| 45 | 51 | ||
| 46 | static int math_cosh (lua_State *L) { | 52 | static int math_cosh (lua_State *L) { |
| 47 | lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); | 53 | lua_pushnumber(L, l_tg(cosh)(luaL_checknumber(L, 1))); |
| 48 | return 1; | 54 | return 1; |
| 49 | } | 55 | } |
| 50 | 56 | ||
| 51 | static int math_tan (lua_State *L) { | 57 | static int math_tan (lua_State *L) { |
| 52 | lua_pushnumber(L, tan(luaL_checknumber(L, 1))); | 58 | lua_pushnumber(L, l_tg(tan)(luaL_checknumber(L, 1))); |
| 53 | return 1; | 59 | return 1; |
| 54 | } | 60 | } |
| 55 | 61 | ||
| 56 | static int math_tanh (lua_State *L) { | 62 | static int math_tanh (lua_State *L) { |
| 57 | lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); | 63 | lua_pushnumber(L, l_tg(tanh)(luaL_checknumber(L, 1))); |
| 58 | return 1; | 64 | return 1; |
| 59 | } | 65 | } |
| 60 | 66 | ||
| 61 | static int math_asin (lua_State *L) { | 67 | static int math_asin (lua_State *L) { |
| 62 | lua_pushnumber(L, asin(luaL_checknumber(L, 1))); | 68 | lua_pushnumber(L, l_tg(asin)(luaL_checknumber(L, 1))); |
| 63 | return 1; | 69 | return 1; |
| 64 | } | 70 | } |
| 65 | 71 | ||
| 66 | static int math_acos (lua_State *L) { | 72 | static int math_acos (lua_State *L) { |
| 67 | lua_pushnumber(L, acos(luaL_checknumber(L, 1))); | 73 | lua_pushnumber(L, l_tg(acos)(luaL_checknumber(L, 1))); |
| 68 | return 1; | 74 | return 1; |
| 69 | } | 75 | } |
| 70 | 76 | ||
| 71 | static int math_atan (lua_State *L) { | 77 | static int math_atan (lua_State *L) { |
| 72 | lua_pushnumber(L, atan(luaL_checknumber(L, 1))); | 78 | lua_pushnumber(L, l_tg(atan)(luaL_checknumber(L, 1))); |
| 73 | return 1; | 79 | return 1; |
| 74 | } | 80 | } |
| 75 | 81 | ||
| 76 | static int math_atan2 (lua_State *L) { | 82 | static int math_atan2 (lua_State *L) { |
| 77 | lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); | 83 | lua_pushnumber(L, l_tg(atan2)(luaL_checknumber(L, 1), |
| 84 | luaL_checknumber(L, 2))); | ||
| 78 | return 1; | 85 | return 1; |
| 79 | } | 86 | } |
| 80 | 87 | ||
| 81 | static int math_ceil (lua_State *L) { | 88 | static int math_ceil (lua_State *L) { |
| 82 | lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); | 89 | lua_pushnumber(L, l_tg(ceil)(luaL_checknumber(L, 1))); |
| 83 | return 1; | 90 | return 1; |
| 84 | } | 91 | } |
| 85 | 92 | ||
| 86 | static int math_floor (lua_State *L) { | 93 | static int math_floor (lua_State *L) { |
| 87 | lua_pushnumber(L, floor(luaL_checknumber(L, 1))); | 94 | lua_pushnumber(L, l_tg(floor)(luaL_checknumber(L, 1))); |
| 88 | return 1; | 95 | return 1; |
| 89 | } | 96 | } |
| 90 | 97 | ||
| 91 | static int math_fmod (lua_State *L) { | 98 | static int math_fmod (lua_State *L) { |
| 92 | lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); | 99 | lua_pushnumber(L, l_tg(fmod)(luaL_checknumber(L, 1), |
| 100 | luaL_checknumber(L, 2))); | ||
| 93 | return 1; | 101 | return 1; |
| 94 | } | 102 | } |
| 95 | 103 | ||
| 96 | static int math_modf (lua_State *L) { | 104 | static int math_modf (lua_State *L) { |
| 97 | double ip; | 105 | lua_Number ip; |
| 98 | double fp = modf(luaL_checknumber(L, 1), &ip); | 106 | lua_Number fp = l_tg(modf)(luaL_checknumber(L, 1), &ip); |
| 99 | lua_pushnumber(L, ip); | 107 | lua_pushnumber(L, ip); |
| 100 | lua_pushnumber(L, fp); | 108 | lua_pushnumber(L, fp); |
| 101 | return 2; | 109 | return 2; |
| 102 | } | 110 | } |
| 103 | 111 | ||
| 104 | static int math_sqrt (lua_State *L) { | 112 | static int math_sqrt (lua_State *L) { |
| 105 | lua_pushnumber(L, sqrt(luaL_checknumber(L, 1))); | 113 | lua_pushnumber(L, l_tg(sqrt)(luaL_checknumber(L, 1))); |
| 106 | return 1; | 114 | return 1; |
| 107 | } | 115 | } |
| 108 | 116 | ||
| 109 | static int math_pow (lua_State *L) { | 117 | static int math_pow (lua_State *L) { |
| 110 | lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); | 118 | lua_pushnumber(L, l_tg(pow)(luaL_checknumber(L, 1), |
| 119 | luaL_checknumber(L, 2))); | ||
| 111 | return 1; | 120 | return 1; |
| 112 | } | 121 | } |
| 113 | 122 | ||
| @@ -115,11 +124,11 @@ static int math_log (lua_State *L) { · 1 unmodified line | |||
| 115 | lua_Number x = luaL_checknumber(L, 1); | 124 | lua_Number x = luaL_checknumber(L, 1); |
| 116 | lua_Number res; | 125 | lua_Number res; |
| 117 | if (lua_isnoneornil(L, 2)) | 126 | if (lua_isnoneornil(L, 2)) |
| 118 | res = log(x); | 127 | res = l_tg(log)(x); |
| 119 | else { | 128 | else { |
| 120 | lua_Number base = luaL_checknumber(L, 2); | 129 | lua_Number base = luaL_checknumber(L, 2); |
| 121 | if (base == 10.0) res = log10(x); | 130 | if (base == 10.0) res = l_tg(log10)(x); |
| 122 | else res = log(x)/log(base); | 131 | else res = l_tg(log)(x)/l_tg(log)(base); |
| 123 | } | 132 | } |
| 124 | lua_pushnumber(L, res); | 133 | lua_pushnumber(L, res); |
| 125 | return 1; | 134 | return 1; |
| @@ -130,12 +139,12 @@ static int math_log10 (lua_State *L) { · 4 unmodified lines | |||
| 130 | luaL_error(L, "function " LUA_QL("log10") | 139 | luaL_error(L, "function " LUA_QL("log10") |
| 131 | " is deprecated; use log(x, 10) instead"); | 140 | " is deprecated; use log(x, 10) instead"); |
| 132 | #endif | 141 | #endif |
| 133 | lua_pushnumber(L, log10(luaL_checknumber(L, 1))); | 142 | lua_pushnumber(L, l_tg(log10)(luaL_checknumber(L, 1))); |
| 134 | return 1; | 143 | return 1; |
| 135 | } | 144 | } |
| 136 | 145 | ||
| 137 | static int math_exp (lua_State *L) { | 146 | static int math_exp (lua_State *L) { |
| 138 | lua_pushnumber(L, exp(luaL_checknumber(L, 1))); | 147 | lua_pushnumber(L, l_tg(exp)(luaL_checknumber(L, 1))); |
| 139 | return 1; | 148 | return 1; |
| 140 | } | 149 | } |
| 141 | 150 | ||
| @@ -151,13 +160,14 @@ static int math_rad (lua_State *L) { · 9 unmodified lines | |||
| 151 | 160 | ||
| 152 | static int math_frexp (lua_State *L) { | 161 | static int math_frexp (lua_State *L) { |
| 153 | int e; | 162 | int e; |
| 154 | lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); | 163 | lua_pushnumber(L, l_tg(frexp)(luaL_checknumber(L, 1), &e)); |
| 155 | lua_pushinteger(L, e); | 164 | lua_pushinteger(L, e); |
| 156 | return 2; | 165 | return 2; |
| 157 | } | 166 | } |
| 158 | 167 | ||
| 159 | static int math_ldexp (lua_State *L) { | 168 | static int math_ldexp (lua_State *L) { |
| 160 | lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); | 169 | lua_pushnumber(L, l_tg(ldexp)(luaL_checknumber(L, 1), |
| 170 | luaL_checkint(L, 2))); | ||
| 161 | return 1; | 171 | return 1; |
| 162 | } | 172 | } |
| 163 | 173 | ||
| @@ -203,14 +213,14 @@ static int math_random (lua_State *L) { · 39 unmodified lines | |||
| 203 | case 1: { /* only upper limit */ | 213 | case 1: { /* only upper limit */ |
| 204 | lua_Number u = luaL_checknumber(L, 1); | 214 | lua_Number u = luaL_checknumber(L, 1); |
| 205 | luaL_argcheck(L, 1.0 <= u, 1, "interval is empty"); | 215 | luaL_argcheck(L, 1.0 <= u, 1, "interval is empty"); |
| 206 | lua_pushnumber(L, floor(r*u) + 1.0); /* int between 1 and `u' */ | 216 | lua_pushnumber(L, l_tg(floor)(r*u) + 1.0); /* int in [1, u] */ |
| 207 | break; | 217 | break; |
| 208 | } | 218 | } |
| 209 | case 2: { /* lower and upper limits */ | 219 | case 2: { /* lower and upper limits */ |
| 210 | lua_Number l = luaL_checknumber(L, 1); | 220 | lua_Number l = luaL_checknumber(L, 1); |
| 211 | lua_Number u = luaL_checknumber(L, 2); | 221 | lua_Number u = luaL_checknumber(L, 2); |
| 212 | luaL_argcheck(L, l <= u, 2, "interval is empty"); | 222 | luaL_argcheck(L, l <= u, 2, "interval is empty"); |
| 213 | lua_pushnumber(L, floor(r*(u-l+1)) + l); /* int between `l' and `u' */ | 223 | lua_pushnumber(L, l_tg(floor)(r*(u-l+1)) + l); /* int in [l, u] */ |
| 214 | break; | 224 | break; |
| 215 | } | 225 | } |
| 216 | default: return luaL_error(L, "wrong number of arguments"); | 226 | default: return luaL_error(L, "wrong number of arguments"); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.92 2010/10/29 14:35:09 roberto Exp $ | 2 | ** $Id: loadlib.c,v 1.94 2010/11/10 20:00:04 roberto Exp $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -239,8 +239,7 @@ static void **ll_register (lua_State *L, const char *path) { · 233 unmodified lines | |||
| 239 | lua_pop(L, 1); /* remove result from gettable */ | 239 | lua_pop(L, 1); /* remove result from gettable */ |
| 240 | plib = (void **)lua_newuserdata(L, sizeof(const void *)); | 240 | plib = (void **)lua_newuserdata(L, sizeof(const void *)); |
| 241 | *plib = NULL; | 241 | *plib = NULL; |
| 242 | luaL_getmetatable(L, "_LOADLIB"); | 242 | luaL_setmetatable(L, "_LOADLIB"); |
| 243 | lua_setmetatable(L, -2); | ||
| 244 | lua_pushfstring(L, "%s%s", LIBPREFIX, path); | 243 | lua_pushfstring(L, "%s%s", LIBPREFIX, path); |
| 245 | lua_pushvalue(L, -2); | 244 | lua_pushvalue(L, -2); |
| 246 | lua_settable(L, LUA_REGISTRYINDEX); | 245 | lua_settable(L, LUA_REGISTRYINDEX); |
| @@ -435,21 +434,14 @@ static int loader_preload (lua_State *L) { · 188 unmodified lines | |||
| 435 | } | 434 | } |
| 436 | 435 | ||
| 437 | 436 | ||
| 438 | static const int sentinel_ = 0; | ||
| 439 | #define sentinel ((void *)&sentinel_) | ||
| 440 | |||
| 441 | |||
| 442 | static int ll_require (lua_State *L) { | 437 | static int ll_require (lua_State *L) { |
| 443 | const char *name = luaL_checkstring(L, 1); | 438 | const char *name = luaL_checkstring(L, 1); |
| 444 | int i; | 439 | int i; |
| 445 | lua_settop(L, 1); /* _LOADED table will be at index 2 */ | 440 | lua_settop(L, 1); /* _LOADED table will be at index 2 */ |
| 446 | lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); | 441 | lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); |
| 447 | lua_getfield(L, 2, name); | 442 | lua_getfield(L, 2, name); |
| 448 | if (lua_toboolean(L, -1)) { /* is it there? */ | 443 | if (lua_toboolean(L, -1)) /* is it there? */ |
| 449 | if (lua_touserdata(L, -1) == sentinel) /* check loops */ | ||
| 450 | luaL_error(L, "loop or previous error loading module " LUA_QS, name); | ||
| 451 | return 1; /* package is already loaded */ | 444 | return 1; /* package is already loaded */ |
| 452 | } | ||
| 453 | /* else must load it; iterate over available loaders */ | 445 | /* else must load it; iterate over available loaders */ |
| 454 | lua_getfield(L, lua_upvalueindex(1), "loaders"); | 446 | lua_getfield(L, lua_upvalueindex(1), "loaders"); |
| 455 | if (!lua_istable(L, -1)) | 447 | if (!lua_istable(L, -1)) |
| @@ -469,14 +461,12 @@ static int ll_require (lua_State *L) { · 13 unmodified lines | |||
| 469 | else | 461 | else |
| 470 | lua_pop(L, 1); | 462 | lua_pop(L, 1); |
| 471 | } | 463 | } |
| 472 | lua_pushlightuserdata(L, sentinel); | ||
| 473 | lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */ | ||
| 474 | lua_pushstring(L, name); /* pass name as argument to module */ | 464 | lua_pushstring(L, name); /* pass name as argument to module */ |
| 475 | lua_call(L, 1, 1); /* run loaded module */ | 465 | lua_call(L, 1, 1); /* run loaded module */ |
| 476 | if (!lua_isnil(L, -1)) /* non-nil return? */ | 466 | if (!lua_isnil(L, -1)) /* non-nil return? */ |
| 477 | lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ | 467 | lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ |
| 478 | lua_getfield(L, 2, name); | 468 | lua_getfield(L, 2, name); |
| 479 | if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */ | 469 | if (lua_isnil(L, -1)) { /* module did not set a value? */ |
| 480 | lua_pushboolean(L, 1); /* use true as result */ | 470 | lua_pushboolean(L, 1); /* use true as result */ |
| 481 | lua_pushvalue(L, -1); /* extra copy to be returned */ | 471 | lua_pushvalue(L, -1); /* extra copy to be returned */ |
| 482 | lua_setfield(L, 2, name); /* _LOADED[name] = true */ | 472 | lua_setfield(L, 2, name); /* _LOADED[name] = true */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.156 2010/10/29 17:52:46 roberto Exp $ | 2 | ** $Id: lstrlib.c,v 1.157 2010/11/08 17:38:37 roberto Exp $ |
| 3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -722,6 +722,7 @@ static int str_gsub (lua_State *L) { · 716 unmodified lines | |||
| 722 | ** 'string.format'; LUA_INTFRM_T is the integer type corresponding to | 722 | ** 'string.format'; LUA_INTFRM_T is the integer type corresponding to |
| 723 | ** the previous length | 723 | ** the previous length |
| 724 | */ | 724 | */ |
| 725 | #if !defined(LUA_INTFRMLEN) /* { */ | ||
| 725 | #if defined(LUA_USELONGLONG) | 726 | #if defined(LUA_USELONGLONG) |
| 726 | 727 | ||
| 727 | #define LUA_INTFRMLEN "ll" | 728 | #define LUA_INTFRMLEN "ll" |
| @@ -732,6 +733,20 @@ static int str_gsub (lua_State *L) { · 4 unmodified lines | |||
| 732 | #define LUA_INTFRMLEN "l" | 733 | #define LUA_INTFRMLEN "l" |
| 733 | #define LUA_INTFRM_T long | 734 | #define LUA_INTFRM_T long |
| 734 | 735 | ||
| 736 | #endif | ||
| 737 | #endif /* } */ | ||
| 738 | |||
| 739 | |||
| 740 | /* | ||
| 741 | ** LUA_FLTFRMLEN is the length modifier for float conversions in | ||
| 742 | ** 'string.format'; LUA_FLTFRM_T is the float type corresponding to | ||
| 743 | ** the previous length | ||
| 744 | */ | ||
| 745 | #if !defined(LUA_FLTFRMLEN) | ||
| 746 | |||
| 747 | #define LUA_FLTFRMLEN "" | ||
| 748 | #define LUA_FLTFRM_T double | ||
| 749 | |||
| 735 | #endif | 750 | #endif |
| 736 | 751 | ||
| 737 | 752 | ||
| @@ -793,14 +808,15 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { · 55 unmodified lines | |||
| 793 | 808 | ||
| 794 | 809 | ||
| 795 | /* | 810 | /* |
| 796 | ** add length modifier into integer formats | 811 | ** add length modifier into formats |
| 797 | */ | 812 | */ |
| 798 | static void addintlen (char *form) { | 813 | static void addlenmod (char *form, const char *lenmod) { |
| 799 | size_t l = strlen(form); | 814 | size_t l = strlen(form); |
| 815 | size_t lm = strlen(lenmod); | ||
| 800 | char spec = form[l - 1]; | 816 | char spec = form[l - 1]; |
| 801 | strcpy(form + l - 1, LUA_INTFRMLEN); | 817 | strcpy(form + l - 1, lenmod); |
| 802 | form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; | 818 | form[l + lm - 1] = spec; |
| 803 | form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; | 819 | form[l + lm] = '\0'; |
| 804 | } | 820 | } |
| 805 | 821 | ||
| 806 | 822 | ||
| @@ -834,13 +850,14 @@ static int str_format (lua_State *L) { · 27 unmodified lines | |||
| 834 | lua_Number n = luaL_checknumber(L, arg); | 850 | lua_Number n = luaL_checknumber(L, arg); |
| 835 | LUA_INTFRM_T r = (n < 0) ? (LUA_INTFRM_T)n : | 851 | LUA_INTFRM_T r = (n < 0) ? (LUA_INTFRM_T)n : |
| 836 | (LUA_INTFRM_T)(unsigned LUA_INTFRM_T)n; | 852 | (LUA_INTFRM_T)(unsigned LUA_INTFRM_T)n; |
| 837 | addintlen(form); | 853 | addlenmod(form, LUA_INTFRMLEN); |
| 838 | nb = sprintf(buff, form, r); | 854 | nb = sprintf(buff, form, r); |
| 839 | break; | 855 | break; |
| 840 | } | 856 | } |
| 841 | case 'e': case 'E': case 'f': | 857 | case 'e': case 'E': case 'f': |
| 842 | case 'g': case 'G': { | 858 | case 'g': case 'G': { |
| 843 | nb = sprintf(buff, form, (double)luaL_checknumber(L, arg)); | 859 | addlenmod(form, LUA_FLTFRMLEN); |
| 860 | nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg)); | ||
| 844 | break; | 861 | break; |
| 845 | } | 862 | } |
| 846 | case 'q': { | 863 | case 'q': { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.52 2010/06/25 12:18:10 roberto Exp $ | 2 | ** $Id: ltable.c,v 2.53 2010/11/11 15:38:43 roberto Exp $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -38,8 +38,8 @@ · 32 unmodified lines | |||
| 38 | /* | 38 | /* |
| 39 | ** max size of array part is 2^MAXBITS | 39 | ** max size of array part is 2^MAXBITS |
| 40 | */ | 40 | */ |
| 41 | #if LUAI_BITSINT > 26 | 41 | #if LUAI_BITSINT >= 32 |
| 42 | #define MAXBITS 26 | 42 | #define MAXBITS 30 |
| 43 | #else | 43 | #else |
| 44 | #define MAXBITS (LUAI_BITSINT-2) | 44 | #define MAXBITS (LUAI_BITSINT-2) |
| 45 | #endif | 45 | #endif |
| @@ -18,7 +18,7 @@ · 17 unmodified lines | |||
| 18 | 18 | ||
| 19 | #define LUA_VERSION_MAJOR "5" | 19 | #define LUA_VERSION_MAJOR "5" |
| 20 | #define LUA_VERSION_MINOR "2" | 20 | #define LUA_VERSION_MINOR "2" |
| 21 | #define LUA_VERSION_RELEASE "0" " (work5)" | 21 | #define LUA_VERSION_RELEASE "0" " (alpha)" |
| 22 | 22 | ||
| 23 | #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR | 23 | #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR |
| 24 | #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE | 24 | #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luaconf.h,v 1.148 2010/10/29 17:52:46 roberto Exp $ | 2 | ** $Id: luaconf.h,v 1.151 2010/11/12 15:48:30 roberto Exp $ |
| 3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -229,7 +229,7 @@ · 223 unmodified lines | |||
| 229 | ** You can define it to get all options, or change specific options | 229 | ** You can define it to get all options, or change specific options |
| 230 | ** to fit your specific needs. | 230 | ** to fit your specific needs. |
| 231 | */ | 231 | */ |
| 232 | #if defined(LUA_COMPAT_ALL) | 232 | #if defined(LUA_COMPAT_ALL) /* { */ |
| 233 | 233 | ||
| 234 | /* | 234 | /* |
| 235 | @@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'. | 235 | @@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'. |
| @@ -238,8 +238,8 @@ · 2 unmodified lines | |||
| 238 | #define LUA_COMPAT_UNPACK | 238 | #define LUA_COMPAT_UNPACK |
| 239 | 239 | ||
| 240 | /* | 240 | /* |
| 241 | @@ LUA_COMPAT_CPCALL controls the presence of macro 'lua_cpcall'. | 241 | @@ macro 'lua_cpcall' emulates deprecated function lua_cpcall. |
| 242 | ** You can call your C function directly (with light C functions) | 242 | ** You can call your C function directly (with light C functions). |
| 243 | */ | 243 | */ |
| 244 | #define lua_cpcall(L,f,u) \ | 244 | #define lua_cpcall(L,f,u) \ |
| 245 | (lua_pushcfunction(L, (f)), \ | 245 | (lua_pushcfunction(L, (f)), \ |
| @@ -258,14 +258,6 @@ · 12 unmodified lines | |||
| 258 | */ | 258 | */ |
| 259 | #define LUA_COMPAT_MAXN | 259 | #define LUA_COMPAT_MAXN |
| 260 | 260 | ||
| 261 | /* | ||
| 262 | @@ LUA_COMPAT_DEBUGLIB controls compatibility with preloading | ||
| 263 | ** the debug library. | ||
| 264 | ** You should add 'require"debug"' everywhere you need the debug | ||
| 265 | ** library. | ||
| 266 | */ | ||
| 267 | #define LUA_COMPAT_DEBUGLIB | ||
| 268 | |||
| 269 | /* | 261 | /* |
| 270 | @@ The following macros supply trivial compatibility for some | 262 | @@ The following macros supply trivial compatibility for some |
| 271 | ** changes in the API. The macros themselves document how to | 263 | ** changes in the API. The macros themselves document how to |
| @@ -275,19 +267,16 @@ · 3 unmodified lines | |||
| 275 | 267 | ||
| 276 | #define lua_objlen(L,i) lua_rawlen(L, (i)) | 268 | #define lua_objlen(L,i) lua_rawlen(L, (i)) |
| 277 | 269 | ||
| 278 | #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) | 270 | #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) |
| 279 | #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) | 271 | #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) |
| 280 | 272 | ||
| 281 | /* compatibility with previous wrong spelling */ | ||
| 282 | #define luaL_typerror luaL_typeerror | ||
| 283 | |||
| 284 | /* | 273 | /* |
| 285 | @@ LUA_COMPAT_MODULE controls compatibility with previous | 274 | @@ LUA_COMPAT_MODULE controls compatibility with previous |
| 286 | ** module functions 'module' (Lua) and 'luaL_register' (C). | 275 | ** module functions 'module' (Lua) and 'luaL_register' (C). |
| 287 | */ | 276 | */ |
| 288 | #define LUA_COMPAT_MODULE | 277 | #define LUA_COMPAT_MODULE |
| 289 | 278 | ||
| 290 | #endif /* LUA_COMPAT_ALL */ | 279 | #endif /* } */ |
| 291 | 280 | ||
| 292 | /* }================================================================== */ | 281 | /* }================================================================== */ |
| 293 | 282 | ||
| @@ -348,27 +337,13 @@ · 54 unmodified lines | |||
| 348 | 337 | ||
| 349 | 338 | ||
| 350 | 339 | ||
| 351 | /* | ||
| 352 | ** {================================================================== | ||
| 353 | ** CHANGE (to smaller values) the following definitions if your system | ||
| 354 | ** has a small C stack. (Or you may want to change them to larger | ||
| 355 | ** values if your system has a large C stack and these limits are | ||
| 356 | ** too rigid for you.) Some of these constants control the size of | ||
| 357 | ** stack-allocated arrays used by the compiler or the interpreter, while | ||
| 358 | ** others limit the maximum number of recursive calls that the compiler | ||
| 359 | ** or the interpreter can perform. Values too large may cause a C stack | ||
| 360 | ** overflow for some forms of deep constructs. | ||
| 361 | ** =================================================================== | ||
| 362 | */ | ||
| 363 | |||
| 364 | 340 | ||
| 365 | /* | 341 | /* |
| 366 | @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. | 342 | @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. |
| 343 | ** CHANGE it if it uses too much C-stack space. | ||
| 367 | */ | 344 | */ |
| 368 | #define LUAL_BUFFERSIZE BUFSIZ | 345 | #define LUAL_BUFFERSIZE BUFSIZ |
| 369 | 346 | ||
| 370 | /* }================================================================== */ | ||
| 371 | |||
| 372 | 347 | ||
| 373 | 348 | ||
| 374 | 349 | ||
| @@ -445,32 +420,21 @@ · 70 unmodified lines | |||
| 445 | #define LUA_UNSIGNED unsigned LUA_INT32 | 420 | #define LUA_UNSIGNED unsigned LUA_INT32 |
| 446 | 421 | ||
| 447 | 422 | ||
| 448 | /* | ||
| 449 | @@ lua_number2int is a macro to convert lua_Number to int. | ||
| 450 | @@ lua_number2integer is a macro to convert lua_Number to LUA_INTEGER. | ||
| 451 | @@ lua_number2uint is a macro to convert a lua_Number to a LUA_UNSIGNED. | ||
| 452 | @@ lua_uint2number is a macro to convert a LUA_UNSIGNED to a lua_Number. | ||
| 453 | */ | ||
| 454 | |||
| 455 | #if defined(LUA_CORE) /* { */ | 423 | #if defined(LUA_CORE) /* { */ |
| 456 | 424 | ||
| 457 | #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && \ | 425 | #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */ |
| 458 | !defined(LUA_NOIEEE754TRICK) /* { */ | ||
| 459 | 426 | ||
| 460 | /* On a Microsoft compiler on a Pentium, use assembler to avoid clashes | 427 | /* On a Microsoft compiler on a Pentium, use assembler to avoid clashes |
| 461 | with a DirectX idiosyncrasy */ | 428 | with a DirectX idiosyncrasy */ |
| 462 | #if defined(_MSC_VER) && defined(M_IX86) /* { */ | 429 | #if defined(_MSC_VER) && defined(M_IX86) /* { */ |
| 463 | 430 | ||
| 464 | #define lua_number2int(i,n) __asm {__asm fld n __asm fistp i} | 431 | #define MS_ASMTRICK |
| 465 | #define lua_number2integer(i,n) lua_number2int(i, n) | ||
| 466 | #define lua_number2uint(i,n) \ | ||
| 467 | {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;} | ||
| 468 | 432 | ||
| 469 | #else /* }{ */ | 433 | #else /* }{ */ |
| 470 | /* the next trick should work on any machine using IEEE754 with | 434 | /* the next definition uses a trick that should work on any machine |
| 471 | a 32-bit integer type */ | 435 | using IEEE754 with a 32-bit integer type */ |
| 472 | 436 | ||
| 473 | union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; | 437 | #define LUA_IEEE754TRICK |
| 474 | 438 | ||
| 475 | /* | 439 | /* |
| 476 | @@ LUA_IEEEENDIAN is the endianness of doubles in your machine | 440 | @@ LUA_IEEEENDIAN is the endianness of doubles in your machine |
| @@ -485,77 +449,11 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; · 8 unmodified lines | |||
| 485 | #define LUA_IEEEENDIAN 1 | 449 | #define LUA_IEEEENDIAN 1 |
| 486 | #endif | 450 | #endif |
| 487 | 451 | ||
| 488 | #if !defined(LUA_IEEEENDIAN) /* { */ | ||
| 489 | #define LUAI_EXTRAIEEE \ | ||
| 490 | static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)}; | ||
| 491 | #define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33) | ||
| 492 | #else | ||
| 493 | #define LUAI_EXTRAIEEE /* empty */ | ||
| 494 | #endif /* } */ | ||
| 495 | |||
| 496 | #define lua_number2int32(i,n,t) \ | ||
| 497 | { LUAI_EXTRAIEEE \ | ||
| 498 | volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \ | ||
| 499 | (i) = (t)u.l_p[LUA_IEEEENDIAN]; } | ||
| 500 | |||
| 501 | #define lua_number2int(i,n) lua_number2int32(i, n, int) | ||
| 502 | #define lua_number2integer(i,n) lua_number2int32(i, n, LUA_INTEGER) | ||
| 503 | #define lua_number2uint(i,n) lua_number2int32(i, n, LUA_UNSIGNED) | ||
| 504 | |||
| 505 | #endif /* } */ | 452 | #endif /* } */ |
| 506 | 453 | ||
| 507 | |||
| 508 | #endif /* } */ | 454 | #endif /* } */ |
| 509 | 455 | ||
| 510 | 456 | #endif /* } */ | |
| 511 | /* the following definitions always work, but may be slow */ | ||
| 512 | |||
| 513 | #if !defined(lua_number2int) | ||
| 514 | #define lua_number2int(i,n) ((i)=(int)(n)) | ||
| 515 | #endif | ||
| 516 | |||
| 517 | #if !defined(lua_number2integer) | ||
| 518 | #define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n)) | ||
| 519 | #endif | ||
| 520 | |||
| 521 | #if !defined(lua_number2uint) && (defined(lapi_c) || defined(luaall_c)) /* { */ | ||
| 522 | /* the following definition assures proper modulo behavior */ | ||
| 523 | #if defined(LUA_NUMBER_DOUBLE) | ||
| 524 | #include <math.h> | ||
| 525 | #define lua_number2uint(i,n) \ | ||
| 526 | ((i)=(LUA_UNSIGNED)((n) - floor((n)/4294967296.0)*4294967296.0)) | ||
| 527 | #else | ||
| 528 | #define lua_number2uint(i,n) ((i)=(LUA_UNSIGNED)(n)) | ||
| 529 | #endif | ||
| 530 | #endif /* } */ | ||
| 531 | |||
| 532 | #if !defined(lua_uint2number) | ||
| 533 | /* on several machines, coercion from unsigned to double is slow, | ||
| 534 | so it may be worth to avoid */ | ||
| 535 | #define lua_uint2number(u) \ | ||
| 536 | ((LUA_INT32)(u) < 0 ? (lua_Number)(u) : (lua_Number)(LUA_INT32)(u)) | ||
| 537 | #endif | ||
| 538 | |||
| 539 | #endif /* } */ | ||
| 540 | |||
| 541 | |||
| 542 | /* | ||
| 543 | @@ luai_hashnum is a macro do hash a lua_Number value into an integer. | ||
| 544 | @* The hash must be deterministic and give reasonable values for | ||
| 545 | @* both small and large values (outside the range of integers). | ||
| 546 | @* It is used only in ltable.c. | ||
| 547 | */ | ||
| 548 | |||
| 549 | #if defined(ltable_c) || defined(luaall_c) | ||
| 550 | |||
| 551 | #include <float.h> | ||
| 552 | #include <math.h> | ||
| 553 | |||
| 554 | #define luai_hashnum(i,n) { int e; \ | ||
| 555 | n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \ | ||
| 556 | lua_number2int(i, n); i += e; } | ||
| 557 | |||
| 558 | #endif /* ltable_c */ | ||
| 559 | 457 | ||
| 560 | /* }================================================================== */ | 458 | /* }================================================================== */ |
| 561 | 459 | ||