Unified · Split
| @@ -1,5 +1,5 @@ | |||
| 1 | 1 | ||
| 2 | This is Lua 5.3.0 (work3), released on 19 Jul 2014. | 2 | This is Lua 5.3.0 (alpha), released on 31 Jul 2014. |
| 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,7 +22,7 @@ Lua 5.3 Reference Manual · 21 unmodified lines | |||
| 22 | 22 | ||
| 23 | <P> | 23 | <P> |
| 24 | <IMG SRC="alert.png" ALIGN="absbottom"> | 24 | <IMG SRC="alert.png" ALIGN="absbottom"> |
| 25 | <EM>All details may change in the final version.</EM> | 25 | <EM>Some details may change in the final version.</EM> |
| 26 | 26 | ||
| 27 | <P> | 27 | <P> |
| 28 | The reference manual is the official definition of the Lua language. | 28 | The reference manual is the official definition of the Lua language. |
| @@ -37,7 +37,7 @@ For a complete introduction to Lua programming, see the book · 8 unmodified lines | |||
| 37 | <A HREF="#index">index</A> | 37 | <A HREF="#index">index</A> |
| 38 | <HR> | 38 | <HR> |
| 39 | <SMALL> | 39 | <SMALL> |
| 40 | Copyright © 2011–2014 Lua.org, PUC-Rio. | 40 | Copyright © 2014 Lua.org, PUC-Rio. |
| 41 | Freely available under the terms of the | 41 | Freely available under the terms of the |
| 42 | <A HREF="http://www.lua.org/license.html">Lua license</A>. | 42 | <A HREF="http://www.lua.org/license.html">Lua license</A>. |
| 43 | </SMALL> | 43 | </SMALL> |
| @@ -229,7 +229,6 @@ Freely available under the terms of the · 185 unmodified lines | |||
| 229 | <TD> | 229 | <TD> |
| 230 | <H3> </H3> | 230 | <H3> </H3> |
| 231 | <P> | 231 | <P> |
| 232 | <A HREF="manual.html#pdf-math">math</A><BR> | ||
| 233 | <A HREF="manual.html#pdf-math.abs">math.abs</A><BR> | 232 | <A HREF="manual.html#pdf-math.abs">math.abs</A><BR> |
| 234 | <A HREF="manual.html#pdf-math.acos">math.acos</A><BR> | 233 | <A HREF="manual.html#pdf-math.acos">math.acos</A><BR> |
| 235 | <A HREF="manual.html#pdf-math.asin">math.asin</A><BR> | 234 | <A HREF="manual.html#pdf-math.asin">math.asin</A><BR> |
| @@ -240,7 +239,6 @@ Freely available under the terms of the · 4 unmodified lines | |||
| 240 | <A HREF="manual.html#pdf-math.floor">math.floor</A><BR> | 239 | <A HREF="manual.html#pdf-math.floor">math.floor</A><BR> |
| 241 | <A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR> | 240 | <A HREF="manual.html#pdf-math.fmod">math.fmod</A><BR> |
| 242 | <A HREF="manual.html#pdf-math.huge">math.huge</A><BR> | 241 | <A HREF="manual.html#pdf-math.huge">math.huge</A><BR> |
| 243 | <A HREF="manual.html#pdf-math.ifloor">math.ifloor</A><BR> | ||
| 244 | <A HREF="manual.html#pdf-math.log">math.log</A><BR> | 242 | <A HREF="manual.html#pdf-math.log">math.log</A><BR> |
| 245 | <A HREF="manual.html#pdf-math.max">math.max</A><BR> | 243 | <A HREF="manual.html#pdf-math.max">math.max</A><BR> |
| 246 | <A HREF="manual.html#pdf-math.maxinteger">math.maxinteger</A><BR> | 244 | <A HREF="manual.html#pdf-math.maxinteger">math.maxinteger</A><BR> |
| @@ -254,7 +252,9 @@ Freely available under the terms of the · 7 unmodified lines | |||
| 254 | <A HREF="manual.html#pdf-math.sin">math.sin</A><BR> | 252 | <A HREF="manual.html#pdf-math.sin">math.sin</A><BR> |
| 255 | <A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR> | 253 | <A HREF="manual.html#pdf-math.sqrt">math.sqrt</A><BR> |
| 256 | <A HREF="manual.html#pdf-math.tan">math.tan</A><BR> | 254 | <A HREF="manual.html#pdf-math.tan">math.tan</A><BR> |
| 255 | <A HREF="manual.html#pdf-math.tointeger">math.tointeger</A><BR> | ||
| 257 | <A HREF="manual.html#pdf-math.type">math.type</A><BR> | 256 | <A HREF="manual.html#pdf-math.type">math.type</A><BR> |
| 257 | <A HREF="manual.html#pdf-math.ult">math.ult</A><BR> | ||
| 258 | 258 | ||
| 259 | <P> | 259 | <P> |
| 260 | <A HREF="manual.html#pdf-os.clock">os.clock</A><BR> | 260 | <A HREF="manual.html#pdf-os.clock">os.clock</A><BR> |
| @@ -301,6 +301,7 @@ Freely available under the terms of the · 40 unmodified lines | |||
| 301 | 301 | ||
| 302 | <P> | 302 | <P> |
| 303 | <A HREF="manual.html#pdf-table.concat">table.concat</A><BR> | 303 | <A HREF="manual.html#pdf-table.concat">table.concat</A><BR> |
| 304 | <A HREF="manual.html#pdf-table.copy">table.copy</A><BR> | ||
| 304 | <A HREF="manual.html#pdf-table.insert">table.insert</A><BR> | 305 | <A HREF="manual.html#pdf-table.insert">table.insert</A><BR> |
| 305 | <A HREF="manual.html#pdf-table.pack">table.pack</A><BR> | 306 | <A HREF="manual.html#pdf-table.pack">table.pack</A><BR> |
| 306 | <A HREF="manual.html#pdf-table.remove">table.remove</A><BR> | 307 | <A HREF="manual.html#pdf-table.remove">table.remove</A><BR> |
| @@ -321,6 +322,7 @@ Freely available under the terms of the · 14 unmodified lines | |||
| 321 | <P> | 322 | <P> |
| 322 | <A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR> | 323 | <A HREF="manual.html#lua_Alloc">lua_Alloc</A><BR> |
| 323 | <A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR> | 324 | <A HREF="manual.html#lua_CFunction">lua_CFunction</A><BR> |
| 325 | <A HREF="manual.html#lua_Ctx">lua_Ctx</A><BR> | ||
| 324 | <A HREF="manual.html#lua_Debug">lua_Debug</A><BR> | 326 | <A HREF="manual.html#lua_Debug">lua_Debug</A><BR> |
| 325 | <A HREF="manual.html#lua_Hook">lua_Hook</A><BR> | 327 | <A HREF="manual.html#lua_Hook">lua_Hook</A><BR> |
| 326 | <A HREF="manual.html#lua_Integer">lua_Integer</A><BR> | 328 | <A HREF="manual.html#lua_Integer">lua_Integer</A><BR> |
| @@ -347,6 +349,7 @@ Freely available under the terms of the · 20 unmodified lines | |||
| 347 | <A HREF="manual.html#lua_error">lua_error</A><BR> | 349 | <A HREF="manual.html#lua_error">lua_error</A><BR> |
| 348 | <A HREF="manual.html#lua_gc">lua_gc</A><BR> | 350 | <A HREF="manual.html#lua_gc">lua_gc</A><BR> |
| 349 | <A HREF="manual.html#lua_getallocf">lua_getallocf</A><BR> | 351 | <A HREF="manual.html#lua_getallocf">lua_getallocf</A><BR> |
| 352 | <A HREF="manual.html#lua_getextraspace">lua_getextraspace</A><BR> | ||
| 350 | <A HREF="manual.html#lua_getfield">lua_getfield</A><BR> | 353 | <A HREF="manual.html#lua_getfield">lua_getfield</A><BR> |
| 351 | <A HREF="manual.html#lua_getglobal">lua_getglobal</A><BR> | 354 | <A HREF="manual.html#lua_getglobal">lua_getglobal</A><BR> |
| 352 | <A HREF="manual.html#lua_gethook">lua_gethook</A><BR> | 355 | <A HREF="manual.html#lua_gethook">lua_gethook</A><BR> |
| @@ -399,7 +402,6 @@ Freely available under the terms of the · 46 unmodified lines | |||
| 399 | <A HREF="manual.html#lua_pushnumber">lua_pushnumber</A><BR> | 402 | <A HREF="manual.html#lua_pushnumber">lua_pushnumber</A><BR> |
| 400 | <A HREF="manual.html#lua_pushstring">lua_pushstring</A><BR> | 403 | <A HREF="manual.html#lua_pushstring">lua_pushstring</A><BR> |
| 401 | <A HREF="manual.html#lua_pushthread">lua_pushthread</A><BR> | 404 | <A HREF="manual.html#lua_pushthread">lua_pushthread</A><BR> |
| 402 | <A HREF="manual.html#lua_pushunsigned">lua_pushunsigned</A><BR> | ||
| 403 | <A HREF="manual.html#lua_pushvalue">lua_pushvalue</A><BR> | 405 | <A HREF="manual.html#lua_pushvalue">lua_pushvalue</A><BR> |
| 404 | <A HREF="manual.html#lua_pushvfstring">lua_pushvfstring</A><BR> | 406 | <A HREF="manual.html#lua_pushvfstring">lua_pushvfstring</A><BR> |
| 405 | <A HREF="manual.html#lua_rawequal">lua_rawequal</A><BR> | 407 | <A HREF="manual.html#lua_rawequal">lua_rawequal</A><BR> |
| @@ -437,8 +439,6 @@ Freely available under the terms of the · 31 unmodified lines | |||
| 437 | <A HREF="manual.html#lua_topointer">lua_topointer</A><BR> | 439 | <A HREF="manual.html#lua_topointer">lua_topointer</A><BR> |
| 438 | <A HREF="manual.html#lua_tostring">lua_tostring</A><BR> | 440 | <A HREF="manual.html#lua_tostring">lua_tostring</A><BR> |
| 439 | <A HREF="manual.html#lua_tothread">lua_tothread</A><BR> | 441 | <A HREF="manual.html#lua_tothread">lua_tothread</A><BR> |
| 440 | <A HREF="manual.html#lua_tounsigned">lua_tounsigned</A><BR> | ||
| 441 | <A HREF="manual.html#lua_tounsignedx">lua_tounsignedx</A><BR> | ||
| 442 | <A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR> | 442 | <A HREF="manual.html#lua_touserdata">lua_touserdata</A><BR> |
| 443 | <A HREF="manual.html#lua_type">lua_type</A><BR> | 443 | <A HREF="manual.html#lua_type">lua_type</A><BR> |
| 444 | <A HREF="manual.html#lua_typename">lua_typename</A><BR> | 444 | <A HREF="manual.html#lua_typename">lua_typename</A><BR> |
| @@ -480,7 +480,6 @@ Freely available under the terms of the · 35 unmodified lines | |||
| 480 | <A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR> | 480 | <A HREF="manual.html#luaL_checkstring">luaL_checkstring</A><BR> |
| 481 | <A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR> | 481 | <A HREF="manual.html#luaL_checktype">luaL_checktype</A><BR> |
| 482 | <A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR> | 482 | <A HREF="manual.html#luaL_checkudata">luaL_checkudata</A><BR> |
| 483 | <A HREF="manual.html#luaL_checkunsigned">luaL_checkunsigned</A><BR> | ||
| 484 | <A HREF="manual.html#luaL_checkversion">luaL_checkversion</A><BR> | 483 | <A HREF="manual.html#luaL_checkversion">luaL_checkversion</A><BR> |
| 485 | <A HREF="manual.html#luaL_dofile">luaL_dofile</A><BR> | 484 | <A HREF="manual.html#luaL_dofile">luaL_dofile</A><BR> |
| 486 | <A HREF="manual.html#luaL_dostring">luaL_dostring</A><BR> | 485 | <A HREF="manual.html#luaL_dostring">luaL_dostring</A><BR> |
| @@ -508,7 +507,6 @@ Freely available under the terms of the · 21 unmodified lines | |||
| 508 | <A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR> | 507 | <A HREF="manual.html#luaL_optlstring">luaL_optlstring</A><BR> |
| 509 | <A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR> | 508 | <A HREF="manual.html#luaL_optnumber">luaL_optnumber</A><BR> |
| 510 | <A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR> | 509 | <A HREF="manual.html#luaL_optstring">luaL_optstring</A><BR> |
| 511 | <A HREF="manual.html#luaL_optunsigned">luaL_optunsigned</A><BR> | ||
| 512 | <A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR> | 510 | <A HREF="manual.html#luaL_prepbuffer">luaL_prepbuffer</A><BR> |
| 513 | <A HREF="manual.html#luaL_prepbuffsize">luaL_prepbuffsize</A><BR> | 511 | <A HREF="manual.html#luaL_prepbuffsize">luaL_prepbuffsize</A><BR> |
| 514 | <A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR> | 512 | <A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR> |
| @@ -531,10 +529,10 @@ Freely available under the terms of the · 16 unmodified lines | |||
| 531 | <HR> | 529 | <HR> |
| 532 | <SMALL CLASS="footer"> | 530 | <SMALL CLASS="footer"> |
| 533 | Last update: | 531 | Last update: |
| 534 | Thu Jun 19 17:09:46 BRT 2014 | 532 | Thu Jul 31 14:04:18 BRT 2014 |
| 535 | </SMALL> | 533 | </SMALL> |
| 536 | <!-- | 534 | <!-- |
| 537 | Last change: updated for Lua 5.3.0 (work3) | 535 | Last change: updated for Lua 5.3.0 (alpha) |
| 538 | --> | 536 | --> |
| 539 | 537 | ||
| 540 | </BODY> | 538 | </BODY> |
| @@ -59,6 +59,10 @@ a:link:active, a:visited:active { · 58 unmodified lines | |||
| 59 | color: #FF0000 ; | 59 | color: #FF0000 ; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | h1 a img { | ||
| 63 | vertical-align: text-bottom ; | ||
| 64 | } | ||
| 65 | |||
| 62 | hr { | 66 | hr { |
| 63 | border: 0 ; | 67 | border: 0 ; |
| 64 | height: 1px ; | 68 | height: 1px ; |
| @@ -88,9 +92,8 @@ input[type=text] { · 23 unmodified lines | |||
| 88 | border-radius: 2em ; | 92 | border-radius: 2em ; |
| 89 | -moz-border-radius: 2em ; | 93 | -moz-border-radius: 2em ; |
| 90 | background-image: url('images/search.png') ; | 94 | background-image: url('images/search.png') ; |
| 91 | background-repeat: no-repeat; | 95 | background-repeat: no-repeat ; |
| 92 | background-position: 4px center ; | 96 | background-position: 4px center ; |
| 93 | padding-left: 20px ; | 97 | padding-left: 20px ; |
| 94 | height: 2em ; | 98 | height: 2em ; |
| 95 | } | 99 | } |
| 96 | |||
| @@ -18,13 +18,13 @@ Lua 5.3 Reference Manual · 17 unmodified lines | |||
| 18 | 18 | ||
| 19 | <P> | 19 | <P> |
| 20 | <IMG SRC="alert.png" ALIGN="absbottom"> | 20 | <IMG SRC="alert.png" ALIGN="absbottom"> |
| 21 | <EM>All details may change in the final version.</EM> | 21 | <EM>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 |
| 25 | <p> | 25 | <p> |
| 26 | <small> | 26 | <small> |
| 27 | Copyright © 2011–2014 Lua.org, PUC-Rio. | 27 | Copyright © 2014 Lua.org, PUC-Rio. |
| 28 | Freely available under the terms of the | 28 | Freely available under the terms of the |
| 29 | <a href="http://www.lua.org/license.html">Lua license</a>. | 29 | <a href="http://www.lua.org/license.html">Lua license</a>. |
| 30 | </small> | 30 | </small> |
| @@ -38,7 +38,7 @@ Freely available under the terms of the · 7 unmodified lines | |||
| 38 | <!-- ====================================================================== --> | 38 | <!-- ====================================================================== --> |
| 39 | <p> | 39 | <p> |
| 40 | 40 | ||
| 41 | <!-- $Id: manual.of,v 1.121 2014/06/18 19:12:23 roberto Exp $ --> | 41 | <!-- $Id: manual.of,v 1.125 2014/07/31 13:58:08 roberto Exp $ --> |
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | 44 | ||
| @@ -125,7 +125,7 @@ it usually represents the absence of a useful value. · 80 unmodified lines | |||
| 125 | Both <b>nil</b> and <b>false</b> make a condition false; | 125 | Both <b>nil</b> and <b>false</b> make a condition false; |
| 126 | any other value makes it true. | 126 | any other value makes it true. |
| 127 | <em>Number</em> represents both | 127 | <em>Number</em> represents both |
| 128 | integral numbers and real (floating-point) numbers. | 128 | integer numbers and real (floating-point) numbers. |
| 129 | <em>String</em> represents immutable sequences of bytes. | 129 | <em>String</em> represents immutable sequences of bytes. |
| 130 | 130 | ||
| 131 | Lua is 8-bit clean: | 131 | Lua is 8-bit clean: |
| @@ -146,7 +146,7 @@ Standard Lua uses 64-bit integers and double-precision (64-bit) floats, · 14 unmodified lines | |||
| 146 | but you can also compile Lua so that it | 146 | but you can also compile Lua so that it |
| 147 | uses 32-bit integers and/or single-precision (32-bit) floats. | 147 | uses 32-bit integers and/or single-precision (32-bit) floats. |
| 148 | The option with 32 bits both for integers and floats | 148 | The option with 32 bits both for integers and floats |
| 149 | (what is called <em>Small Lua</em>) is particularly attractive | 149 | (called <em>Small Lua</em>) is particularly attractive |
| 150 | for small machines. | 150 | for small machines. |
| 151 | 151 | ||
| 152 | 152 | ||
| @@ -159,7 +159,7 @@ functions written in C · 6 unmodified lines | |||
| 159 | <p> | 159 | <p> |
| 160 | The type <em>userdata</em> is provided to allow arbitrary C data to | 160 | The type <em>userdata</em> is provided to allow arbitrary C data to |
| 161 | be stored in Lua variables. | 161 | be stored in Lua variables. |
| 162 | A userdata value is a pointer to a block of raw memory. | 162 | A userdata value represents a block of raw memory. |
| 163 | There are two kinds of userdata: | 163 | There are two kinds of userdata: |
| 164 | full userdata, where the block of memory is managed by Lua, | 164 | full userdata, where the block of memory is managed by Lua, |
| 165 | and light userdata, where the block of memory is managed by the host. | 165 | and light userdata, where the block of memory is managed by the host. |
| @@ -178,7 +178,7 @@ The type <em>thread</em> represents independent threads of execution · 12 unmodified lines | |||
| 178 | and it is used to implement coroutines (see <a href="#2.6">§2.6</a>). | 178 | and it is used to implement coroutines (see <a href="#2.6">§2.6</a>). |
| 179 | Do not confuse Lua threads with operating-system threads. | 179 | Do not confuse Lua threads with operating-system threads. |
| 180 | Lua supports coroutines on all systems, | 180 | Lua supports coroutines on all systems, |
| 181 | even those that do not support threads. | 181 | even those that do not support threads natively. |
| 182 | 182 | ||
| 183 | 183 | ||
| 184 | <p> | 184 | <p> |
| @@ -324,7 +324,9 @@ is never updated by Lua. · 139 unmodified lines | |||
| 324 | <p> | 324 | <p> |
| 325 | Because Lua is an embedded extension language, | 325 | Because Lua is an embedded extension language, |
| 326 | all Lua actions start from C code in the host program | 326 | all Lua actions start from C code in the host program |
| 327 | calling a function from the Lua library (see <a href="#lua_pcall"><code>lua_pcall</code></a>). | 327 | calling a function from the Lua library. |
| 328 | (when you use Lua standalone, | ||
| 329 | the <code>lua</code> application is the host program.) | ||
| 328 | Whenever an error occurs during | 330 | Whenever an error occurs during |
| 329 | the compilation or execution of a Lua chunk, | 331 | the compilation or execution of a Lua chunk, |
| 330 | control returns to the host, | 332 | control returns to the host, |
| @@ -1891,9 +1893,9 @@ that rounds the quotient towards minus infinite (floor). · 1560 unmodified lines | |||
| 1891 | In case of overflows in integer arithmetic, | 1893 | In case of overflows in integer arithmetic, |
| 1892 | all operations <em>wrap around</em>, | 1894 | all operations <em>wrap around</em>, |
| 1893 | according to the usual rules of two-complement arithmetic. | 1895 | according to the usual rules of two-complement arithmetic. |
| 1894 | (In other words, they return the correct result modulo <em>2<sup>64</sup></em>.) | 1896 | (In other words, |
| 1895 | 1897 | they return the unique representable integer | |
| 1896 | 1898 | that is equal modulo <em>2<sup>64</sup></em> to the mathematical result.) | |
| 1897 | 1899 | ||
| 1898 | 1900 | ||
| 1899 | 1901 | ||
| @@ -1921,7 +1923,7 @@ Both right and left shifts fill the vacant bits with zeros. · 21 unmodified lines | |||
| 1921 | Negative displacements shift to the other direction; | 1923 | Negative displacements shift to the other direction; |
| 1922 | displacements with absolute values equal to or higher than | 1924 | displacements with absolute values equal to or higher than |
| 1923 | the number of bits in an integer | 1925 | the number of bits in an integer |
| 1924 | result in zero (all bits are shifted out). | 1926 | result in zero (as all bits are shifted out). |
| 1925 | 1927 | ||
| 1926 | 1928 | ||
| 1927 | 1929 | ||
| @@ -1952,16 +1954,17 @@ In a conversion from integer to float, · 24 unmodified lines | |||
| 1952 | if the integer value has an exact representation as a float, | 1954 | if the integer value has an exact representation as a float, |
| 1953 | that is the result. | 1955 | that is the result. |
| 1954 | Otherwise, | 1956 | Otherwise, |
| 1955 | the conversion gets the nearest higher or lower representable value. | 1957 | the conversion gets the nearest higher or |
| 1958 | the nearest lower representable value. | ||
| 1956 | This kind of conversion never fails. | 1959 | This kind of conversion never fails. |
| 1957 | 1960 | ||
| 1958 | 1961 | ||
| 1959 | <p> | 1962 | <p> |
| 1960 | The conversion from float to integer | 1963 | The conversion from float to integer |
| 1961 | first takes the floor of the float number. | 1964 | checks whether the float has an exact representation as an integer |
| 1962 | If that value can be represented as an integer | 1965 | (that is, the float has an integral value and |
| 1963 | (that is, it is in the range of integer representation), | 1966 | it is in the range of integer representation). |
| 1964 | that is the result. | 1967 | If it does, that representation is the result. |
| 1965 | Otherwise, the conversion fails. | 1968 | Otherwise, the conversion fails. |
| 1966 | 1969 | ||
| 1967 | 1970 | ||
| @@ -2005,7 +2008,7 @@ Otherwise, the values of the operands are compared. · 37 unmodified lines | |||
| 2005 | Strings are compared in the obvious way. | 2008 | Strings are compared in the obvious way. |
| 2006 | Numbers follow the usual rule for binary operations: | 2009 | Numbers follow the usual rule for binary operations: |
| 2007 | if both operands are integers, | 2010 | if both operands are integers, |
| 2008 | the are compared as integers; | 2011 | they are compared as integers; |
| 2009 | otherwise, they are converted to floats | 2012 | otherwise, they are converted to floats |
| 2010 | and compared as such. | 2013 | and compared as such. |
| 2011 | 2014 | ||
| @@ -2028,7 +2031,7 @@ by using the "eq" metamethod (see <a href="#2.4">§2.4</a>). · 16 unmodified lines | |||
| 2028 | 2031 | ||
| 2029 | 2032 | ||
| 2030 | <p> | 2033 | <p> |
| 2031 | Equality comparisons never convert strings to numbers | 2034 | Equality comparisons do not convert strings to numbers |
| 2032 | or vice versa. | 2035 | or vice versa. |
| 2033 | Thus, <code>"0"==0</code> evaluates to <b>false</b>, | 2036 | Thus, <code>"0"==0</code> evaluates to <b>false</b>, |
| 2034 | and <code>t[0]</code> and <code>t["0"]</code> denote different | 2037 | and <code>t[0]</code> and <code>t["0"]</code> denote different |
| @@ -2190,7 +2193,7 @@ with key <code>exp1</code> and value <code>exp2</code>. · 155 unmodified lines | |||
| 2190 | A field of the form <code>name = exp</code> is equivalent to | 2193 | A field of the form <code>name = exp</code> is equivalent to |
| 2191 | <code>["name"] = exp</code>. | 2194 | <code>["name"] = exp</code>. |
| 2192 | Finally, fields of the form <code>exp</code> are equivalent to | 2195 | Finally, fields of the form <code>exp</code> are equivalent to |
| 2193 | <code>[i] = exp</code>, where <code>i</code> are consecutive numerical integers, | 2196 | <code>[i] = exp</code>, where <code>i</code> are consecutive integers |
| 2194 | starting with 1. | 2197 | starting with 1. |
| 2195 | Fields in the other formats do not affect this counting. | 2198 | Fields in the other formats do not affect this counting. |
| 2196 | For example, | 2199 | For example, |
| @@ -2861,7 +2864,7 @@ the Lua code being ran by <a href="#lua_pcall"><code>lua_pcall</code></a> to yie · 664 unmodified lines | |||
| 2861 | First, we can rewrite our function like here: | 2864 | First, we can rewrite our function like here: |
| 2862 | 2865 | ||
| 2863 | <pre> | 2866 | <pre> |
| 2864 | int k (lua_State *L, int status, int ctx) { | 2867 | int k (lua_State *L, int status, lua_Ctx ctx) { |
| 2865 | ... /* code 2 */ | 2868 | ... /* code 2 */ |
| 2866 | } | 2869 | } |
| 2867 | 2870 | ||
| @@ -2905,6 +2908,12 @@ the status is always <a href="#pdf-LUA_YIELD"><code>LUA_YIELD</code></a> when Lu · 37 unmodified lines | |||
| 2905 | (For these two functions, | 2908 | (For these two functions, |
| 2906 | Lua will not call the continuation in case of errors, | 2909 | Lua will not call the continuation in case of errors, |
| 2907 | because they do not handle errors.) | 2910 | because they do not handle errors.) |
| 2911 | Similarly, when using <a href="#lua_callk"><code>lua_callk</code></a>, | ||
| 2912 | you should call the continuation function | ||
| 2913 | with <a href="#pdf-LUA_OK"><code>LUA_OK</code></a> as the status. | ||
| 2914 | (For <a href="#lua_yieldk"><code>lua_yieldk</code></a>, there is not much point in calling | ||
| 2915 | directly the continuation function, | ||
| 2916 | because <a href="#lua_yieldk"><code>lua_yieldk</code></a> usually does not return.) | ||
| 2908 | 2917 | ||
| 2909 | 2918 | ||
| 2910 | <p> | 2919 | <p> |
| @@ -3159,7 +3168,7 @@ This is considered good programming practice. · 248 unmodified lines | |||
| 3159 | 3168 | ||
| 3160 | <hr><h3><a name="lua_callk"><code>lua_callk</code></a></h3><p> | 3169 | <hr><h3><a name="lua_callk"><code>lua_callk</code></a></h3><p> |
| 3161 | <span class="apii">[-(nargs + 1), +nresults, <em>e</em>]</span> | 3170 | <span class="apii">[-(nargs + 1), +nresults, <em>e</em>]</span> |
| 3162 | <pre>void lua_callk (lua_State *L, int nargs, int nresults, int ctx, | 3171 | <pre>void lua_callk (lua_State *L, int nargs, int nresults, lua_Ctx ctx, |
| 3163 | lua_KFunction k);</pre> | 3172 | lua_KFunction k);</pre> |
| 3164 | 3173 | ||
| 3165 | <p> | 3174 | <p> |
| @@ -3307,7 +3316,7 @@ Concatenation is performed following the usual semantics of Lua · 141 unmodified lines | |||
| 3307 | <pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre> | 3316 | <pre>void lua_copy (lua_State *L, int fromidx, int toidx);</pre> |
| 3308 | 3317 | ||
| 3309 | <p> | 3318 | <p> |
| 3310 | Moves the element at index <code>fromidx</code> | 3319 | Copies the element at index <code>fromidx</code> |
| 3311 | into the valid index <code>toidx</code> | 3320 | into the valid index <code>toidx</code> |
| 3312 | without shifting any element | 3321 | without shifting any element |
| 3313 | (therefore replacing the value at that position). | 3322 | (therefore replacing the value at that position). |
| @@ -3335,6 +3344,21 @@ Otherwise you can use the function <a href="#lua_newtable"><code>lua_newtable</c · 21 unmodified lines | |||
| 3335 | 3344 | ||
| 3336 | 3345 | ||
| 3337 | 3346 | ||
| 3347 | <hr><h3><a name="lua_Ctx"><code>lua_Ctx</code></a></h3> | ||
| 3348 | <pre>typedef ... lua_Ctx;</pre> | ||
| 3349 | |||
| 3350 | <p> | ||
| 3351 | The type for continuation-function contexts. | ||
| 3352 | It must be a numerical type. | ||
| 3353 | This type is defined as <code>intptr_t</code> | ||
| 3354 | when <code>intptr_t</code> is available, | ||
| 3355 | so that it can store pointers too. | ||
| 3356 | Otherwise, it is defined as <code>ptrdiff_t</code>. | ||
| 3357 | |||
| 3358 | |||
| 3359 | |||
| 3360 | |||
| 3361 | |||
| 3338 | <hr><h3><a name="lua_dump"><code>lua_dump</code></a></h3><p> | 3362 | <hr><h3><a name="lua_dump"><code>lua_dump</code></a></h3><p> |
| 3339 | <span class="apii">[-0, +0, <em>e</em>]</span> | 3363 | <span class="apii">[-0, +0, <em>e</em>]</span> |
| 3340 | <pre>int lua_dump (lua_State *L, | 3364 | <pre>int lua_dump (lua_State *L, |
| @@ -3485,6 +3509,31 @@ Returns the type of the pushed value. · 144 unmodified lines | |||
| 3485 | 3509 | ||
| 3486 | 3510 | ||
| 3487 | 3511 | ||
| 3512 | <hr><h3><a name="lua_getextraspace"><code>lua_getextraspace</code></a></h3><p> | ||
| 3513 | <span class="apii">[-0, +0, –]</span> | ||
| 3514 | <pre>void *lua_getextraspace (lua_State *L);</pre> | ||
| 3515 | |||
| 3516 | <p> | ||
| 3517 | Returns a pointer to a raw memory area associated with the | ||
| 3518 | given Lua state. | ||
| 3519 | The application can use this area for any purpose; | ||
| 3520 | Lua does not use it for anything. | ||
| 3521 | |||
| 3522 | |||
| 3523 | <p> | ||
| 3524 | Each new thread has this area initialized with a copy | ||
| 3525 | of the area of the main thread. | ||
| 3526 | |||
| 3527 | |||
| 3528 | <p> | ||
| 3529 | By default, this area has the size of a pointer to void, | ||
| 3530 | but you can recompile Lua with a different size for this area. | ||
| 3531 | (See <code>LUA_EXTRASPACE</code> in <code>luaconf.h</code>.) | ||
| 3532 | |||
| 3533 | |||
| 3534 | |||
| 3535 | |||
| 3536 | |||
| 3488 | <hr><h3><a name="lua_getglobal"><code>lua_getglobal</code></a></h3><p> | 3537 | <hr><h3><a name="lua_getglobal"><code>lua_getglobal</code></a></h3><p> |
| 3489 | <span class="apii">[-0, +1, <em>e</em>]</span> | 3538 | <span class="apii">[-0, +1, <em>e</em>]</span> |
| 3490 | <pre>int lua_getglobal (lua_State *L, const char *name);</pre> | 3539 | <pre>int lua_getglobal (lua_State *L, const char *name);</pre> |
| @@ -3502,8 +3551,9 @@ Returns the type of that value. · 11 unmodified lines | |||
| 3502 | <pre>int lua_getmetatable (lua_State *L, int index);</pre> | 3551 | <pre>int lua_getmetatable (lua_State *L, int index);</pre> |
| 3503 | 3552 | ||
| 3504 | <p> | 3553 | <p> |
| 3505 | Pushes onto the stack the metatable of the value at the given index. | 3554 | If the value at the given index has a metatable, |
| 3506 | If the value does not have a metatable, | 3555 | the function pushes that metatable onto the stack and returns 1. |
| 3556 | Otherwise, | ||
| 3507 | the function returns 0 and pushes nothing on the stack. | 3557 | the function returns 0 and pushes nothing on the stack. |
| 3508 | 3558 | ||
| 3509 | 3559 | ||
| @@ -3588,9 +3638,9 @@ The type of integers in Lua. · 78 unmodified lines | |||
| 3588 | <p> | 3638 | <p> |
| 3589 | By default this type is <code>long long</code> | 3639 | By default this type is <code>long long</code> |
| 3590 | (usually a 64-bit two-complement integer), | 3640 | (usually a 64-bit two-complement integer), |
| 3591 | but that can be changed in <code>luaconf.h</code> | 3641 | but that can be changed to <code>long</code> or <code>int</code>, |
| 3592 | to <code>long</code> or <code>int</code> | 3642 | usually a 32-bit two-complement integer. |
| 3593 | (usually a 32-bit two-complement integer). | 3643 | (See <code>LUA_INT</code> in <code>luaconf.h</code>.) |
| 3594 | 3644 | ||
| 3595 | 3645 | ||
| 3596 | <p> | 3646 | <p> |
| @@ -3775,7 +3825,7 @@ and 0 otherwise. · 178 unmodified lines | |||
| 3775 | 3825 | ||
| 3776 | 3826 | ||
| 3777 | <hr><h3><a name="lua_KFunction"><code>lua_KFunction</code></a></h3> | 3827 | <hr><h3><a name="lua_KFunction"><code>lua_KFunction</code></a></h3> |
| 3778 | <pre>typedef int (*lua_KFunction) (lua_State *L, int status, int ctx);</pre> | 3828 | <pre>typedef int (*lua_KFunction) (lua_State *L, int status, lua_Ctx ctx);</pre> |
| 3779 | 3829 | ||
| 3780 | <p> | 3830 | <p> |
| 3781 | Type for continuation functions (see <a href="#4.7">§4.7</a>). | 3831 | Type for continuation functions (see <a href="#4.7">§4.7</a>). |
| @@ -3988,7 +4038,8 @@ The type of floats in Lua. · 206 unmodified lines | |||
| 3988 | 4038 | ||
| 3989 | <p> | 4039 | <p> |
| 3990 | By default this type is double, | 4040 | By default this type is double, |
| 3991 | but that can be changed in <code>luaconf.h</code> to a single float. | 4041 | but that can be changed to a single float. |
| 4042 | (See <code>LUA_REAL</code> in <code>luaconf.h</code>.) | ||
| 3992 | 4043 | ||
| 3993 | 4044 | ||
| 3994 | 4045 | ||
| @@ -4096,7 +4147,7 @@ error while running a <code>__gc</code> metamethod. · 101 unmodified lines | |||
| 4096 | int nargs, | 4147 | int nargs, |
| 4097 | int nresults, | 4148 | int nresults, |
| 4098 | int errfunc, | 4149 | int errfunc, |
| 4099 | int ctx, | 4150 | lua_Ctx ctx, |
| 4100 | lua_KFunction k);</pre> | 4151 | lua_KFunction k);</pre> |
| 4101 | 4152 | ||
| 4102 | <p> | 4153 | <p> |
| @@ -4366,17 +4417,6 @@ Returns 1 if this thread is the main thread of its state. · 263 unmodified lines | |||
| 4366 | 4417 | ||
| 4367 | 4418 | ||
| 4368 | 4419 | ||
| 4369 | <hr><h3><a name="lua_pushunsigned"><code>lua_pushunsigned</code></a></h3><p> | ||
| 4370 | <span class="apii">[-0, +1, –]</span> | ||
| 4371 | <pre>void lua_pushunsigned (lua_State *L, lua_Unsigned n);</pre> | ||
| 4372 | |||
| 4373 | <p> | ||
| 4374 | Pushes an integer with value <code>n</code> onto the stack. | ||
| 4375 | |||
| 4376 | |||
| 4377 | |||
| 4378 | |||
| 4379 | |||
| 4380 | <hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3><p> | 4420 | <hr><h3><a name="lua_pushvalue"><code>lua_pushvalue</code></a></h3><p> |
| 4381 | <span class="apii">[-0, +1, –]</span> | 4421 | <span class="apii">[-0, +1, –]</span> |
| 4382 | <pre>void lua_pushvalue (lua_State *L, int index);</pre> | 4422 | <pre>void lua_pushvalue (lua_State *L, int index);</pre> |
| @@ -4916,9 +4956,12 @@ to a string inside the Lua state. · 533 unmodified lines | |||
| 4916 | This string always has a zero ('<code>\0</code>') | 4956 | This string always has a zero ('<code>\0</code>') |
| 4917 | after its last character (as in C), | 4957 | after its last character (as in C), |
| 4918 | but can contain other zeros in its body. | 4958 | but can contain other zeros in its body. |
| 4959 | |||
| 4960 | |||
| 4961 | <p> | ||
| 4919 | Because Lua has garbage collection, | 4962 | Because Lua has garbage collection, |
| 4920 | there is no guarantee that the pointer returned by <code>lua_tolstring</code> | 4963 | there is no guarantee that the pointer returned by <code>lua_tolstring</code> |
| 4921 | will be valid after the corresponding value is removed from the stack. | 4964 | will be valid after the corresponding Lua value is removed from the stack. |
| 4922 | 4965 | ||
| 4923 | 4966 | ||
| 4924 | 4967 | ||
| @@ -5001,48 +5044,6 @@ otherwise, the function returns <code>NULL</code>. · 76 unmodified lines | |||
| 5001 | 5044 | ||
| 5002 | 5045 | ||
| 5003 | 5046 | ||
| 5004 | <hr><h3><a name="lua_tounsigned"><code>lua_tounsigned</code></a></h3><p> | ||
| 5005 | <span class="apii">[-0, +0, –]</span> | ||
| 5006 | <pre>lua_Unsigned lua_tounsigned (lua_State *L, int index);</pre> | ||
| 5007 | |||
| 5008 | <p> | ||
| 5009 | Equivalent to <a href="#lua_tounsignedx"><code>lua_tounsignedx</code></a> with <code>isnum</code> equal to <code>NULL</code>. | ||
| 5010 | |||
| 5011 | |||
| 5012 | |||
| 5013 | |||
| 5014 | |||
| 5015 | <hr><h3><a name="lua_tounsignedx"><code>lua_tounsignedx</code></a></h3><p> | ||
| 5016 | <span class="apii">[-0, +0, –]</span> | ||
| 5017 | <pre>lua_Unsigned lua_tounsignedx (lua_State *L, int index, int *isnum);</pre> | ||
| 5018 | |||
| 5019 | <p> | ||
| 5020 | Converts the Lua value at the given index | ||
| 5021 | to the unsigned integral type <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>. | ||
| 5022 | The Lua value must be an integer, | ||
| 5023 | or a float, | ||
| 5024 | or a string convertible to a number | ||
| 5025 | (see <a href="#3.4.3">§3.4.3</a>); | ||
| 5026 | otherwise, <code>lua_tounsignedx</code> returns 0. | ||
| 5027 | |||
| 5028 | |||
| 5029 | <p> | ||
| 5030 | If the number is not an integer, | ||
| 5031 | it is rounded towards minus infinite (floor). | ||
| 5032 | If the result is outside the range of representable values, | ||
| 5033 | it is normalized to the module of its division by | ||
| 5034 | one more than the maximum representable value. | ||
| 5035 | |||
| 5036 | |||
| 5037 | <p> | ||
| 5038 | If <code>isnum</code> is not <code>NULL</code>, | ||
| 5039 | its referent is assigned a boolean value that | ||
| 5040 | indicates whether the operation succeeded. | ||
| 5041 | |||
| 5042 | |||
| 5043 | |||
| 5044 | |||
| 5045 | |||
| 5046 | <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p> | 5047 | <hr><h3><a name="lua_touserdata"><code>lua_touserdata</code></a></h3><p> |
| 5047 | <span class="apii">[-0, +0, –]</span> | 5048 | <span class="apii">[-0, +0, –]</span> |
| 5048 | <pre>void *lua_touserdata (lua_State *L, int index);</pre> | 5049 | <pre>void *lua_touserdata (lua_State *L, int index);</pre> |
| @@ -5101,11 +5102,6 @@ which must be one the values returned by <a href="#lua_type"><code>lua_type</cod · 52 unmodified lines | |||
| 5101 | The unsigned version of <a href="#lua_Integer"><code>lua_Integer</code></a>. | 5102 | The unsigned version of <a href="#lua_Integer"><code>lua_Integer</code></a>. |
| 5102 | 5103 | ||
| 5103 | 5104 | ||
| 5104 | <p> | ||
| 5105 | Lua also defines the constant <a name="pdf-LUA_MAXUNSIGNED"><code>LUA_MAXUNSIGNED</code></a>, | ||
| 5106 | with the maximum value that fits in this type. | ||
| 5107 | |||
| 5108 | |||
| 5109 | 5105 | ||
| 5110 | 5106 | ||
| 5111 | 5107 | ||
| @@ -5178,14 +5174,14 @@ and pushes them onto the stack <code>to</code>. · 66 unmodified lines | |||
| 5178 | 5174 | ||
| 5179 | 5175 | ||
| 5180 | <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p> | 5176 | <hr><h3><a name="lua_yield"><code>lua_yield</code></a></h3><p> |
| 5181 | <span class="apii">[-?, +?, –]</span> | 5177 | <span class="apii">[-?, +?, <em>e</em>]</span> |
| 5182 | <pre>int lua_yield (lua_State *L, int nresults);</pre> | 5178 | <pre>int lua_yield (lua_State *L, int nresults);</pre> |
| 5183 | 5179 | ||
| 5184 | <p> | 5180 | <p> |
| 5185 | This function is equivalent to <a href="#lua_yieldk"><code>lua_yieldk</code></a>, | 5181 | This function is equivalent to <a href="#lua_yieldk"><code>lua_yieldk</code></a>, |
| 5186 | but it has no continuation (see <a href="#4.7">§4.7</a>). | 5182 | but it has no continuation (see <a href="#4.7">§4.7</a>). |
| 5187 | Therefore, when the thread resumes, | 5183 | Therefore, when the thread resumes, |
| 5188 | it returns to the function that called | 5184 | it continues the function that called |
| 5189 | the function calling <code>lua_yield</code>. | 5185 | the function calling <code>lua_yield</code>. |
| 5190 | 5186 | ||
| 5191 | 5187 | ||
| @@ -5193,21 +5189,15 @@ the function calling <code>lua_yield</code>. · 1 unmodified line | |||
| 5193 | 5189 | ||
| 5194 | 5190 | ||
| 5195 | <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p> | 5191 | <hr><h3><a name="lua_yieldk"><code>lua_yieldk</code></a></h3><p> |
| 5196 | <span class="apii">[-?, +?, –]</span> | 5192 | <span class="apii">[-?, +?, <em>e</em>]</span> |
| 5197 | <pre>int lua_yieldk (lua_State *L, int nresults, int ctx, lua_KFunction k);</pre> | 5193 | <pre>int lua_yieldk (lua_State *L, int nresults, lua_Ctx ctx, lua_KFunction k);</pre> |
| 5198 | 5194 | ||
| 5199 | <p> | 5195 | <p> |
| 5200 | Yields a coroutine. | 5196 | Yields a coroutine (thread). |
| 5201 | 5197 | ||
| 5202 | 5198 | ||
| 5203 | <p> | 5199 | <p> |
| 5204 | This function should only be called as the | 5200 | When a C function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a>, |
| 5205 | return expression of a C function, as follows: | ||
| 5206 | |||
| 5207 | <pre> | ||
| 5208 | return lua_yieldk (L, n, ctx, k); | ||
| 5209 | </pre><p> | ||
| 5210 | When a C function calls <a href="#lua_yieldk"><code>lua_yieldk</code></a> in that way, | ||
| 5211 | the running coroutine suspends its execution, | 5201 | the running coroutine suspends its execution, |
| 5212 | and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine returns. | 5202 | and the call to <a href="#lua_resume"><code>lua_resume</code></a> that started this coroutine returns. |
| 5213 | The parameter <code>nresults</code> is the number of values from the stack | 5203 | The parameter <code>nresults</code> is the number of values from the stack |
| @@ -5227,6 +5217,29 @@ the continuation function receives the value <code>ctx</code> · 13 unmodified lines | |||
| 5227 | that was passed to <a href="#lua_yieldk"><code>lua_yieldk</code></a>. | 5217 | that was passed to <a href="#lua_yieldk"><code>lua_yieldk</code></a>. |
| 5228 | 5218 | ||
| 5229 | 5219 | ||
| 5220 | <p> | ||
| 5221 | Usually, this function does not return; | ||
| 5222 | when the coroutine eventually resumes, | ||
| 5223 | it continues executing the continuation function. | ||
| 5224 | However, there is one special case, | ||
| 5225 | which is when this function is called | ||
| 5226 | from inside a line hook (see <a href="#4.9">§4.9</a>). | ||
| 5227 | In that case, <code>lua_yieldk</code> should be called with no continuation | ||
| 5228 | (probably in the form of <a href="#lua_yield"><code>lua_yield</code></a>), | ||
| 5229 | and the hook should return immediately after the call. | ||
| 5230 | Lua will yield and, | ||
| 5231 | when the coroutine resumes again, | ||
| 5232 | it will continue the normal execution | ||
| 5233 | of the (Lua) function that triggered the hook. | ||
| 5234 | |||
| 5235 | |||
| 5236 | <p> | ||
| 5237 | This function can raise an error if it is called from a thread | ||
| 5238 | with a pending C call with no continuation function, | ||
| 5239 | or it is called from a thread that is not running inside a resume | ||
| 5240 | (e.g., the main thread). | ||
| 5241 | |||
| 5242 | |||
| 5230 | 5243 | ||
| 5231 | 5244 | ||
| 5232 | 5245 | ||
| @@ -6196,18 +6209,6 @@ returns the userdata address (see <a href="#lua_touserdata"><code>lua_touserdata · 963 unmodified lines | |||
| 6196 | 6209 | ||
| 6197 | 6210 | ||
| 6198 | 6211 | ||
| 6199 | <hr><h3><a name="luaL_checkunsigned"><code>luaL_checkunsigned</code></a></h3><p> | ||
| 6200 | <span class="apii">[-0, +0, <em>v</em>]</span> | ||
| 6201 | <pre>lua_Unsigned luaL_checkunsigned (lua_State *L, int arg);</pre> | ||
| 6202 | |||
| 6203 | <p> | ||
| 6204 | Checks whether the function argument <code>arg</code> is a number | ||
| 6205 | and returns this number converted to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>. | ||
| 6206 | |||
| 6207 | |||
| 6208 | |||
| 6209 | |||
| 6210 | |||
| 6211 | <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p> | 6212 | <hr><h3><a name="luaL_checkversion"><code>luaL_checkversion</code></a></h3><p> |
| 6212 | <span class="apii">[-0, +0, –]</span> | 6213 | <span class="apii">[-0, +0, –]</span> |
| 6213 | <pre>void luaL_checkversion (lua_State *L);</pre> | 6214 | <pre>void luaL_checkversion (lua_State *L);</pre> |
| @@ -6682,23 +6683,6 @@ Otherwise, raises an error. · 468 unmodified lines | |||
| 6682 | 6683 | ||
| 6683 | 6684 | ||
| 6684 | 6685 | ||
| 6685 | <hr><h3><a name="luaL_optunsigned"><code>luaL_optunsigned</code></a></h3><p> | ||
| 6686 | <span class="apii">[-0, +0, <em>v</em>]</span> | ||
| 6687 | <pre>lua_Unsigned luaL_optunsigned (lua_State *L, | ||
| 6688 | int arg, | ||
| 6689 | lua_Unsigned u);</pre> | ||
| 6690 | |||
| 6691 | <p> | ||
| 6692 | If the function argument <code>arg</code> is a number, | ||
| 6693 | returns this number converted to a <a href="#lua_Unsigned"><code>lua_Unsigned</code></a>. | ||
| 6694 | If this argument is absent or is <b>nil</b>, | ||
| 6695 | returns <code>u</code>. | ||
| 6696 | Otherwise, raises an error. | ||
| 6697 | |||
| 6698 | |||
| 6699 | |||
| 6700 | |||
| 6701 | |||
| 6702 | <hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p> | 6686 | <hr><h3><a name="luaL_prepbuffer"><code>luaL_prepbuffer</code></a></h3><p> |
| 6703 | <span class="apii">[-?, +?, <em>e</em>]</span> | 6687 | <span class="apii">[-?, +?, <em>e</em>]</span> |
| 6704 | <pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre> | 6688 | <pre>char *luaL_prepbuffer (luaL_Buffer *B);</pre> |
| @@ -6803,18 +6787,19 @@ in which both <code>name</code> and <code>func</code> are <code>NULL</code>. · 98 unmodified lines | |||
| 6803 | lua_CFunction openf, int glb);</pre> | 6787 | lua_CFunction openf, int glb);</pre> |
| 6804 | 6788 | ||
| 6805 | <p> | 6789 | <p> |
| 6806 | Calls function <code>openf</code> with string <code>modname</code> as an argument | 6790 | If <code>modname</code> is not already present in <a href="#pdf-package.loaded"><code>package.loaded</code></a>, |
| 6791 | calls function <code>openf</code> with string <code>modname</code> as an argument | ||
| 6807 | and sets the call result in <code>package.loaded[modname]</code>, | 6792 | and sets the call result in <code>package.loaded[modname]</code>, |
| 6808 | as if that function has been called through <a href="#pdf-require"><code>require</code></a>. | 6793 | as if that function has been called through <a href="#pdf-require"><code>require</code></a>. |
| 6809 | 6794 | ||
| 6810 | 6795 | ||
| 6811 | <p> | 6796 | <p> |
| 6812 | If <code>glb</code> is true, | 6797 | If <code>glb</code> is true, |
| 6813 | also stores the result into global <code>modname</code>. | 6798 | also stores the module into global <code>modname</code>. |
| 6814 | 6799 | ||
| 6815 | 6800 | ||
| 6816 | <p> | 6801 | <p> |
| 6817 | Leaves a copy of that result on the stack. | 6802 | Leaves a copy of the module on the stack. |
| 6818 | 6803 | ||
| 6819 | 6804 | ||
| 6820 | 6805 | ||
| @@ -7218,21 +7203,19 @@ Otherwise, returns the metatable of the given object. · 397 unmodified lines | |||
| 7218 | 7203 | ||
| 7219 | 7204 | ||
| 7220 | <p> | 7205 | <p> |
| 7221 | If <code>t</code> has a metamethod <code>__ipairs</code>, | 7206 | Returns three values (an iterator function, the table <code>t</code>, and 0) |
| 7222 | calls it with <code>t</code> as argument and returns the first three | ||
| 7223 | results from the call. | ||
| 7224 | |||
| 7225 | |||
| 7226 | <p> | ||
| 7227 | Otherwise, | ||
| 7228 | returns three values: an iterator function, the table <code>t</code>, and 0, | ||
| 7229 | so that the construction | 7207 | so that the construction |
| 7230 | 7208 | ||
| 7231 | <pre> | 7209 | <pre> |
| 7232 | for i,v in ipairs(t) do <em>body</em> end | 7210 | for i,v in ipairs(t) do <em>body</em> end |
| 7233 | </pre><p> | 7211 | </pre><p> |
| 7234 | will iterate over the pairs (<code>1,t[1]</code>), (<code>2,t[2]</code>), ..., | 7212 | will iterate over the pairs |
| 7235 | up to the first integer key absent from the table. | 7213 | (<code>1,t[1]</code>), (<code>2,t[2]</code>), ..., (<code>#t,t[#t]</code>). |
| 7214 | |||
| 7215 | |||
| 7216 | <p> | ||
| 7217 | The table should be a proper sequence | ||
| 7218 | or have a <code>__len</code> metamethod (see <a href="#3.4.7">§3.4.7</a>). | ||
| 7236 | 7219 | ||
| 7237 | 7220 | ||
| 7238 | 7221 | ||
| @@ -7973,9 +7956,9 @@ The name of this C function is the string "<code>luaopen_</code>" · 734 unmodified lines | |||
| 7973 | concatenated with a copy of the module name where each dot | 7956 | concatenated with a copy of the module name where each dot |
| 7974 | is replaced by an underscore. | 7957 | is replaced by an underscore. |
| 7975 | Moreover, if the module name has a hyphen, | 7958 | Moreover, if the module name has a hyphen, |
| 7976 | its prefix up to (and including) the first hyphen is removed. | 7959 | its sufix after (and including) the first hyphen is removed. |
| 7977 | For instance, if the module name is <code>a.v1-b.c</code>, | 7960 | For instance, if the module name is <code>a.b.c-v2.1</code>, |
| 7978 | the function name will be <code>luaopen_b_c</code>. | 7961 | the function name will be <code>luaopen_a_b_c</code>. |
| 7979 | 7962 | ||
| 7980 | 7963 | ||
| 7981 | <p> | 7964 | <p> |
| @@ -8138,6 +8121,8 @@ This function may not work correctly in architectures · 156 unmodified lines | |||
| 8138 | with mixed endian. | 8121 | with mixed endian. |
| 8139 | 8122 | ||
| 8140 | 8123 | ||
| 8124 | |||
| 8125 | |||
| 8141 | <p> | 8126 | <p> |
| 8142 | <hr><h3><a name="pdf-string.dumpint"><code>string.dumpint (n [, size [, endianness]])</code></a></h3> | 8127 | <hr><h3><a name="pdf-string.dumpint"><code>string.dumpint (n [, size [, endianness]])</code></a></h3> |
| 8143 | Returns a string with the two-complement representation of integer <code>n</code>, | 8128 | Returns a string with the two-complement representation of integer <code>n</code>, |
| @@ -8165,7 +8150,7 @@ that do not use a two-complement representation for integers. · 21 unmodified lines | |||
| 8165 | 8150 | ||
| 8166 | <p> | 8151 | <p> |
| 8167 | Looks for the first match of | 8152 | Looks for the first match of |
| 8168 | <code>pattern</code> in the string <code>s</code>. | 8153 | <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) in the string <code>s</code>. |
| 8169 | If it finds a match, then <code>find</code> returns the indices of <code>s</code> | 8154 | If it finds a match, then <code>find</code> returns the indices of <code>s</code> |
| 8170 | where this occurrence starts and ends; | 8155 | where this occurrence starts and ends; |
| 8171 | otherwise, it returns <b>nil</b>. | 8156 | otherwise, it returns <b>nil</b>. |
| @@ -8235,7 +8220,8 @@ it is converted to one following the same rules of <a href="#pdf-tostring"><code · 63 unmodified lines | |||
| 8235 | <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern)</code></a></h3> | 8220 | <hr><h3><a name="pdf-string.gmatch"><code>string.gmatch (s, pattern)</code></a></h3> |
| 8236 | Returns an iterator function that, | 8221 | Returns an iterator function that, |
| 8237 | each time it is called, | 8222 | each time it is called, |
| 8238 | returns the next captures from <code>pattern</code> over the string <code>s</code>. | 8223 | returns the next captures from <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) |
| 8224 | over the string <code>s</code>. | ||
| 8239 | If <code>pattern</code> specifies no captures, | 8225 | If <code>pattern</code> specifies no captures, |
| 8240 | then the whole match is produced in each call. | 8226 | then the whole match is produced in each call. |
| 8241 | 8227 | ||
| @@ -8273,7 +8259,7 @@ work as an anchor, as this would prevent the iteration. · 31 unmodified lines | |||
| 8273 | <hr><h3><a name="pdf-string.gsub"><code>string.gsub (s, pattern, repl [, n])</code></a></h3> | 8259 | <hr><h3><a name="pdf-string.gsub"><code>string.gsub (s, pattern, repl [, n])</code></a></h3> |
| 8274 | Returns a copy of <code>s</code> | 8260 | Returns a copy of <code>s</code> |
| 8275 | in which all (or the first <code>n</code>, if given) | 8261 | in which all (or the first <code>n</code>, if given) |
| 8276 | occurrences of the <code>pattern</code> have been | 8262 | occurrences of the <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) have been |
| 8277 | replaced by a replacement string specified by <code>repl</code>, | 8263 | replaced by a replacement string specified by <code>repl</code>, |
| 8278 | which can be a string, a table, or a function. | 8264 | which can be a string, a table, or a function. |
| 8279 | <code>gsub</code> also returns, as its second value, | 8265 | <code>gsub</code> also returns, as its second value, |
| @@ -8368,7 +8354,7 @@ The definition of what an uppercase letter is depends on the current locale. · 88 unmodified lines | |||
| 8368 | <p> | 8354 | <p> |
| 8369 | <hr><h3><a name="pdf-string.match"><code>string.match (s, pattern [, init])</code></a></h3> | 8355 | <hr><h3><a name="pdf-string.match"><code>string.match (s, pattern [, init])</code></a></h3> |
| 8370 | Looks for the first <em>match</em> of | 8356 | Looks for the first <em>match</em> of |
| 8371 | <code>pattern</code> in the string <code>s</code>. | 8357 | <code>pattern</code> (see <a href="#6.4.1">§6.4.1</a>) in the string <code>s</code>. |
| 8372 | If it finds one, then <code>match</code> returns | 8358 | If it finds one, then <code>match</code> returns |
| 8373 | the captures from the pattern; | 8359 | the captures from the pattern; |
| 8374 | otherwise it returns <b>nil</b>. | 8360 | otherwise it returns <b>nil</b>. |
| @@ -8456,8 +8442,21 @@ The definition of what a lowercase letter is depends on the current locale. · 81 unmodified lines | |||
| 8456 | 8442 | ||
| 8457 | 8443 | ||
| 8458 | 8444 | ||
| 8445 | |||
| 8446 | |||
| 8459 | <h3>6.4.1 – <a name="6.4.1">Patterns</a></h3> | 8447 | <h3>6.4.1 – <a name="6.4.1">Patterns</a></h3> |
| 8460 | 8448 | ||
| 8449 | <p> | ||
| 8450 | Patterns in Lua are described by regular strings, | ||
| 8451 | which are interpreted as patterns by the pattern-matching functions | ||
| 8452 | <a href="#pdf-string.find"><code>string.find</code></a>, | ||
| 8453 | <a href="#pdf-string.gmatch"><code>string.gmatch</code></a>, | ||
| 8454 | <a href="#pdf-string.gsub"><code>string.gsub</code></a>, | ||
| 8455 | and <a href="#pdf-string.match"><code>string.match</code></a>. | ||
| 8456 | This section describes the syntax and the meaning | ||
| 8457 | (that is, what they match) of these strings. | ||
| 8458 | |||
| 8459 | |||
| 8461 | 8460 | ||
| 8462 | <h4>Character Class:</h4><p> | 8461 | <h4>Character Class:</h4><p> |
| 8463 | A <em>character class</em> is used to represent a set of characters. | 8462 | A <em>character class</em> is used to represent a set of characters. |
| @@ -8649,8 +8648,6 @@ string <code>"flaaap"</code>, there will be two captures: 3 and 5. · 185 unmodified lines | |||
| 8649 | 8648 | ||
| 8650 | 8649 | ||
| 8651 | 8650 | ||
| 8652 | |||
| 8653 | |||
| 8654 | <h2>6.5 – <a name="6.5">UTF-8 Support</a></h2> | 8651 | <h2>6.5 – <a name="6.5">UTF-8 Support</a></h2> |
| 8655 | 8652 | ||
| 8656 | <p> | 8653 | <p> |
| @@ -8774,11 +8771,6 @@ All functions ignore non-numeric keys · 117 unmodified lines | |||
| 8774 | in tables given as arguments. | 8771 | in tables given as arguments. |
| 8775 | 8772 | ||
| 8776 | 8773 | ||
| 8777 | <p> | ||
| 8778 | For performance reasons, | ||
| 8779 | all table accesses (get/set) performed by these functions are raw. | ||
| 8780 | |||
| 8781 | |||
| 8782 | <p> | 8774 | <p> |
| 8783 | <hr><h3><a name="pdf-table.concat"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3> | 8775 | <hr><h3><a name="pdf-table.concat"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3> |
| 8784 | 8776 | ||
| @@ -8794,6 +8786,22 @@ If <code>i</code> is greater than <code>j</code>, returns the empty string. · 9 unmodified lines | |||
| 8794 | 8786 | ||
| 8795 | 8787 | ||
| 8796 | 8788 | ||
| 8789 | <p> | ||
| 8790 | <hr><h3><a name="pdf-table.copy"><code>table.copy (a1, f, e, [a2,] t)</code></a></h3> | ||
| 8791 | |||
| 8792 | |||
| 8793 | <p> | ||
| 8794 | Copies elements from table <code>a1</code> to table <code>a2</code>. | ||
| 8795 | This function performs the equivalent to the following | ||
| 8796 | multiple assignment: | ||
| 8797 | <code>a2[t],··· = a1[f],···,a1[e]</code>. | ||
| 8798 | The default for <code>a2</code> is <code>a1</code>. | ||
| 8799 | The destination range can overlap with the source range. | ||
| 8800 | Index <code>f</code> must be positive. | ||
| 8801 | |||
| 8802 | |||
| 8803 | |||
| 8804 | |||
| 8797 | <p> | 8805 | <p> |
| 8798 | <hr><h3><a name="pdf-table.insert"><code>table.insert (list, [pos,] value)</code></a></h3> | 8806 | <hr><h3><a name="pdf-table.insert"><code>table.insert (list, [pos,] value)</code></a></h3> |
| 8799 | 8807 | ||
| @@ -9014,18 +9022,6 @@ a value larger than any other numerical value. · 214 unmodified lines | |||
| 9014 | 9022 | ||
| 9015 | 9023 | ||
| 9016 | 9024 | ||
| 9017 | <p> | ||
| 9018 | <hr><h3><a name="pdf-math.ifloor"><code>math.ifloor (x)</code></a></h3> | ||
| 9019 | |||
| 9020 | |||
| 9021 | <p> | ||
| 9022 | Returns the largest integer smaller than or equal to <code>x</code>. | ||
| 9023 | If the value does not fit in an integer, | ||
| 9024 | returns <b>nil</b>. | ||
| 9025 | |||
| 9026 | |||
| 9027 | |||
| 9028 | |||
| 9029 | <p> | 9025 | <p> |
| 9030 | <hr><h3><a name="pdf-math.log"><code>math.log (x [, base])</code></a></h3> | 9026 | <hr><h3><a name="pdf-math.log"><code>math.log (x [, base])</code></a></h3> |
| 9031 | 9027 | ||
| @@ -9171,6 +9167,18 @@ Returns the tangent of <code>x</code> (assumed to be in radians). · 139 unmodified lines | |||
| 9171 | 9167 | ||
| 9172 | 9168 | ||
| 9173 | 9169 | ||
| 9170 | <p> | ||
| 9171 | <hr><h3><a name="pdf-math.tointeger"><code>math.tointeger (x)</code></a></h3> | ||
| 9172 | |||
| 9173 | |||
| 9174 | <p> | ||
| 9175 | If the value <code>x</code> is convertible to an integer, | ||
| 9176 | returns that integer. | ||
| 9177 | Otherwise, returns <b>nil</b>. | ||
| 9178 | |||
| 9179 | |||
| 9180 | |||
| 9181 | |||
| 9174 | <p> | 9182 | <p> |
| 9175 | <hr><h3><a name="pdf-math.type"><code>math.type (x)</code></a></h3> | 9183 | <hr><h3><a name="pdf-math.type"><code>math.type (x)</code></a></h3> |
| 9176 | 9184 | ||
| @@ -9183,6 +9191,18 @@ or <b>nil</b> if <code>x</code> is not a number. · 6 unmodified lines | |||
| 9183 | 9191 | ||
| 9184 | 9192 | ||
| 9185 | 9193 | ||
| 9194 | <p> | ||
| 9195 | <hr><h3><a name="pdf-math.ult"><code>math.ult (m, n)</code></a></h3> | ||
| 9196 | |||
| 9197 | |||
| 9198 | <p> | ||
| 9199 | Returns a boolean, | ||
| 9200 | true if integer <code>m</code> is below integer <code>n</code> when | ||
| 9201 | they are compared as unsigned integers. | ||
| 9202 | |||
| 9203 | |||
| 9204 | |||
| 9205 | |||
| 9186 | 9206 | ||
| 9187 | 9207 | ||
| 9188 | 9208 | ||
| @@ -10272,8 +10292,7 @@ The options are: · 1083 unmodified lines | |||
| 10272 | <li><b><code>--</code>: </b> stops handling options;</li> | 10292 | <li><b><code>--</code>: </b> stops handling options;</li> |
| 10273 | <li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li> | 10293 | <li><b><code>-</code>: </b> executes <code>stdin</code> as a file and stops handling options.</li> |
| 10274 | </ul><p> | 10294 | </ul><p> |
| 10275 | After handling its options, <code>lua</code> runs the given <em>script</em>, | 10295 | After handling its options, <code>lua</code> runs the given <em>script</em>. |
| 10276 | passing to it the given <em>args</em> as string arguments. | ||
| 10277 | When called without arguments, | 10296 | When called without arguments, |
| 10278 | <code>lua</code> behaves as <code>lua -v -i</code> | 10297 | <code>lua</code> behaves as <code>lua -v -i</code> |
| 10279 | when the standard input (<code>stdin</code>) is a terminal, | 10298 | when the standard input (<code>stdin</code>) is a terminal, |
| @@ -10283,7 +10302,7 @@ and as <code>lua -</code> otherwise. · 3 unmodified lines | |||
| 10283 | <p> | 10302 | <p> |
| 10284 | When called without option <code>-E</code>, | 10303 | When called without option <code>-E</code>, |
| 10285 | the interpreter checks for an environment variable <a name="pdf-LUA_INIT_5_3"><code>LUA_INIT_5_3</code></a> | 10304 | the interpreter checks for an environment variable <a name="pdf-LUA_INIT_5_3"><code>LUA_INIT_5_3</code></a> |
| 10286 | (or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if it is not defined) | 10305 | (or <a name="pdf-LUA_INIT"><code>LUA_INIT</code></a> if the versioned name is not defined) |
| 10287 | before running any argument. | 10306 | before running any argument. |
| 10288 | If the variable content has the format <code>@<em>filename</em></code>, | 10307 | If the variable content has the format <code>@<em>filename</em></code>, |
| 10289 | then <code>lua</code> executes the file. | 10308 | then <code>lua</code> executes the file. |
| @@ -10343,6 +10362,11 @@ For instance, the call · 53 unmodified lines | |||
| 10343 | $ lua -e "print(arg[1])" | 10362 | $ lua -e "print(arg[1])" |
| 10344 | </pre><p> | 10363 | </pre><p> |
| 10345 | will print "<code>-e</code>". | 10364 | will print "<code>-e</code>". |
| 10365 | If there is a script, | ||
| 10366 | the script is called with parameters | ||
| 10367 | <code>arg[1]</code>, ···, <code>arg[#arg]</code>. | ||
| 10368 | (Like all chunks in Lua, | ||
| 10369 | the script is compiled as a vararg function.) | ||
| 10346 | 10370 | ||
| 10347 | 10371 | ||
| 10348 | <p> | 10372 | <p> |
| @@ -10417,7 +10441,7 @@ do not imply source-code changes in a program, · 68 unmodified lines | |||
| 10417 | such as the numeric values for constants | 10441 | such as the numeric values for constants |
| 10418 | or the implementation of functions as macros. | 10442 | or the implementation of functions as macros. |
| 10419 | Therefore, | 10443 | Therefore, |
| 10420 | you should never assume that binaries are compatible between | 10444 | you should not assume that binaries are compatible between |
| 10421 | different Lua versions. | 10445 | different Lua versions. |
| 10422 | Always recompile clients of the Lua API when | 10446 | Always recompile clients of the Lua API when |
| 10423 | using a new version. | 10447 | using a new version. |
| @@ -10426,7 +10450,7 @@ using a new version. · 2 unmodified lines | |||
| 10426 | <p> | 10450 | <p> |
| 10427 | Similarly, Lua versions can always change the internal representation | 10451 | Similarly, Lua versions can always change the internal representation |
| 10428 | of precompiled chunks; | 10452 | of precompiled chunks; |
| 10429 | precompiled chunks are never compatible between different Lua versions. | 10453 | precompiled chunks are not compatible between different Lua versions. |
| 10430 | 10454 | ||
| 10431 | 10455 | ||
| 10432 | <p> | 10456 | <p> |
| @@ -10458,12 +10482,6 @@ it is not a general guideline for good programming. · 25 unmodified lines | |||
| 10458 | For good programming, | 10482 | For good programming, |
| 10459 | use floats where you need floats | 10483 | use floats where you need floats |
| 10460 | and integers where you need integers.) | 10484 | and integers where you need integers.) |
| 10461 | |||
| 10462 | |||
| 10463 | <p> | ||
| 10464 | Although not formally an incompatibility, | ||
| 10465 | the proper differentiation between floats and integers | ||
| 10466 | have an impact on performance. | ||
| 10467 | </li> | 10485 | </li> |
| 10468 | 10486 | ||
| 10469 | <li> | 10487 | <li> |
| @@ -10502,6 +10520,16 @@ better yet, to replace its functions with appropriate bitwise operations. · 32 unmodified lines | |||
| 10502 | while the bitwise operators in Standard Lua operate on 64-bit integers.) | 10520 | while the bitwise operators in Standard Lua operate on 64-bit integers.) |
| 10503 | </li> | 10521 | </li> |
| 10504 | 10522 | ||
| 10523 | <li> | ||
| 10524 | The Table library now respects metamethods | ||
| 10525 | for setting and getting elements. | ||
| 10526 | </li> | ||
| 10527 | |||
| 10528 | <li> | ||
| 10529 | The <a href="#pdf-ipairs"><code>ipairs</code></a> iterator now respects metamethods and | ||
| 10530 | its id{__ipairs} metamethod has been deprecated. | ||
| 10531 | </li> | ||
| 10532 | |||
| 10505 | <li> | 10533 | <li> |
| 10506 | Option names in <a href="#pdf-io.read"><code>io.read</code></a> do not have a starting '<code>*</code>' anymore. | 10534 | Option names in <a href="#pdf-io.read"><code>io.read</code></a> do not have a starting '<code>*</code>' anymore. |
| 10507 | For compatibility, Lua will continue to ignore this character. | 10535 | For compatibility, Lua will continue to ignore this character. |
| @@ -10513,12 +10541,23 @@ The following functions were deprecated in the mathematical library: · 5 unmodified lines | |||
| 10513 | <code>frexp</code>, and <code>ldexp</code>. | 10541 | <code>frexp</code>, and <code>ldexp</code>. |
| 10514 | You can replace <code>math.pow(x,y)</code> with <code>x^y</code>; | 10542 | You can replace <code>math.pow(x,y)</code> with <code>x^y</code>; |
| 10515 | you can replace <code>math.atan2</code> with <code>math.atan</code>, | 10543 | you can replace <code>math.atan2</code> with <code>math.atan</code>, |
| 10516 | which now accepts two parameters; | 10544 | which now accepts one or two parameters; |
| 10517 | you can replace <code>math.ldexp(x,exp)</code> with <code>x * 2.0^exp</code>. | 10545 | you can replace <code>math.ldexp(x,exp)</code> with <code>x * 2.0^exp</code>. |
| 10518 | For the other operations, | 10546 | For the other operations, |
| 10519 | the best choice is to use an external library. | 10547 | the best choice is to use an external library. |
| 10520 | </li> | 10548 | </li> |
| 10521 | 10549 | ||
| 10550 | <li> | ||
| 10551 | The searcher for C loaders used by <a href="#pdf-require"><code>require</code></a> | ||
| 10552 | changed the way it handles versioned names. | ||
| 10553 | Now, the version should come after the module name | ||
| 10554 | (as is usual in most other tools). | ||
| 10555 | For compatibility, that searcher still tries the old format | ||
| 10556 | if if cannot find an open function according to the new style. | ||
| 10557 | (Lua 5.2 already worked that way, | ||
| 10558 | but it did not document the change.) | ||
| 10559 | </li> | ||
| 10560 | |||
| 10522 | </ul> | 10561 | </ul> |
| 10523 | 10562 | ||
| 10524 | 10563 | ||
| @@ -10541,6 +10580,13 @@ Function <a href="#lua_dump"><code>lua_dump</code></a> has an extra parameter, < · 16 unmodified lines | |||
| 10541 | Use 0 as the value of this parameter to get the old behavior. | 10580 | Use 0 as the value of this parameter to get the old behavior. |
| 10542 | </li> | 10581 | </li> |
| 10543 | 10582 | ||
| 10583 | <li> | ||
| 10584 | Functions to inject/project unsigned integers | ||
| 10585 | (<code>lua_pushunsigned</code>, <code>lua_tounsigned</code>, etc.) | ||
| 10586 | were deprecated. | ||
| 10587 | Use their signed equivalents with a type cast. | ||
| 10588 | </li> | ||
| 10589 | |||
| 10544 | </ul> | 10590 | </ul> |
| 10545 | 10591 | ||
| 10546 | 10592 | ||
| @@ -10550,7 +10596,7 @@ Use 0 as the value of this parameter to get the old behavior. · 3 unmodified lines | |||
| 10550 | 10596 | ||
| 10551 | <p> | 10597 | <p> |
| 10552 | Here is the complete syntax of Lua in extended BNF. | 10598 | Here is the complete syntax of Lua in extended BNF. |
| 10553 | (It does not describe operator precedences.) | 10599 | (For operator precedences, see <a href="#3.4.8">§3.4.8</a>.) |
| 10554 | 10600 | ||
| 10555 | 10601 | ||
| 10556 | 10602 | ||
| @@ -10635,10 +10681,10 @@ Here is the complete syntax of Lua in extended BNF. · 78 unmodified lines | |||
| 10635 | <HR> | 10681 | <HR> |
| 10636 | <SMALL CLASS="footer"> | 10682 | <SMALL CLASS="footer"> |
| 10637 | Last update: | 10683 | Last update: |
| 10638 | Thu Jun 19 17:13:19 BRT 2014 | 10684 | Thu Jul 31 14:02:14 BRT 2014 |
| 10639 | </SMALL> | 10685 | </SMALL> |
| 10640 | <!-- | 10686 | <!-- |
| 10641 | Last change: updated for Lua 5.3.0 (work3) | 10687 | Last change: revised for Lua 5.3.0 (alpha) |
| 10642 | --> | 10688 | --> |
| 10643 | 10689 | ||
| 10644 | </body></html> | 10690 | </body></html> |
| @@ -31,12 +31,12 @@ tt, kbd, code { · 30 unmodified lines | |||
| 31 | <HR> | 31 | <HR> |
| 32 | <H1> | 32 | <H1> |
| 33 | <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A> | 33 | <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A> |
| 34 | Welcome to Lua 5.3 (work3) | 34 | Welcome to Lua 5.3 (alpha) |
| 35 | </H1> | 35 | </H1> |
| 36 | 36 | ||
| 37 | <P> | 37 | <P> |
| 38 | <IMG SRC="alert.png" ALIGN="absbottom"> | 38 | <IMG SRC="alert.png" ALIGN="absbottom"> |
| 39 | <EM>All details may change in the final version.</EM> | 39 | <EM>Some details may change in the final version.</EM> |
| 40 | 40 | ||
| 41 | <P> | 41 | <P> |
| 42 | <A HREF="#about">about</A> | 42 | <A HREF="#about">about</A> |
| @@ -114,7 +114,7 @@ Here are the details. · 71 unmodified lines | |||
| 114 | <OL> | 114 | <OL> |
| 115 | <LI> | 115 | <LI> |
| 116 | Open a terminal window and move to | 116 | Open a terminal window and move to |
| 117 | the top-level directory, which is named <TT>lua-5.3.0-work3</TT>. | 117 | the top-level directory, which is named <TT>lua-5.3.0-alpha</TT>. |
| 118 | The <TT>Makefile</TT> there controls both the build process and the installation process. | 118 | The <TT>Makefile</TT> there controls both the build process and the installation process. |
| 119 | <P> | 119 | <P> |
| 120 | <LI> | 120 | <LI> |
| @@ -275,36 +275,38 @@ lists the · 154 unmodified lines | |||
| 275 | <LI> better support for small architectures ("Small Lua" with 32-bit numbers) | 275 | <LI> better support for small architectures ("Small Lua" with 32-bit numbers) |
| 276 | <LI> bitwise operators | 276 | <LI> bitwise operators |
| 277 | <LI> basic utf-8 library | 277 | <LI> basic utf-8 library |
| 278 | |||
| 278 | <LI> utf-8 escapes in literal strings | 279 | <LI> utf-8 escapes in literal strings |
| 279 | <LI> functions for packing/unpacking numbers | ||
| 280 | <LI> userdata can have any Lua value as uservalue | ||
| 281 | <LI> strip option in <CODE>lua_dump</CODE>/<CODE>string.dump</CODE> | 280 | <LI> strip option in <CODE>lua_dump</CODE>/<CODE>string.dump</CODE> |
| 282 | </UL> | 281 | </UL> |
| 283 | 282 | ||
| 284 | Here are the other changes introduced in Lua 5.3: | 283 | Here are the other changes introduced in Lua 5.3: |
| 285 | <H3>Language</H3> | 284 | <H3>Language</H3> |
| 286 | <UL> | 285 | <UL> |
| 287 | <LI> | 286 | <LI> userdata can have any Lua value as uservalue |
| 287 | <LI> integer division | ||
| 288 | <LI> more flexible rules for some metamethods | ||
| 288 | </UL> | 289 | </UL> |
| 289 | 290 | ||
| 290 | <H3>Libraries</H3> | 291 | <H3>Libraries</H3> |
| 291 | <UL> | 292 | <UL> |
| 292 | <LI> | 293 | <LI> functions for packing/unpacking numbers |
| 294 | <LI> strip option in <CODE>string.dump</CODE> | ||
| 295 | <LI> table library respects metamethods | ||
| 296 | <LI> new function <CODE>table.copy</CODE> | ||
| 297 | <LI> new function <CODE>debug.Csize</CODE> | ||
| 293 | </UL> | 298 | </UL> |
| 294 | 299 | ||
| 295 | <H3>C API</H3> | 300 | <H3>C API</H3> |
| 296 | <UL> | 301 | <UL> |
| 297 | <LI> | 302 | <LI> new functions: <CODE>lua_rotate</CODE>, <CODE>lua_isyieldable</CODE>, <CODE>lua_strtonum</CODE> |
| 298 | </UL> | 303 | <LI> <CODE>lua_gettable</CODE> and similar functions return type of resulted value |
| 299 | |||
| 300 | <H3>Implementation</H3> | ||
| 301 | <UL> | ||
| 302 | <LI> | ||
| 303 | </UL> | 304 | </UL> |
| 304 | 305 | ||
| 305 | <H3>Lua standalone interpreter</H3> | 306 | <H3>Lua standalone interpreter</H3> |
| 306 | <UL> | 307 | <UL> |
| 307 | <LI> Can be used as calculator; no need to prefix with '=' | 308 | <LI> can be used as calculator; no need to prefix with '=' |
| 309 | <LI> <CODE>arg</CODE> table available to all code | ||
| 308 | </UL> | 310 | </UL> |
| 309 | 311 | ||
| 310 | <H2><A NAME="license">License</A></H2> | 312 | <H2><A NAME="license">License</A></H2> |
| @@ -354,10 +356,10 @@ THE SOFTWARE. · 43 unmodified lines | |||
| 354 | <HR> | 356 | <HR> |
| 355 | <SMALL CLASS="footer"> | 357 | <SMALL CLASS="footer"> |
| 356 | Last update: | 358 | Last update: |
| 357 | Wed Jun 11 22:54:18 BRT 2014 | 359 | Thu Jul 31 15:23:46 BRT 2014 |
| 358 | </SMALL> | 360 | </SMALL> |
| 359 | <!-- | 361 | <!-- |
| 360 | Last change: updated for Lua 5.3.0 (work3) | 362 | Last change: updated for Lua 5.3.0 (alpha) |
| 361 | --> | 363 | --> |
| 362 | 364 | ||
| 363 | </BODY> | 365 | </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 -Wextra -DLUA_COMPAT_ALL $(SYSCFLAGS) $(MYCFLAGS) | 10 | CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS) |
| 11 | LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) | 11 | LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) |
| 12 | LIBS= -lm $(SYSLIBS) $(MYLIBS) | 12 | LIBS= -lm $(SYSLIBS) $(MYLIBS) |
| 13 | 13 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.219 2014/06/19 18:27:20 roberto Exp $ | 2 | ** $Id: lapi.c,v 2.232 2014/07/30 14:00:14 roberto Exp $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -44,32 +44,35 @@ const char lua_ident[] = · 38 unmodified lines | |||
| 44 | /* test for pseudo index */ | 44 | /* test for pseudo index */ |
| 45 | #define ispseudo(i) ((i) <= LUA_REGISTRYINDEX) | 45 | #define ispseudo(i) ((i) <= LUA_REGISTRYINDEX) |
| 46 | 46 | ||
| 47 | /* test for upvalue */ | ||
| 48 | #define isupvalue(i) ((i) < LUA_REGISTRYINDEX) | ||
| 49 | |||
| 47 | /* test for valid but not pseudo index */ | 50 | /* test for valid but not pseudo index */ |
| 48 | #define isstackindex(i, o) (isvalid(o) && !ispseudo(i)) | 51 | #define isstackindex(i, o) (isvalid(o) && !ispseudo(i)) |
| 49 | 52 | ||
| 50 | #define api_checkvalidindex(L, o) api_check(L, isvalid(o), "invalid index") | 53 | #define api_checkvalidindex(o) api_check(isvalid(o), "invalid index") |
| 51 | 54 | ||
| 52 | #define api_checkstackindex(L, i, o) \ | 55 | #define api_checkstackindex(i, o) \ |
| 53 | api_check(L, isstackindex(i, o), "index not in the stack") | 56 | api_check(isstackindex(i, o), "index not in the stack") |
| 54 | 57 | ||
| 55 | 58 | ||
| 56 | static TValue *index2addr (lua_State *L, int idx) { | 59 | static TValue *index2addr (lua_State *L, int idx) { |
| 57 | CallInfo *ci = L->ci; | 60 | CallInfo *ci = L->ci; |
| 58 | if (idx > 0) { | 61 | if (idx > 0) { |
| 59 | TValue *o = ci->func + idx; | 62 | TValue *o = ci->func + idx; |
| 60 | api_check(L, idx <= ci->top - (ci->func + 1), "unacceptable index"); | 63 | api_check(idx <= ci->top - (ci->func + 1), "unacceptable index"); |
| 61 | if (o >= L->top) return NONVALIDVALUE; | 64 | if (o >= L->top) return NONVALIDVALUE; |
| 62 | else return o; | 65 | else return o; |
| 63 | } | 66 | } |
| 64 | else if (!ispseudo(idx)) { /* negative index */ | 67 | else if (!ispseudo(idx)) { /* negative index */ |
| 65 | api_check(L, idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); | 68 | api_check(idx != 0 && -idx <= L->top - (ci->func + 1), "invalid index"); |
| 66 | return L->top + idx; | 69 | return L->top + idx; |
| 67 | } | 70 | } |
| 68 | else if (idx == LUA_REGISTRYINDEX) | 71 | else if (idx == LUA_REGISTRYINDEX) |
| 69 | return &G(L)->l_registry; | 72 | return &G(L)->l_registry; |
| 70 | else { /* upvalues */ | 73 | else { /* upvalues */ |
| 71 | idx = LUA_REGISTRYINDEX - idx; | 74 | idx = LUA_REGISTRYINDEX - idx; |
| 72 | api_check(L, idx <= MAXUPVAL + 1, "upvalue index too large"); | 75 | api_check(idx <= MAXUPVAL + 1, "upvalue index too large"); |
| 73 | if (ttislcf(ci->func)) /* light C function? */ | 76 | if (ttislcf(ci->func)) /* light C function? */ |
| 74 | return NONVALIDVALUE; /* it has no upvalues */ | 77 | return NONVALIDVALUE; /* it has no upvalues */ |
| 75 | else { | 78 | else { |
| @@ -94,7 +97,7 @@ LUA_API int lua_checkstack (lua_State *L, int size) { · 18 unmodified lines | |||
| 94 | int res; | 97 | int res; |
| 95 | CallInfo *ci = L->ci; | 98 | CallInfo *ci = L->ci; |
| 96 | lua_lock(L); | 99 | lua_lock(L); |
| 97 | api_check(L, size >= 0, "negative 'size'"); | 100 | api_check(size >= 0, "negative 'size'"); |
| 98 | if (L->stack_last - L->top > size) /* stack large enough? */ | 101 | if (L->stack_last - L->top > size) /* stack large enough? */ |
| 99 | res = 1; /* yes; check is OK */ | 102 | res = 1; /* yes; check is OK */ |
| 100 | else { /* no; need to grow stack */ | 103 | else { /* no; need to grow stack */ |
| @@ -116,8 +119,8 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { · 15 unmodified lines | |||
| 116 | if (from == to) return; | 119 | if (from == to) return; |
| 117 | lua_lock(to); | 120 | lua_lock(to); |
| 118 | api_checknelems(from, n); | 121 | api_checknelems(from, n); |
| 119 | api_check(from, G(from) == G(to), "moving among independent states"); | 122 | api_check(G(from) == G(to), "moving among independent states"); |
| 120 | api_check(from, to->ci->top - to->top >= n, "not enough elements to move"); | 123 | api_check(to->ci->top - to->top >= n, "not enough elements to move"); |
| 121 | from->top -= n; | 124 | from->top -= n; |
| 122 | for (i = 0; i < n; i++) { | 125 | for (i = 0; i < n; i++) { |
| 123 | setobj2s(to, to->top++, from->top + i); | 126 | setobj2s(to, to->top++, from->top + i); |
| @@ -168,13 +171,13 @@ LUA_API void lua_settop (lua_State *L, int idx) { · 44 unmodified lines | |||
| 168 | StkId func = L->ci->func; | 171 | StkId func = L->ci->func; |
| 169 | lua_lock(L); | 172 | lua_lock(L); |
| 170 | if (idx >= 0) { | 173 | if (idx >= 0) { |
| 171 | api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); | 174 | api_check(idx <= L->stack_last - (func + 1), "new top too large"); |
| 172 | while (L->top < (func + 1) + idx) | 175 | while (L->top < (func + 1) + idx) |
| 173 | setnilvalue(L->top++); | 176 | setnilvalue(L->top++); |
| 174 | L->top = (func + 1) + idx; | 177 | L->top = (func + 1) + idx; |
| 175 | } | 178 | } |
| 176 | else { | 179 | else { |
| 177 | api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); | 180 | api_check(-(idx+1) <= (L->top - (func + 1)), "invalid new top"); |
| 178 | L->top += idx+1; /* `subtract' index (index is negative) */ | 181 | L->top += idx+1; /* `subtract' index (index is negative) */ |
| 179 | } | 182 | } |
| 180 | lua_unlock(L); | 183 | lua_unlock(L); |
| @@ -183,7 +186,7 @@ LUA_API void lua_settop (lua_State *L, int idx) { · 2 unmodified lines | |||
| 183 | 186 | ||
| 184 | /* | 187 | /* |
| 185 | ** Reverse the stack segment from 'from' to 'to' | 188 | ** Reverse the stack segment from 'from' to 'to' |
| 186 | ** (auxiliar to 'lua_rotate') | 189 | ** (auxiliary to 'lua_rotate') |
| 187 | */ | 190 | */ |
| 188 | static void reverse (lua_State *L, StkId from, StkId to) { | 191 | static void reverse (lua_State *L, StkId from, StkId to) { |
| 189 | for (; from < to; from++, to--) { | 192 | for (; from < to; from++, to--) { |
| @@ -204,8 +207,8 @@ LUA_API void lua_rotate (lua_State *L, int idx, int n) { · 14 unmodified lines | |||
| 204 | lua_lock(L); | 207 | lua_lock(L); |
| 205 | t = L->top - 1; /* end of stack segment being rotated */ | 208 | t = L->top - 1; /* end of stack segment being rotated */ |
| 206 | p = index2addr(L, idx); /* start of segment */ | 209 | p = index2addr(L, idx); /* start of segment */ |
| 207 | api_checkstackindex(L, idx, p); | 210 | api_checkstackindex(idx, p); |
| 208 | api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); | 211 | api_check((n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); |
| 209 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ | 212 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ |
| 210 | reverse(L, p, m); /* reverse the prefix with length 'n' */ | 213 | reverse(L, p, m); /* reverse the prefix with length 'n' */ |
| 211 | reverse(L, m + 1, t); /* reverse the suffix */ | 214 | reverse(L, m + 1, t); /* reverse the suffix */ |
| @@ -214,31 +217,17 @@ LUA_API void lua_rotate (lua_State *L, int idx, int n) { · 2 unmodified lines | |||
| 214 | } | 217 | } |
| 215 | 218 | ||
| 216 | 219 | ||
| 217 | static void moveto (lua_State *L, TValue *fr, int idx) { | 220 | LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { |
| 218 | TValue *to = index2addr(L, idx); | 221 | TValue *fr, *to; |
| 219 | api_checkvalidindex(L, to); | 222 | lua_lock(L); |
| 223 | fr = index2addr(L, fromidx); | ||
| 224 | to = index2addr(L, toidx); | ||
| 225 | api_checkvalidindex(to); | ||
| 220 | setobj(L, to, fr); | 226 | setobj(L, to, fr); |
| 221 | if (idx < LUA_REGISTRYINDEX) /* function upvalue? */ | 227 | if (isupvalue(toidx)) /* function upvalue? */ |
| 222 | luaC_barrier(L, clCvalue(L->ci->func), fr); | 228 | luaC_barrier(L, clCvalue(L->ci->func), fr); |
| 223 | /* LUA_REGISTRYINDEX does not need gc barrier | 229 | /* LUA_REGISTRYINDEX does not need gc barrier |
| 224 | (collector revisits it before finishing collection) */ | 230 | (collector revisits it before finishing collection) */ |
| 225 | } | ||
| 226 | |||
| 227 | |||
| 228 | LUA_API void lua_replace (lua_State *L, int idx) { | ||
| 229 | lua_lock(L); | ||
| 230 | api_checknelems(L, 1); | ||
| 231 | moveto(L, L->top - 1, idx); | ||
| 232 | L->top--; | ||
| 233 | lua_unlock(L); | ||
| 234 | } | ||
| 235 | |||
| 236 | |||
| 237 | LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { | ||
| 238 | TValue *fr; | ||
| 239 | lua_lock(L); | ||
| 240 | fr = index2addr(L, fromidx); | ||
| 241 | moveto(L, fr, toidx); | ||
| 242 | lua_unlock(L); | 231 | lua_unlock(L); |
| 243 | } | 232 | } |
| 244 | 233 | ||
| @@ -265,6 +254,7 @@ LUA_API int lua_type (lua_State *L, int idx) { · 20 unmodified lines | |||
| 265 | 254 | ||
| 266 | LUA_API const char *lua_typename (lua_State *L, int t) { | 255 | LUA_API const char *lua_typename (lua_State *L, int t) { |
| 267 | UNUSED(L); | 256 | UNUSED(L); |
| 257 | api_check(LUA_TNONE <= t && t < LUA_NUMTAGS, "invalid tag"); | ||
| 268 | return ttypename(t); | 258 | return ttypename(t); |
| 269 | } | 259 | } |
| 270 | 260 | ||
| @@ -289,8 +279,8 @@ LUA_API int lua_isnumber (lua_State *L, int idx) { · 18 unmodified lines | |||
| 289 | 279 | ||
| 290 | 280 | ||
| 291 | LUA_API int lua_isstring (lua_State *L, int idx) { | 281 | LUA_API int lua_isstring (lua_State *L, int idx) { |
| 292 | int t = lua_type(L, idx); | 282 | const TValue *o = index2addr(L, idx); |
| 293 | return (t == LUA_TSTRING || t == LUA_TNUMBER); | 283 | return (ttisstring(o) || cvt2str(o)); |
| 294 | } | 284 | } |
| 295 | 285 | ||
| 296 | 286 | ||
| @@ -334,7 +324,7 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { · 37 unmodified lines | |||
| 334 | case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; | 324 | case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break; |
| 335 | case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; | 325 | case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; |
| 336 | case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; | 326 | case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; |
| 337 | default: api_check(L, 0, "invalid option"); | 327 | default: api_check(0, "invalid option"); |
| 338 | } | 328 | } |
| 339 | } | 329 | } |
| 340 | lua_unlock(L); | 330 | lua_unlock(L); |
| @@ -372,40 +362,6 @@ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { · 31 unmodified lines | |||
| 372 | } | 362 | } |
| 373 | 363 | ||
| 374 | 364 | ||
| 375 | LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) { | ||
| 376 | lua_Unsigned res = 0; | ||
| 377 | const TValue *o = index2addr(L, idx); | ||
| 378 | int isnum = 0; | ||
| 379 | switch (ttype(o)) { | ||
| 380 | case LUA_TNUMINT: { | ||
| 381 | res = l_castS2U(ivalue(o)); | ||
| 382 | isnum = 1; | ||
| 383 | break; | ||
| 384 | } | ||
| 385 | case LUA_TNUMFLT: { /* compute floor(n) % 2^(numbits in an integer) */ | ||
| 386 | const lua_Number two2n = cast_num(LUA_MAXUNSIGNED) + cast_num(1); | ||
| 387 | lua_Number n = fltvalue(o); /* get value */ | ||
| 388 | int neg = 0; | ||
| 389 | n = l_floor(n); /* get its floor */ | ||
| 390 | if (n < 0) { | ||
| 391 | neg = 1; | ||
| 392 | n = -n; /* make 'n' positive, so that 'fmod' is the same as '%' */ | ||
| 393 | } | ||
| 394 | n = l_mathop(fmod)(n, two2n); /* n = n % 2^(numbits in an integer) */ | ||
| 395 | if (luai_numisnan(n)) /* not a number? */ | ||
| 396 | break; /* not an integer, too */ | ||
| 397 | res = cast(lua_Unsigned, n); /* 'n' now must fit in an unsigned */ | ||
| 398 | if (neg) res = 0u - res; /* back to negative, if needed */ | ||
| 399 | isnum = 1; | ||
| 400 | break; | ||
| 401 | } | ||
| 402 | default: break; | ||
| 403 | } | ||
| 404 | if (pisnum) *pisnum = isnum; | ||
| 405 | return res; | ||
| 406 | } | ||
| 407 | |||
| 408 | |||
| 409 | LUA_API int lua_toboolean (lua_State *L, int idx) { | 365 | LUA_API int lua_toboolean (lua_State *L, int idx) { |
| 410 | const TValue *o = index2addr(L, idx); | 366 | const TValue *o = index2addr(L, idx); |
| 411 | return !l_isfalse(o); | 367 | return !l_isfalse(o); |
| @@ -415,14 +371,14 @@ LUA_API int lua_toboolean (lua_State *L, int idx) { · 3 unmodified lines | |||
| 415 | LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { | 371 | LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { |
| 416 | StkId o = index2addr(L, idx); | 372 | StkId o = index2addr(L, idx); |
| 417 | if (!ttisstring(o)) { | 373 | if (!ttisstring(o)) { |
| 418 | lua_lock(L); /* `luaV_tostring' may create a new string */ | 374 | if (!cvt2str(o)) { /* not convertible? */ |
| 419 | if (!luaV_tostring(L, o)) { /* conversion failed? */ | ||
| 420 | if (len != NULL) *len = 0; | 375 | if (len != NULL) *len = 0; |
| 421 | lua_unlock(L); | ||
| 422 | return NULL; | 376 | return NULL; |
| 423 | } | 377 | } |
| 378 | lua_lock(L); /* `luaO_tostring' may create a new string */ | ||
| 424 | luaC_checkGC(L); | 379 | luaC_checkGC(L); |
| 425 | o = index2addr(L, idx); /* previous call may reallocate the stack */ | 380 | o = index2addr(L, idx); /* previous call may reallocate the stack */ |
| 381 | luaO_tostring(L, o); | ||
| 426 | lua_unlock(L); | 382 | lua_unlock(L); |
| 427 | } | 383 | } |
| 428 | if (len != NULL) *len = tsvalue(o)->len; | 384 | if (len != NULL) *len = tsvalue(o)->len; |
| @@ -453,7 +409,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { · 24 unmodified lines | |||
| 453 | LUA_API void *lua_touserdata (lua_State *L, int idx) { | 409 | LUA_API void *lua_touserdata (lua_State *L, int idx) { |
| 454 | StkId o = index2addr(L, idx); | 410 | StkId o = index2addr(L, idx); |
| 455 | switch (ttnov(o)) { | 411 | switch (ttnov(o)) { |
| 456 | case LUA_TUSERDATA: return (rawuvalue(o) + 1); | 412 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); |
| 457 | case LUA_TLIGHTUSERDATA: return pvalue(o); | 413 | case LUA_TLIGHTUSERDATA: return pvalue(o); |
| 458 | default: return NULL; | 414 | default: return NULL; |
| 459 | } | 415 | } |
| @@ -512,14 +468,6 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { · 52 unmodified lines | |||
| 512 | } | 468 | } |
| 513 | 469 | ||
| 514 | 470 | ||
| 515 | LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) { | ||
| 516 | lua_lock(L); | ||
| 517 | setivalue(L->top, l_castU2S(u)); | ||
| 518 | api_incr_top(L); | ||
| 519 | lua_unlock(L); | ||
| 520 | } | ||
| 521 | |||
| 522 | |||
| 523 | LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { | 471 | LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { |
| 524 | TString *ts; | 472 | TString *ts; |
| 525 | lua_lock(L); | 473 | lua_lock(L); |
| @@ -582,7 +530,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { · 56 unmodified lines | |||
| 582 | else { | 530 | else { |
| 583 | CClosure *cl; | 531 | CClosure *cl; |
| 584 | api_checknelems(L, n); | 532 | api_checknelems(L, n); |
| 585 | api_check(L, n <= MAXUPVAL, "upvalue index too large"); | 533 | api_check(n <= MAXUPVAL, "upvalue index too large"); |
| 586 | luaC_checkGC(L); | 534 | luaC_checkGC(L); |
| 587 | cl = luaF_newCclosure(L, n); | 535 | cl = luaF_newCclosure(L, n); |
| 588 | cl->f = fn; | 536 | cl->f = fn; |
| @@ -667,7 +615,7 @@ LUA_API int lua_rawget (lua_State *L, int idx) { · 78 unmodified lines | |||
| 667 | StkId t; | 615 | StkId t; |
| 668 | lua_lock(L); | 616 | lua_lock(L); |
| 669 | t = index2addr(L, idx); | 617 | t = index2addr(L, idx); |
| 670 | api_check(L, ttistable(t), "table expected"); | 618 | api_check(ttistable(t), "table expected"); |
| 671 | setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); | 619 | setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1)); |
| 672 | lua_unlock(L); | 620 | lua_unlock(L); |
| 673 | return ttnov(L->top - 1); | 621 | return ttnov(L->top - 1); |
| @@ -678,7 +626,7 @@ LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { · 4 unmodified lines | |||
| 678 | StkId t; | 626 | StkId t; |
| 679 | lua_lock(L); | 627 | lua_lock(L); |
| 680 | t = index2addr(L, idx); | 628 | t = index2addr(L, idx); |
| 681 | api_check(L, ttistable(t), "table expected"); | 629 | api_check(ttistable(t), "table expected"); |
| 682 | setobj2s(L, L->top, luaH_getint(hvalue(t), n)); | 630 | setobj2s(L, L->top, luaH_getint(hvalue(t), n)); |
| 683 | api_incr_top(L); | 631 | api_incr_top(L); |
| 684 | lua_unlock(L); | 632 | lua_unlock(L); |
| @@ -691,7 +639,7 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { · 6 unmodified lines | |||
| 691 | TValue k; | 639 | TValue k; |
| 692 | lua_lock(L); | 640 | lua_lock(L); |
| 693 | t = index2addr(L, idx); | 641 | t = index2addr(L, idx); |
| 694 | api_check(L, ttistable(t), "table expected"); | 642 | api_check(ttistable(t), "table expected"); |
| 695 | setpvalue(&k, cast(void *, p)); | 643 | setpvalue(&k, cast(void *, p)); |
| 696 | setobj2s(L, L->top, luaH_get(hvalue(t), &k)); | 644 | setobj2s(L, L->top, luaH_get(hvalue(t), &k)); |
| 697 | api_incr_top(L); | 645 | api_incr_top(L); |
| @@ -746,8 +694,8 @@ LUA_API int lua_getuservalue (lua_State *L, int idx) { · 48 unmodified lines | |||
| 746 | StkId o; | 694 | StkId o; |
| 747 | lua_lock(L); | 695 | lua_lock(L); |
| 748 | o = index2addr(L, idx); | 696 | o = index2addr(L, idx); |
| 749 | api_check(L, ttisfulluserdata(o), "full userdata expected"); | 697 | api_check(ttisfulluserdata(o), "full userdata expected"); |
| 750 | getuservalue(L, rawuvalue(o), L->top); | 698 | getuservalue(L, uvalue(o), L->top); |
| 751 | api_incr_top(L); | 699 | api_incr_top(L); |
| 752 | lua_unlock(L); | 700 | lua_unlock(L); |
| 753 | return ttnov(L->top - 1); | 701 | return ttnov(L->top - 1); |
| @@ -796,42 +744,48 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { · 42 unmodified lines | |||
| 796 | 744 | ||
| 797 | 745 | ||
| 798 | LUA_API void lua_rawset (lua_State *L, int idx) { | 746 | LUA_API void lua_rawset (lua_State *L, int idx) { |
| 799 | StkId t; | 747 | StkId o; |
| 748 | Table *t; | ||
| 800 | lua_lock(L); | 749 | lua_lock(L); |
| 801 | api_checknelems(L, 2); | 750 | api_checknelems(L, 2); |
| 802 | t = index2addr(L, idx); | 751 | o = index2addr(L, idx); |
| 803 | api_check(L, ttistable(t), "table expected"); | 752 | api_check(ttistable(o), "table expected"); |
| 804 | setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); | 753 | t = hvalue(o); |
| 805 | invalidateTMcache(hvalue(t)); | 754 | setobj2t(L, luaH_set(L, t, L->top-2), L->top-1); |
| 806 | luaC_barrierback(L, gcvalue(t), L->top-1); | 755 | invalidateTMcache(t); |
| 756 | luaC_barrierback(L, t, L->top-1); | ||
| 807 | L->top -= 2; | 757 | L->top -= 2; |
| 808 | lua_unlock(L); | 758 | lua_unlock(L); |
| 809 | } | 759 | } |
| 810 | 760 | ||
| 811 | 761 | ||
| 812 | LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { | 762 | LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { |
| 813 | StkId t; | 763 | StkId o; |
| 764 | Table *t; | ||
| 814 | lua_lock(L); | 765 | lua_lock(L); |
| 815 | api_checknelems(L, 1); | 766 | api_checknelems(L, 1); |
| 816 | t = index2addr(L, idx); | 767 | o = index2addr(L, idx); |
| 817 | api_check(L, ttistable(t), "table expected"); | 768 | api_check(ttistable(o), "table expected"); |
| 818 | luaH_setint(L, hvalue(t), n, L->top - 1); | 769 | t = hvalue(o); |
| 819 | luaC_barrierback(L, gcvalue(t), L->top-1); | 770 | luaH_setint(L, t, n, L->top - 1); |
| 771 | luaC_barrierback(L, t, L->top-1); | ||
| 820 | L->top--; | 772 | L->top--; |
| 821 | lua_unlock(L); | 773 | lua_unlock(L); |
| 822 | } | 774 | } |
| 823 | 775 | ||
| 824 | 776 | ||
| 825 | LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { | 777 | LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { |
| 826 | StkId t; | 778 | StkId o; |
| 779 | Table *t; | ||
| 827 | TValue k; | 780 | TValue k; |
| 828 | lua_lock(L); | 781 | lua_lock(L); |
| 829 | api_checknelems(L, 1); | 782 | api_checknelems(L, 1); |
| 830 | t = index2addr(L, idx); | 783 | o = index2addr(L, idx); |
| 831 | api_check(L, ttistable(t), "table expected"); | 784 | api_check(ttistable(o), "table expected"); |
| 785 | t = hvalue(o); | ||
| 832 | setpvalue(&k, cast(void *, p)); | 786 | setpvalue(&k, cast(void *, p)); |
| 833 | setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1); | 787 | setobj2t(L, luaH_set(L, t, &k), L->top - 1); |
| 834 | luaC_barrierback(L, gcvalue(t), L->top - 1); | 788 | luaC_barrierback(L, t, L->top - 1); |
| 835 | L->top--; | 789 | L->top--; |
| 836 | lua_unlock(L); | 790 | lua_unlock(L); |
| 837 | } | 791 | } |
| @@ -846,7 +800,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { · 8 unmodified lines | |||
| 846 | if (ttisnil(L->top - 1)) | 800 | if (ttisnil(L->top - 1)) |
| 847 | mt = NULL; | 801 | mt = NULL; |
| 848 | else { | 802 | else { |
| 849 | api_check(L, ttistable(L->top - 1), "table expected"); | 803 | api_check(ttistable(L->top - 1), "table expected"); |
| 850 | mt = hvalue(L->top - 1); | 804 | mt = hvalue(L->top - 1); |
| 851 | } | 805 | } |
| 852 | switch (ttnov(obj)) { | 806 | switch (ttnov(obj)) { |
| @@ -861,7 +815,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { · 8 unmodified lines | |||
| 861 | case LUA_TUSERDATA: { | 815 | case LUA_TUSERDATA: { |
| 862 | uvalue(obj)->metatable = mt; | 816 | uvalue(obj)->metatable = mt; |
| 863 | if (mt) { | 817 | if (mt) { |
| 864 | luaC_objbarrier(L, rawuvalue(obj), mt); | 818 | luaC_objbarrier(L, uvalue(obj), mt); |
| 865 | luaC_checkfinalizer(L, gcvalue(obj), mt); | 819 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
| 866 | } | 820 | } |
| 867 | break; | 821 | break; |
| @@ -882,8 +836,8 @@ LUA_API void lua_setuservalue (lua_State *L, int idx) { · 14 unmodified lines | |||
| 882 | lua_lock(L); | 836 | lua_lock(L); |
| 883 | api_checknelems(L, 1); | 837 | api_checknelems(L, 1); |
| 884 | o = index2addr(L, idx); | 838 | o = index2addr(L, idx); |
| 885 | api_check(L, ttisfulluserdata(o), "full userdata expected"); | 839 | api_check(ttisfulluserdata(o), "full userdata expected"); |
| 886 | setuservalue(L, rawuvalue(o), L->top - 1); | 840 | setuservalue(L, uvalue(o), L->top - 1); |
| 887 | luaC_barrier(L, gcvalue(o), L->top - 1); | 841 | luaC_barrier(L, gcvalue(o), L->top - 1); |
| 888 | L->top--; | 842 | L->top--; |
| 889 | lua_unlock(L); | 843 | lua_unlock(L); |
| @@ -896,18 +850,18 @@ LUA_API void lua_setuservalue (lua_State *L, int idx) { · 6 unmodified lines | |||
| 896 | 850 | ||
| 897 | 851 | ||
| 898 | #define checkresults(L,na,nr) \ | 852 | #define checkresults(L,na,nr) \ |
| 899 | api_check(L, (nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \ | 853 | api_check((nr) == LUA_MULTRET || (L->ci->top - L->top >= (nr) - (na)), \ |
| 900 | "results from function overflow current stack size") | 854 | "results from function overflow current stack size") |
| 901 | 855 | ||
| 902 | 856 | ||
| 903 | LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx, | 857 | LUA_API void lua_callk (lua_State *L, int nargs, int nresults, lua_Ctx ctx, |
| 904 | lua_KFunction k) { | 858 | lua_KFunction k) { |
| 905 | StkId func; | 859 | StkId func; |
| 906 | lua_lock(L); | 860 | lua_lock(L); |
| 907 | api_check(L, k == NULL || !isLua(L->ci), | 861 | api_check(k == NULL || !isLua(L->ci), |
| 908 | "cannot use continuations inside hooks"); | 862 | "cannot use continuations inside hooks"); |
| 909 | api_checknelems(L, nargs+1); | 863 | api_checknelems(L, nargs+1); |
| 910 | api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); | 864 | api_check(L->status == LUA_OK, "cannot do calls on non-normal thread"); |
| 911 | checkresults(L, nargs, nresults); | 865 | checkresults(L, nargs, nresults); |
| 912 | func = L->top - (nargs+1); | 866 | func = L->top - (nargs+1); |
| 913 | if (k != NULL && L->nny == 0) { /* need to prepare continuation? */ | 867 | if (k != NULL && L->nny == 0) { /* need to prepare continuation? */ |
| @@ -940,21 +894,21 @@ static void f_call (lua_State *L, void *ud) { · 26 unmodified lines | |||
| 940 | 894 | ||
| 941 | 895 | ||
| 942 | LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, | 896 | LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, |
| 943 | int ctx, lua_KFunction k) { | 897 | lua_Ctx ctx, lua_KFunction k) { |
| 944 | struct CallS c; | 898 | struct CallS c; |
| 945 | int status; | 899 | int status; |
| 946 | ptrdiff_t func; | 900 | ptrdiff_t func; |
| 947 | lua_lock(L); | 901 | lua_lock(L); |
| 948 | api_check(L, k == NULL || !isLua(L->ci), | 902 | api_check(k == NULL || !isLua(L->ci), |
| 949 | "cannot use continuations inside hooks"); | 903 | "cannot use continuations inside hooks"); |
| 950 | api_checknelems(L, nargs+1); | 904 | api_checknelems(L, nargs+1); |
| 951 | api_check(L, L->status == LUA_OK, "cannot do calls on non-normal thread"); | 905 | api_check(L->status == LUA_OK, "cannot do calls on non-normal thread"); |
| 952 | checkresults(L, nargs, nresults); | 906 | checkresults(L, nargs, nresults); |
| 953 | if (errfunc == 0) | 907 | if (errfunc == 0) |
| 954 | func = 0; | 908 | func = 0; |
| 955 | else { | 909 | else { |
| 956 | StkId o = index2addr(L, errfunc); | 910 | StkId o = index2addr(L, errfunc); |
| 957 | api_checkstackindex(L, errfunc, o); | 911 | api_checkstackindex(errfunc, o); |
| 958 | func = savestack(L, o); | 912 | func = savestack(L, o); |
| 959 | } | 913 | } |
| 960 | c.func = L->top - (nargs+1); /* function to be called */ | 914 | c.func = L->top - (nargs+1); /* function to be called */ |
| @@ -999,7 +953,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, · 38 unmodified lines | |||
| 999 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | 953 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); |
| 1000 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ | 954 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
| 1001 | setobj(L, f->upvals[0]->v, gt); | 955 | setobj(L, f->upvals[0]->v, gt); |
| 1002 | luaC_barrier(L, f->upvals[0], gt); | 956 | luaC_upvalbarrier(L, f->upvals[0]); |
| 1003 | } | 957 | } |
| 1004 | } | 958 | } |
| 1005 | lua_unlock(L); | 959 | lua_unlock(L); |
| @@ -1062,7 +1016,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { · 56 unmodified lines | |||
| 1062 | case LUA_GCSTEP: { | 1016 | case LUA_GCSTEP: { |
| 1063 | l_mem debt = 1; /* =1 to signal that it did an actual step */ | 1017 | l_mem debt = 1; /* =1 to signal that it did an actual step */ |
| 1064 | int oldrunning = g->gcrunning; | 1018 | int oldrunning = g->gcrunning; |
| 1065 | g->gcrunning = 1; /* force GC to run */ | 1019 | g->gcrunning = 1; /* allow GC to run */ |
| 1066 | if (data == 0) { | 1020 | if (data == 0) { |
| 1067 | luaE_setdebt(g, -GCSTEPSIZE); /* to do a "small" step */ | 1021 | luaE_setdebt(g, -GCSTEPSIZE); /* to do a "small" step */ |
| 1068 | luaC_step(L); | 1022 | luaC_step(L); |
| @@ -1119,7 +1073,7 @@ LUA_API int lua_next (lua_State *L, int idx) { · 50 unmodified lines | |||
| 1119 | int more; | 1073 | int more; |
| 1120 | lua_lock(L); | 1074 | lua_lock(L); |
| 1121 | t = index2addr(L, idx); | 1075 | t = index2addr(L, idx); |
| 1122 | api_check(L, ttistable(t), "table expected"); | 1076 | api_check(ttistable(t), "table expected"); |
| 1123 | more = luaH_next(L, hvalue(t), L->top - 1); | 1077 | more = luaH_next(L, hvalue(t), L->top - 1); |
| 1124 | if (more) { | 1078 | if (more) { |
| 1125 | api_incr_top(L); | 1079 | api_incr_top(L); |
| @@ -1183,19 +1137,19 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) { · 57 unmodified lines | |||
| 1183 | setuvalue(L, L->top, u); | 1137 | setuvalue(L, L->top, u); |
| 1184 | api_incr_top(L); | 1138 | api_incr_top(L); |
| 1185 | lua_unlock(L); | 1139 | lua_unlock(L); |
| 1186 | return u + 1; | 1140 | return getudatamem(u); |
| 1187 | } | 1141 | } |
| 1188 | 1142 | ||
| 1189 | 1143 | ||
| 1190 | 1144 | ||
| 1191 | static const char *aux_upvalue (StkId fi, int n, TValue **val, | 1145 | static const char *aux_upvalue (StkId fi, int n, TValue **val, |
| 1192 | GCObject **owner, UpVal **uv) { | 1146 | CClosure **owner, UpVal **uv) { |
| 1193 | switch (ttype(fi)) { | 1147 | switch (ttype(fi)) { |
| 1194 | case LUA_TCCL: { /* C closure */ | 1148 | case LUA_TCCL: { /* C closure */ |
| 1195 | CClosure *f = clCvalue(fi); | 1149 | CClosure *f = clCvalue(fi); |
| 1196 | if (!(1 <= n && n <= f->nupvalues)) return NULL; | 1150 | if (!(1 <= n && n <= f->nupvalues)) return NULL; |
| 1197 | *val = &f->upvalue[n-1]; | 1151 | *val = &f->upvalue[n-1]; |
| 1198 | if (owner) *owner = obj2gco(f); | 1152 | if (owner) *owner = f; |
| 1199 | return ""; | 1153 | return ""; |
| 1200 | } | 1154 | } |
| 1201 | case LUA_TLCL: { /* Lua closure */ | 1155 | case LUA_TLCL: { /* Lua closure */ |
| @@ -1230,7 +1184,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) { · 28 unmodified lines | |||
| 1230 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { | 1184 | LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { |
| 1231 | const char *name; | 1185 | const char *name; |
| 1232 | TValue *val = NULL; /* to avoid warnings */ | 1186 | TValue *val = NULL; /* to avoid warnings */ |
| 1233 | GCObject *owner = NULL; | 1187 | CClosure *owner = NULL; |
| 1234 | UpVal *uv = NULL; | 1188 | UpVal *uv = NULL; |
| 1235 | StkId fi; | 1189 | StkId fi; |
| 1236 | lua_lock(L); | 1190 | lua_lock(L); |
| @@ -1251,9 +1205,9 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) { · 14 unmodified lines | |||
| 1251 | static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { | 1205 | static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { |
| 1252 | LClosure *f; | 1206 | LClosure *f; |
| 1253 | StkId fi = index2addr(L, fidx); | 1207 | StkId fi = index2addr(L, fidx); |
| 1254 | api_check(L, ttisLclosure(fi), "Lua function expected"); | 1208 | api_check(ttisLclosure(fi), "Lua function expected"); |
| 1255 | f = clLvalue(fi); | 1209 | f = clLvalue(fi); |
| 1256 | api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); | 1210 | api_check((1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index"); |
| 1257 | if (pf) *pf = f; | 1211 | if (pf) *pf = f; |
| 1258 | return &f->upvals[n - 1]; /* get its upvalue pointer */ | 1212 | return &f->upvals[n - 1]; /* get its upvalue pointer */ |
| 1259 | } | 1213 | } |
| @@ -1267,11 +1221,11 @@ LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { · 7 unmodified lines | |||
| 1267 | } | 1221 | } |
| 1268 | case LUA_TCCL: { /* C closure */ | 1222 | case LUA_TCCL: { /* C closure */ |
| 1269 | CClosure *f = clCvalue(fi); | 1223 | CClosure *f = clCvalue(fi); |
| 1270 | api_check(L, 1 <= n && n <= f->nupvalues, "invalid upvalue index"); | 1224 | api_check(1 <= n && n <= f->nupvalues, "invalid upvalue index"); |
| 1271 | return &f->upvalue[n - 1]; | 1225 | return &f->upvalue[n - 1]; |
| 1272 | } | 1226 | } |
| 1273 | default: { | 1227 | default: { |
| 1274 | api_check(L, 0, "closure expected"); | 1228 | api_check(0, "closure expected"); |
| 1275 | return NULL; | 1229 | return NULL; |
| 1276 | } | 1230 | } |
| 1277 | } | 1231 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.h,v 2.7 2009/11/27 15:37:59 roberto Exp $ | 2 | ** $Id: lapi.h,v 2.8 2014/07/15 21:26:50 roberto Exp $ |
| 3 | ** Auxiliary functions from Lua API | 3 | ** Auxiliary functions from Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -11,13 +11,13 @@ · 5 unmodified lines | |||
| 11 | #include "llimits.h" | 11 | #include "llimits.h" |
| 12 | #include "lstate.h" | 12 | #include "lstate.h" |
| 13 | 13 | ||
| 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ | 14 | #define api_incr_top(L) {L->top++; api_check(L->top <= L->ci->top, \ |
| 15 | "stack overflow");} | 15 | "stack overflow");} |
| 16 | 16 | ||
| 17 | #define adjustresults(L,nres) \ | 17 | #define adjustresults(L,nres) \ |
| 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } | 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } |
| 19 | 19 | ||
| 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ | 20 | #define api_checknelems(L,n) api_check((n) < (L->top - L->ci->func), \ |
| 21 | "not enough elements in the stack") | 21 | "not enough elements in the stack") |
| 22 | 22 | ||
| 23 | 23 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.263 2014/05/12 21:44:17 roberto Exp $ | 2 | ** $Id: lauxlib.c,v 1.267 2014/07/19 14:37:09 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 | */ |
| @@ -396,8 +396,8 @@ LUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def) { · 390 unmodified lines | |||
| 396 | 396 | ||
| 397 | 397 | ||
| 398 | static void interror (lua_State *L, int arg) { | 398 | static void interror (lua_State *L, int arg) { |
| 399 | if (lua_type(L, arg) == LUA_TNUMBER) | 399 | if (lua_isnumber(L, arg)) |
| 400 | luaL_argerror(L, arg, "float value out of integer range"); | 400 | luaL_argerror(L, arg, "number has no integer representation"); |
| 401 | else | 401 | else |
| 402 | tag_error(L, arg, LUA_TNUMBER); | 402 | tag_error(L, arg, LUA_TNUMBER); |
| 403 | } | 403 | } |
| @@ -413,26 +413,11 @@ LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) { · 9 unmodified lines | |||
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | 415 | ||
| 416 | LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int arg) { | ||
| 417 | int isnum; | ||
| 418 | lua_Unsigned d = lua_tounsignedx(L, arg, &isnum); | ||
| 419 | if (!isnum) | ||
| 420 | interror(L, arg); | ||
| 421 | return d; | ||
| 422 | } | ||
| 423 | |||
| 424 | |||
| 425 | LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg, | 416 | LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg, |
| 426 | lua_Integer def) { | 417 | lua_Integer def) { |
| 427 | return luaL_opt(L, luaL_checkinteger, arg, def); | 418 | return luaL_opt(L, luaL_checkinteger, arg, def); |
| 428 | } | 419 | } |
| 429 | 420 | ||
| 430 | |||
| 431 | LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int arg, | ||
| 432 | lua_Unsigned def) { | ||
| 433 | return luaL_opt(L, luaL_checkunsigned, arg, def); | ||
| 434 | } | ||
| 435 | |||
| 436 | /* }====================================================== */ | 421 | /* }====================================================== */ |
| 437 | 422 | ||
| 438 | 423 | ||
| @@ -898,22 +883,26 @@ LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) { · 459 unmodified lines | |||
| 898 | 883 | ||
| 899 | 884 | ||
| 900 | /* | 885 | /* |
| 901 | ** stripped-down 'require'. Calls 'openf' to open a module, | 886 | ** Stripped-down 'require': After checking "loaded" table, calls 'openf' |
| 902 | ** registers the result in 'package.loaded' table and, if 'glb' | 887 | ** to open a module, registers the result in 'package.loaded' table and, |
| 903 | ** is true, also registers the result in the global table. | 888 | ** if 'glb' is true, also registers the result in the global table. |
| 904 | ** Leaves resulting module on the top. | 889 | ** Leaves resulting module on the top. |
| 905 | */ | 890 | */ |
| 906 | LUALIB_API void luaL_requiref (lua_State *L, const char *modname, | 891 | LUALIB_API void luaL_requiref (lua_State *L, const char *modname, |
| 907 | lua_CFunction openf, int glb) { | 892 | lua_CFunction openf, int glb) { |
| 908 | lua_pushcfunction(L, openf); | ||
| 909 | lua_pushstring(L, modname); /* argument to open function */ | ||
| 910 | lua_call(L, 1, 1); /* open module */ | ||
| 911 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); | 893 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); |
| 912 | lua_pushvalue(L, -2); /* make copy of module (call result) */ | 894 | lua_getfield(L, -1, modname); /* _LOADED[modname] */ |
| 913 | lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ | 895 | if (!lua_toboolean(L, -1)) { /* package not already loaded? */ |
| 914 | lua_pop(L, 1); /* remove _LOADED table */ | 896 | lua_pop(L, 1); /* remove field */ |
| 897 | lua_pushcfunction(L, openf); | ||
| 898 | lua_pushstring(L, modname); /* argument to open function */ | ||
| 899 | lua_call(L, 1, 1); /* call 'openf' to open module */ | ||
| 900 | lua_pushvalue(L, -1); /* make copy of module (call result) */ | ||
| 901 | lua_setfield(L, -3, modname); /* _LOADED[modname] = module */ | ||
| 902 | } | ||
| 903 | lua_remove(L, -2); /* remove _LOADED table */ | ||
| 915 | if (glb) { | 904 | if (glb) { |
| 916 | lua_pushvalue(L, -1); /* copy of 'mod' */ | 905 | lua_pushvalue(L, -1); /* copy of module */ |
| 917 | lua_setglobal(L, modname); /* _G[modname] = module */ | 906 | lua_setglobal(L, modname); /* _G[modname] = module */ |
| 918 | } | 907 | } |
| 919 | } | 908 | } |
| @@ -963,13 +952,12 @@ LUALIB_API lua_State *luaL_newstate (void) { · 43 unmodified lines | |||
| 963 | 952 | ||
| 964 | LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) { | 953 | LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) { |
| 965 | const lua_Number *v = lua_version(L); | 954 | const lua_Number *v = lua_version(L); |
| 955 | if (sz != LUAL_NUMSIZES) /* check numeric types */ | ||
| 956 | luaL_error(L, "core and library have incompatible numeric types"); | ||
| 966 | if (v != lua_version(NULL)) | 957 | if (v != lua_version(NULL)) |
| 967 | luaL_error(L, "multiple Lua VMs detected"); | 958 | luaL_error(L, "multiple Lua VMs detected"); |
| 968 | else if (*v != ver) | 959 | else if (*v != ver) |
| 969 | luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", | 960 | luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", |
| 970 | ver, *v); | 961 | ver, *v); |
| 971 | /* check numeric types */ | ||
| 972 | if (sz != LUAL_NUMSIZES) | ||
| 973 | luaL_error(L, "core and library have incompatible numeric types"); | ||
| 974 | } | 962 | } |
| 975 | 963 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.124 2014/04/15 18:25:49 roberto Exp $ | 2 | ** $Id: lauxlib.h,v 1.125 2014/06/26 17:25:11 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 | */ |
| @@ -46,9 +46,6 @@ LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def); · 40 unmodified lines | |||
| 46 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg); | 46 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg); |
| 47 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg, | 47 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg, |
| 48 | lua_Integer def); | 48 | lua_Integer def); |
| 49 | LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int arg); | ||
| 50 | LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int arg, | ||
| 51 | lua_Unsigned def); | ||
| 52 | 49 | ||
| 53 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); | 50 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); |
| 54 | LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t); | 51 | LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t); |
| @@ -211,6 +208,22 @@ LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, · 156 unmodified lines | |||
| 211 | #endif | 208 | #endif |
| 212 | 209 | ||
| 213 | 210 | ||
| 211 | /* | ||
| 212 | ** {============================================================ | ||
| 213 | ** Compatibility with deprecated unsigned conversions | ||
| 214 | ** ============================================================= | ||
| 215 | */ | ||
| 216 | #if defined(LUA_COMPAT_APIUNSIGNED) | ||
| 217 | |||
| 218 | #define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a)) | ||
| 219 | #define luaL_optunsigned(L,a,d) \ | ||
| 220 | ((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d))) | ||
| 221 | |||
| 222 | #endif | ||
| 223 | /* }============================================================ */ | ||
| 224 | |||
| 225 | |||
| 226 | |||
| 214 | #endif | 227 | #endif |
| 215 | 228 | ||
| 216 | 229 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.289 2014/06/10 17:41:38 roberto Exp $ | 2 | ** $Id: lbaselib.c,v 1.293 2014/07/24 19:33:29 roberto Exp $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -200,9 +200,12 @@ static int luaB_collectgarbage (lua_State *L) { · 194 unmodified lines | |||
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | 202 | ||
| 203 | /* | ||
| 204 | ** This function has all type names as upvalues, to maximize performance. | ||
| 205 | */ | ||
| 203 | static int luaB_type (lua_State *L) { | 206 | static int luaB_type (lua_State *L) { |
| 204 | luaL_checkany(L, 1); | 207 | luaL_checkany(L, 1); |
| 205 | lua_pushstring(L, luaL_typename(L, 1)); | 208 | lua_pushvalue(L, lua_upvalueindex(lua_type(L, 1) + 1)); |
| 206 | return 1; | 209 | return 1; |
| 207 | } | 210 | } |
| 208 | 211 | ||
| @@ -241,17 +244,53 @@ static int luaB_pairs (lua_State *L) { · 32 unmodified lines | |||
| 241 | } | 244 | } |
| 242 | 245 | ||
| 243 | 246 | ||
| 244 | static int ipairsaux (lua_State *L) { | 247 | /* |
| 245 | int i = luaL_checkint(L, 2); | 248 | ** Traversal function for 'ipairs' for raw tables |
| 249 | */ | ||
| 250 | static int ipairsaux_raw (lua_State *L) { | ||
| 251 | int i = luaL_checkint(L, 2) + 1; | ||
| 246 | luaL_checktype(L, 1, LUA_TTABLE); | 252 | luaL_checktype(L, 1, LUA_TTABLE); |
| 247 | i++; /* next value */ | ||
| 248 | lua_pushinteger(L, i); | 253 | lua_pushinteger(L, i); |
| 249 | return (lua_rawgeti(L, 1, i) == LUA_TNIL) ? 1 : 2; | 254 | return (lua_rawgeti(L, 1, i) == LUA_TNIL) ? 1 : 2; |
| 250 | } | 255 | } |
| 251 | 256 | ||
| 252 | 257 | ||
| 258 | /* | ||
| 259 | ** Traversal function for 'ipairs' for tables with metamethods | ||
| 260 | */ | ||
| 261 | static int ipairsaux (lua_State *L) { | ||
| 262 | int i = luaL_checkint(L, 2) + 1; | ||
| 263 | if (i > luaL_len(L, 1)) { /* larger than length? */ | ||
| 264 | lua_pushnil(L); /* end traversal */ | ||
| 265 | return 1; | ||
| 266 | } | ||
| 267 | else { | ||
| 268 | lua_pushinteger(L, i); | ||
| 269 | lua_pushinteger(L, i); /* key for indexing table */ | ||
| 270 | lua_gettable(L, 1); | ||
| 271 | return 2; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | |||
| 275 | |||
| 276 | /* | ||
| 277 | ** This function will use either 'ipairsaux' or 'ipairsaux_raw' to | ||
| 278 | ** traverse a table, depending on whether the table has metamethods | ||
| 279 | ** that can affect the traversal. | ||
| 280 | */ | ||
| 253 | static int luaB_ipairs (lua_State *L) { | 281 | static int luaB_ipairs (lua_State *L) { |
| 254 | return pairsmeta(L, "__ipairs", 1, ipairsaux); | 282 | lua_CFunction iter = |
| 283 | (luaL_getmetafield(L, 1, "__len") || | ||
| 284 | luaL_getmetafield(L, 1, "__index")) | ||
| 285 | ? ipairsaux : ipairsaux_raw; | ||
| 286 | #if defined(LUA_COMPAT_IPAIRS) | ||
| 287 | return pairsmeta(L, "__ipairs", 1, iter); | ||
| 288 | #else | ||
| 289 | lua_pushcfunction(L, iter); /* iteration function */ | ||
| 290 | lua_pushvalue(L, 1); /* state */ | ||
| 291 | lua_pushinteger(L, 0); /* initial value */ | ||
| 292 | return 3; | ||
| 293 | #endif | ||
| 255 | } | 294 | } |
| 256 | 295 | ||
| 257 | 296 | ||
| @@ -341,7 +380,7 @@ static int luaB_load (lua_State *L) { · 83 unmodified lines | |||
| 341 | /* }====================================================== */ | 380 | /* }====================================================== */ |
| 342 | 381 | ||
| 343 | 382 | ||
| 344 | static int dofilecont (lua_State *L, int d1, int d2) { | 383 | static int dofilecont (lua_State *L, int d1, lua_Ctx d2) { |
| 345 | (void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */ | 384 | (void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */ |
| 346 | return lua_gettop(L) - 1; | 385 | return lua_gettop(L) - 1; |
| 347 | } | 386 | } |
| @@ -387,12 +426,12 @@ static int luaB_select (lua_State *L) { · 39 unmodified lines | |||
| 387 | 426 | ||
| 388 | /* | 427 | /* |
| 389 | ** Continuation function for 'pcall' and 'xpcall'. Both functions | 428 | ** Continuation function for 'pcall' and 'xpcall'. Both functions |
| 390 | ** already pushed a 'true' before doing the call, so in case of sucess | 429 | ** already pushed a 'true' before doing the call, so in case of success |
| 391 | ** 'finishpcall' only has to return everything in the stack minus | 430 | ** 'finishpcall' only has to return everything in the stack minus |
| 392 | ** 'extra' values (where 'extra' is exactly the number of items to be | 431 | ** 'extra' values (where 'extra' is exactly the number of items to be |
| 393 | ** ignored). | 432 | ** ignored). |
| 394 | */ | 433 | */ |
| 395 | static int finishpcall (lua_State *L, int status, int extra) { | 434 | static int finishpcall (lua_State *L, int status, lua_Ctx extra) { |
| 396 | if (status != LUA_OK && status != LUA_YIELD) { /* error? */ | 435 | if (status != LUA_OK && status != LUA_YIELD) { /* error? */ |
| 397 | lua_pushboolean(L, 0); /* first result (false) */ | 436 | lua_pushboolean(L, 0); /* first result (false) */ |
| 398 | lua_pushvalue(L, -2); /* error message */ | 437 | lua_pushvalue(L, -2); /* error message */ |
| @@ -461,21 +500,31 @@ static const luaL_Reg base_funcs[] = { · 62 unmodified lines | |||
| 461 | {"setmetatable", luaB_setmetatable}, | 500 | {"setmetatable", luaB_setmetatable}, |
| 462 | {"tonumber", luaB_tonumber}, | 501 | {"tonumber", luaB_tonumber}, |
| 463 | {"tostring", luaB_tostring}, | 502 | {"tostring", luaB_tostring}, |
| 464 | {"type", luaB_type}, | ||
| 465 | {"xpcall", luaB_xpcall}, | 503 | {"xpcall", luaB_xpcall}, |
| 504 | /* placeholders */ | ||
| 505 | {"type", NULL}, | ||
| 506 | {"_G", NULL}, | ||
| 507 | {"_VERSION", NULL}, | ||
| 466 | {NULL, NULL} | 508 | {NULL, NULL} |
| 467 | }; | 509 | }; |
| 468 | 510 | ||
| 469 | 511 | ||
| 470 | LUAMOD_API int luaopen_base (lua_State *L) { | 512 | LUAMOD_API int luaopen_base (lua_State *L) { |
| 471 | /* set global _G */ | 513 | int i; |
| 472 | lua_pushglobaltable(L); | ||
| 473 | lua_pushglobaltable(L); | ||
| 474 | lua_setfield(L, -2, "_G"); | ||
| 475 | /* open lib into global table */ | 514 | /* open lib into global table */ |
| 515 | lua_pushglobaltable(L); | ||
| 476 | luaL_setfuncs(L, base_funcs, 0); | 516 | luaL_setfuncs(L, base_funcs, 0); |
| 517 | /* set global _G */ | ||
| 518 | lua_pushvalue(L, -1); | ||
| 519 | lua_setfield(L, -2, "_G"); | ||
| 520 | /* set global _VERSION */ | ||
| 477 | lua_pushliteral(L, LUA_VERSION); | 521 | lua_pushliteral(L, LUA_VERSION); |
| 478 | lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */ | 522 | lua_setfield(L, -2, "_VERSION"); |
| 523 | /* set function 'type' with proper upvalues */ | ||
| 524 | for (i = 0; i < LUA_NUMTAGS; i++) /* push all type names as upvalues */ | ||
| 525 | lua_pushstring(L, lua_typename(L, i)); | ||
| 526 | lua_pushcclosure(L, luaB_type, LUA_NUMTAGS); | ||
| 527 | lua_setfield(L, -2, "type"); | ||
| 479 | return 1; | 528 | return 1; |
| 480 | } | 529 | } |
| 481 | 530 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.97 2013/12/09 14:21:10 roberto Exp $ | 2 | ** $Id: ldebug.c,v 2.100 2014/07/30 14:00:14 roberto Exp $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -271,7 +271,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { · 265 unmodified lines | |||
| 271 | if (*what == '>') { | 271 | if (*what == '>') { |
| 272 | ci = NULL; | 272 | ci = NULL; |
| 273 | func = L->top - 1; | 273 | func = L->top - 1; |
| 274 | api_check(L, ttisfunction(func), "function expected"); | 274 | api_check(ttisfunction(func), "function expected"); |
| 275 | what++; /* skip the '>' */ | 275 | what++; /* skip the '>' */ |
| 276 | L->top--; /* pop function */ | 276 | L->top--; /* pop function */ |
| 277 | } | 277 | } |
| @@ -526,26 +526,27 @@ l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) { · 248 unmodified lines | |||
| 526 | 526 | ||
| 527 | 527 | ||
| 528 | l_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) { | 528 | l_noret luaG_concaterror (lua_State *L, const TValue *p1, const TValue *p2) { |
| 529 | if (ttisstring(p1) || ttisnumber(p1)) p1 = p2; | 529 | if (ttisstring(p1) || cvt2str(p1)) p1 = p2; |
| 530 | lua_assert(!ttisstring(p1) && !ttisnumber(p1)); | ||
| 531 | luaG_typeerror(L, p1, "concatenate"); | 530 | luaG_typeerror(L, p1, "concatenate"); |
| 532 | } | 531 | } |
| 533 | 532 | ||
| 534 | 533 | ||
| 535 | l_noret luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { | 534 | l_noret luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) { |
| 536 | lua_Number temp; | 535 | lua_Number temp; |
| 537 | if (!tonumber(p1, &temp)) | 536 | if (!tonumber(p1, &temp)) /* first operand is wrong? */ |
| 538 | p2 = p1; /* first operand is wrong */ | 537 | p2 = p1; /* now second is wrong */ |
| 539 | luaG_typeerror(L, p2, "perform arithmetic on"); | 538 | luaG_typeerror(L, p2, "perform arithmetic on"); |
| 540 | } | 539 | } |
| 541 | 540 | ||
| 542 | 541 | ||
| 542 | /* | ||
| 543 | ** Error when both values are convertible to numbers, but not to integers | ||
| 544 | */ | ||
| 543 | l_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) { | 545 | l_noret luaG_tointerror (lua_State *L, const TValue *p1, const TValue *p2) { |
| 544 | lua_Integer temp; | 546 | lua_Integer temp; |
| 545 | if (!tointeger(p1, &temp)) | 547 | if (!tointeger(p1, &temp)) |
| 546 | p2 = p1; | 548 | p2 = p1; |
| 547 | luaG_runerror(L, "attempt to convert an out of range float%s to an integer", | 549 | luaG_runerror(L, "number%s has no integer representation", varinfo(L, p2)); |
| 548 | varinfo(L, p2)); | ||
| 549 | } | 550 | } |
| 550 | 551 | ||
| 551 | 552 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.123 2014/06/19 18:27:20 roberto Exp $ | 2 | ** $Id: ldo.c,v 2.126 2014/07/17 13:53:37 roberto Exp $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -516,7 +516,7 @@ static l_noret resume_error (lua_State *L, const char *msg, StkId firstArg) { · 510 unmodified lines | |||
| 516 | /* | 516 | /* |
| 517 | ** Do the work for 'lua_resume' in protected mode. Most of the work | 517 | ** Do the work for 'lua_resume' in protected mode. Most of the work |
| 518 | ** depends on the status of the coroutine: initial state, suspended | 518 | ** depends on the status of the coroutine: initial state, suspended |
| 519 | ** inside a hook, or regulary suspended (optionally with a continuation | 519 | ** inside a hook, or regularly suspended (optionally with a continuation |
| 520 | ** function), plus erroneous cases: non-suspended coroutine or dead | 520 | ** function), plus erroneous cases: non-suspended coroutine or dead |
| 521 | ** coroutine. | 521 | ** coroutine. |
| 522 | */ | 522 | */ |
| @@ -593,7 +593,8 @@ LUA_API int lua_isyieldable (lua_State *L) { · 70 unmodified lines | |||
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | 595 | ||
| 596 | LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_KFunction k) { | 596 | LUA_API int lua_yieldk (lua_State *L, int nresults, lua_Ctx ctx, |
| 597 | lua_KFunction k) { | ||
| 597 | CallInfo *ci = L->ci; | 598 | CallInfo *ci = L->ci; |
| 598 | luai_userstateyield(L, nresults); | 599 | luai_userstateyield(L, nresults); |
| 599 | lua_lock(L); | 600 | lua_lock(L); |
| @@ -607,7 +608,7 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_KFunction k) { · 7 unmodified lines | |||
| 607 | L->status = LUA_YIELD; | 608 | L->status = LUA_YIELD; |
| 608 | ci->extra = savestack(L, ci->func); /* save current 'func' */ | 609 | ci->extra = savestack(L, ci->func); /* save current 'func' */ |
| 609 | if (isLua(ci)) { /* inside a hook? */ | 610 | if (isLua(ci)) { /* inside a hook? */ |
| 610 | api_check(L, k == NULL, "hooks cannot continue after yielding"); | 611 | api_check(k == NULL, "hooks cannot continue after yielding"); |
| 611 | } | 612 | } |
| 612 | else { | 613 | else { |
| 613 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ | 614 | if ((ci->u.c.k = k) != NULL) /* is there a continuation? */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldump.c,v 2.32 2014/06/18 18:35:43 roberto Exp $ | 2 | ** $Id: ldump.c,v 2.33 2014/07/18 13:36:14 roberto Exp $ |
| 3 | ** save precompiled Lua chunks | 3 | ** save precompiled Lua chunks |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -71,7 +71,7 @@ static void DumpString (const TString *s, DumpState *D) { · 65 unmodified lines | |||
| 71 | if (s == NULL) | 71 | if (s == NULL) |
| 72 | DumpByte(0, D); | 72 | DumpByte(0, D); |
| 73 | else { | 73 | else { |
| 74 | size_t size = s->tsv.len + 1; /* include trailing '\0' */ | 74 | size_t size = s->len + 1; /* include trailing '\0' */ |
| 75 | if (size < 0xFF) | 75 | if (size < 0xFF) |
| 76 | DumpByte(cast_int(size), D); | 76 | DumpByte(cast_int(size), D); |
| 77 | else { | 77 | else { |
| @@ -112,7 +112,7 @@ static void DumpConstants (const Proto *f, DumpState *D) { · 34 unmodified lines | |||
| 112 | break; | 112 | break; |
| 113 | case LUA_TSHRSTR: | 113 | case LUA_TSHRSTR: |
| 114 | case LUA_TLNGSTR: | 114 | case LUA_TLNGSTR: |
| 115 | DumpString(rawtsvalue(o), D); | 115 | DumpString(tsvalue(o), D); |
| 116 | break; | 116 | break; |
| 117 | default: | 117 | default: |
| 118 | lua_assert(0); | 118 | lua_assert(0); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.183 2014/05/25 19:08:32 roberto Exp $ | 2 | ** $Id: lgc.c,v 2.192 2014/07/29 16:22:24 roberto Exp $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -62,10 +62,10 @@ · 56 unmodified lines | |||
| 62 | */ | 62 | */ |
| 63 | #define maskcolors (~(bitmask(BLACKBIT) | WHITEBITS)) | 63 | #define maskcolors (~(bitmask(BLACKBIT) | WHITEBITS)) |
| 64 | #define makewhite(g,x) \ | 64 | #define makewhite(g,x) \ |
| 65 | (gch(x)->marked = cast_byte((gch(x)->marked & maskcolors) | luaC_white(g))) | 65 | (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g))) |
| 66 | 66 | ||
| 67 | #define white2gray(x) resetbits(gch(x)->marked, WHITEBITS) | 67 | #define white2gray(x) resetbits(x->marked, WHITEBITS) |
| 68 | #define black2gray(x) resetbit(gch(x)->marked, BLACKBIT) | 68 | #define black2gray(x) resetbit(x->marked, BLACKBIT) |
| 69 | 69 | ||
| 70 | 70 | ||
| 71 | #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) | 71 | #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) |
| @@ -81,7 +81,7 @@ · 9 unmodified lines | |||
| 81 | if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); } | 81 | if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); } |
| 82 | 82 | ||
| 83 | #define markobject(g,t) \ | 83 | #define markobject(g,t) \ |
| 84 | { if ((t) && iswhite(obj2gco(t))) reallymarkobject(g, obj2gco(t)); } | 84 | { if ((t) && iswhite(t)) reallymarkobject(g, obj2gco(t)); } |
| 85 | 85 | ||
| 86 | static void reallymarkobject (global_State *g, GCObject *o); | 86 | static void reallymarkobject (global_State *g, GCObject *o); |
| 87 | 87 | ||
| @@ -112,7 +112,7 @@ static void reallymarkobject (global_State *g, GCObject *o); · 24 unmodified lines | |||
| 112 | static void removeentry (Node *n) { | 112 | static void removeentry (Node *n) { |
| 113 | lua_assert(ttisnil(gval(n))); | 113 | lua_assert(ttisnil(gval(n))); |
| 114 | if (valiswhite(gkey(n))) | 114 | if (valiswhite(gkey(n))) |
| 115 | setdeadvalue(gkey(n)); /* unused and unmarked key; remove it */ | 115 | setdeadvalue(wgkey(n)); /* unused and unmarked key; remove it */ |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | 118 | ||
| @@ -126,7 +126,7 @@ static void removeentry (Node *n) { · 7 unmodified lines | |||
| 126 | static int iscleared (global_State *g, const TValue *o) { | 126 | static int iscleared (global_State *g, const TValue *o) { |
| 127 | if (!iscollectable(o)) return 0; | 127 | if (!iscollectable(o)) return 0; |
| 128 | else if (ttisstring(o)) { | 128 | else if (ttisstring(o)) { |
| 129 | markobject(g, rawtsvalue(o)); /* strings are `values', so are never weak */ | 129 | markobject(g, tsvalue(o)); /* strings are `values', so are never weak */ |
| 130 | return 0; | 130 | return 0; |
| 131 | } | 131 | } |
| 132 | else return iswhite(gcvalue(o)); | 132 | else return iswhite(gcvalue(o)); |
| @@ -135,13 +135,13 @@ static int iscleared (global_State *g, const TValue *o) { · 2 unmodified lines | |||
| 135 | 135 | ||
| 136 | /* | 136 | /* |
| 137 | ** barrier that moves collector forward, that is, mark the white object | 137 | ** barrier that moves collector forward, that is, mark the white object |
| 138 | ** being pointed by a black object. | 138 | ** being pointed by a black object. (If in sweep phase, clear the black |
| 139 | ** object to white [sweep it] to avoid other barrier calls for this | ||
| 140 | ** same object.) | ||
| 139 | */ | 141 | */ |
| 140 | void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) { | 142 | void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) { |
| 141 | global_State *g = G(L); | 143 | global_State *g = G(L); |
| 142 | lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); | 144 | lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); |
| 143 | lua_assert(g->gcstate != GCSpause); | ||
| 144 | lua_assert(gch(o)->tt != LUA_TTABLE); /* tables use a back barrier */ | ||
| 145 | if (keepinvariant(g)) /* must keep invariant? */ | 145 | if (keepinvariant(g)) /* must keep invariant? */ |
| 146 | reallymarkobject(g, v); /* restore invariant */ | 146 | reallymarkobject(g, v); /* restore invariant */ |
| 147 | else { /* sweep phase */ | 147 | else { /* sweep phase */ |
| @@ -153,16 +153,14 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) { · 5 unmodified lines | |||
| 153 | 153 | ||
| 154 | /* | 154 | /* |
| 155 | ** barrier that moves collector backward, that is, mark the black object | 155 | ** barrier that moves collector backward, that is, mark the black object |
| 156 | ** pointing to a white object as gray again. (Current implementation | 156 | ** pointing to a white object as gray again. |
| 157 | ** only works for tables; access to 'gclist' is not uniform across | ||
| 158 | ** different types.) | ||
| 159 | */ | 157 | */ |
| 160 | void luaC_barrierback_ (lua_State *L, GCObject *o) { | 158 | void luaC_barrierback_ (lua_State *L, Table *t) { |
| 161 | global_State *g = G(L); | 159 | global_State *g = G(L); |
| 162 | lua_assert(isblack(o) && !isdead(g, o) && gch(o)->tt == LUA_TTABLE); | 160 | lua_assert(isblack(t) && !isdead(g, t)); |
| 163 | black2gray(o); /* make object gray (again) */ | 161 | black2gray(t); /* make table gray (again) */ |
| 164 | gco2t(o)->gclist = g->grayagain; | 162 | t->gclist = g->grayagain; |
| 165 | g->grayagain = o; | 163 | g->grayagain = obj2gco(t); |
| 166 | } | 164 | } |
| 167 | 165 | ||
| 168 | 166 | ||
| @@ -185,8 +183,8 @@ void luaC_fix (lua_State *L, GCObject *o) { · 16 unmodified lines | |||
| 185 | global_State *g = G(L); | 183 | global_State *g = G(L); |
| 186 | lua_assert(g->allgc == o); /* object must be 1st in 'allgc' list! */ | 184 | lua_assert(g->allgc == o); /* object must be 1st in 'allgc' list! */ |
| 187 | white2gray(o); /* they will be gray forever */ | 185 | white2gray(o); /* they will be gray forever */ |
| 188 | g->allgc = o->gch.next; /* remove object from 'allgc' list */ | 186 | g->allgc = o->next; /* remove object from 'allgc' list */ |
| 189 | o->gch.next = g->fixedgc; /* link it to 'fixedgc' list */ | 187 | o->next = g->fixedgc; /* link it to 'fixedgc' list */ |
| 190 | g->fixedgc = o; | 188 | g->fixedgc = o; |
| 191 | } | 189 | } |
| 192 | 190 | ||
| @@ -198,9 +196,9 @@ void luaC_fix (lua_State *L, GCObject *o) { · 5 unmodified lines | |||
| 198 | GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) { | 196 | GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) { |
| 199 | global_State *g = G(L); | 197 | global_State *g = G(L); |
| 200 | GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz)); | 198 | GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz)); |
| 201 | gch(o)->marked = luaC_white(g); | 199 | o->marked = luaC_white(g); |
| 202 | gch(o)->tt = tt; | 200 | o->tt = tt; |
| 203 | gch(o)->next = g->allgc; | 201 | o->next = g->allgc; |
| 204 | g->allgc = o; | 202 | g->allgc = o; |
| 205 | return o; | 203 | return o; |
| 206 | } | 204 | } |
| @@ -225,7 +223,7 @@ GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) { · 18 unmodified lines | |||
| 225 | static void reallymarkobject (global_State *g, GCObject *o) { | 223 | static void reallymarkobject (global_State *g, GCObject *o) { |
| 226 | reentry: | 224 | reentry: |
| 227 | white2gray(o); | 225 | white2gray(o); |
| 228 | switch (gch(o)->tt) { | 226 | switch (o->tt) { |
| 229 | case LUA_TSHRSTR: | 227 | case LUA_TSHRSTR: |
| 230 | case LUA_TLNGSTR: { | 228 | case LUA_TLNGSTR: { |
| 231 | gray2black(o); | 229 | gray2black(o); |
| @@ -237,7 +235,7 @@ static void reallymarkobject (global_State *g, GCObject *o) { · 5 unmodified lines | |||
| 237 | markobject(g, gco2u(o)->metatable); /* mark its metatable */ | 235 | markobject(g, gco2u(o)->metatable); /* mark its metatable */ |
| 238 | gray2black(o); | 236 | gray2black(o); |
| 239 | g->GCmemtrav += sizeudata(gco2u(o)); | 237 | g->GCmemtrav += sizeudata(gco2u(o)); |
| 240 | getuservalue(g->mainthread, rawgco2u(o), &uvalue); | 238 | getuservalue(g->mainthread, gco2u(o), &uvalue); |
| 241 | if (valiswhite(&uvalue)) { /* markvalue(g, &uvalue); */ | 239 | if (valiswhite(&uvalue)) { /* markvalue(g, &uvalue); */ |
| 242 | o = gcvalue(&uvalue); | 240 | o = gcvalue(&uvalue); |
| 243 | goto reentry; | 241 | goto reentry; |
| @@ -288,7 +286,7 @@ static void markmt (global_State *g) { · 44 unmodified lines | |||
| 288 | */ | 286 | */ |
| 289 | static void markbeingfnz (global_State *g) { | 287 | static void markbeingfnz (global_State *g) { |
| 290 | GCObject *o; | 288 | GCObject *o; |
| 291 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) | 289 | for (o = g->tobefnz; o != NULL; o = o->next) |
| 292 | markobject(g, o); | 290 | markobject(g, o); |
| 293 | } | 291 | } |
| 294 | 292 | ||
| @@ -303,8 +301,8 @@ static void remarkupvals (global_State *g) { · 8 unmodified lines | |||
| 303 | lua_State *thread; | 301 | lua_State *thread; |
| 304 | lua_State **p = &g->twups; | 302 | lua_State **p = &g->twups; |
| 305 | while ((thread = *p) != NULL) { | 303 | while ((thread = *p) != NULL) { |
| 306 | lua_assert(!isblack(obj2gco(thread))); /* threads are never black */ | 304 | lua_assert(!isblack(thread)); /* threads are never black */ |
| 307 | if (isgray(obj2gco(thread)) && thread->openupval != NULL) | 305 | if (isgray(thread) && thread->openupval != NULL) |
| 308 | p = &thread->twups; /* keep marked thread with upvalues in the list */ | 306 | p = &thread->twups; /* keep marked thread with upvalues in the list */ |
| 309 | else { /* thread is not marked or without upvalues */ | 307 | else { /* thread is not marked or without upvalues */ |
| 310 | UpVal *uv; | 308 | UpVal *uv; |
| @@ -429,7 +427,7 @@ static lu_mem traversetable (global_State *g, Table *h) { · 118 unmodified lines | |||
| 429 | ((weakkey = strchr(svalue(mode), 'k')), | 427 | ((weakkey = strchr(svalue(mode), 'k')), |
| 430 | (weakvalue = strchr(svalue(mode), 'v')), | 428 | (weakvalue = strchr(svalue(mode), 'v')), |
| 431 | (weakkey || weakvalue))) { /* is really weak? */ | 429 | (weakkey || weakvalue))) { /* is really weak? */ |
| 432 | black2gray(obj2gco(h)); /* keep table gray */ | 430 | black2gray(h); /* keep table gray */ |
| 433 | if (!weakkey) /* strong keys? */ | 431 | if (!weakkey) /* strong keys? */ |
| 434 | traverseweakvalue(g, h); | 432 | traverseweakvalue(g, h); |
| 435 | else if (!weakvalue) /* strong values? */ | 433 | else if (!weakvalue) /* strong values? */ |
| @@ -446,7 +444,7 @@ static lu_mem traversetable (global_State *g, Table *h) { · 10 unmodified lines | |||
| 446 | 444 | ||
| 447 | static int traverseproto (global_State *g, Proto *f) { | 445 | static int traverseproto (global_State *g, Proto *f) { |
| 448 | int i; | 446 | int i; |
| 449 | if (f->cache && iswhite(obj2gco(f->cache))) | 447 | if (f->cache && iswhite(f->cache)) |
| 450 | f->cache = NULL; /* allow cache to be collected */ | 448 | f->cache = NULL; /* allow cache to be collected */ |
| 451 | markobject(g, f->source); | 449 | markobject(g, f->source); |
| 452 | for (i = 0; i < f->sizek; i++) /* mark literals */ | 450 | for (i = 0; i < f->sizek; i++) /* mark literals */ |
| @@ -528,7 +526,7 @@ static void propagatemark (global_State *g) { · 75 unmodified lines | |||
| 528 | GCObject *o = g->gray; | 526 | GCObject *o = g->gray; |
| 529 | lua_assert(isgray(o)); | 527 | lua_assert(isgray(o)); |
| 530 | gray2black(o); | 528 | gray2black(o); |
| 531 | switch (gch(o)->tt) { | 529 | switch (o->tt) { |
| 532 | case LUA_TTABLE: { | 530 | case LUA_TTABLE: { |
| 533 | Table *h = gco2t(o); | 531 | Table *h = gco2t(o); |
| 534 | g->gray = h->gclist; /* remove from 'gray' list */ | 532 | g->gray = h->gclist; /* remove from 'gray' list */ |
| @@ -685,7 +683,7 @@ static void freeLclosure (lua_State *L, LClosure *cl) { · 150 unmodified lines | |||
| 685 | 683 | ||
| 686 | 684 | ||
| 687 | static void freeobj (lua_State *L, GCObject *o) { | 685 | static void freeobj (lua_State *L, GCObject *o) { |
| 688 | switch (gch(o)->tt) { | 686 | switch (o->tt) { |
| 689 | case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; | 687 | case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; |
| 690 | case LUA_TLCL: { | 688 | case LUA_TLCL: { |
| 691 | freeLclosure(L, gco2lcl(o)); | 689 | freeLclosure(L, gco2lcl(o)); |
| @@ -699,7 +697,7 @@ static void freeobj (lua_State *L, GCObject *o) { · 7 unmodified lines | |||
| 699 | case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break; | 697 | case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break; |
| 700 | case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break; | 698 | case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break; |
| 701 | case LUA_TSHRSTR: | 699 | case LUA_TSHRSTR: |
| 702 | luaS_remove(L, rawgco2ts(o)); /* remove it from hash table */ | 700 | luaS_remove(L, gco2ts(o)); /* remove it from hash table */ |
| 703 | /* go through */ | 701 | /* go through */ |
| 704 | case LUA_TLNGSTR: { | 702 | case LUA_TLNGSTR: { |
| 705 | luaM_freemem(L, o, sizestring(gco2ts(o))); | 703 | luaM_freemem(L, o, sizestring(gco2ts(o))); |
| @@ -727,14 +725,14 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { · 21 unmodified lines | |||
| 727 | int white = luaC_white(g); /* current white */ | 725 | int white = luaC_white(g); /* current white */ |
| 728 | while (*p != NULL && count-- > 0) { | 726 | while (*p != NULL && count-- > 0) { |
| 729 | GCObject *curr = *p; | 727 | GCObject *curr = *p; |
| 730 | int marked = gch(curr)->marked; | 728 | int marked = curr->marked; |
| 731 | if (isdeadm(ow, marked)) { /* is 'curr' dead? */ | 729 | if (isdeadm(ow, marked)) { /* is 'curr' dead? */ |
| 732 | *p = gch(curr)->next; /* remove 'curr' from list */ | 730 | *p = curr->next; /* remove 'curr' from list */ |
| 733 | freeobj(L, curr); /* erase 'curr' */ | 731 | freeobj(L, curr); /* erase 'curr' */ |
| 734 | } | 732 | } |
| 735 | else { /* update marks */ | 733 | else { /* update marks */ |
| 736 | gch(curr)->marked = cast_byte((marked & maskcolors) | white); | 734 | curr->marked = cast_byte((marked & maskcolors) | white); |
| 737 | p = &gch(curr)->next; /* go to next element */ | 735 | p = &curr->next; /* go to next element */ |
| 738 | } | 736 | } |
| 739 | } | 737 | } |
| 740 | return (*p == NULL) ? NULL : p; | 738 | return (*p == NULL) ? NULL : p; |
| @@ -781,10 +779,10 @@ static void checkSizes (lua_State *L, global_State *g) { · 40 unmodified lines | |||
| 781 | static GCObject *udata2finalize (global_State *g) { | 779 | static GCObject *udata2finalize (global_State *g) { |
| 782 | GCObject *o = g->tobefnz; /* get first element */ | 780 | GCObject *o = g->tobefnz; /* get first element */ |
| 783 | lua_assert(tofinalize(o)); | 781 | lua_assert(tofinalize(o)); |
| 784 | g->tobefnz = gch(o)->next; /* remove it from 'tobefnz' list */ | 782 | g->tobefnz = o->next; /* remove it from 'tobefnz' list */ |
| 785 | gch(o)->next = g->allgc; /* return it to 'allgc' list */ | 783 | o->next = g->allgc; /* return it to 'allgc' list */ |
| 786 | g->allgc = o; | 784 | g->allgc = o; |
| 787 | resetbit(gch(o)->marked, FINALIZEDBIT); /* object is "normal" again */ | 785 | resetbit(o->marked, FINALIZEDBIT); /* object is "normal" again */ |
| 788 | if (issweepphase(g)) | 786 | if (issweepphase(g)) |
| 789 | makewhite(g, o); /* "sweep" object */ | 787 | makewhite(g, o); /* "sweep" object */ |
| 790 | return o; | 788 | return o; |
| @@ -859,7 +857,7 @@ static void callallpendingfinalizers (lua_State *L, int propagateerrors) { · 68 unmodified lines | |||
| 859 | */ | 857 | */ |
| 860 | static GCObject **findlast (GCObject **p) { | 858 | static GCObject **findlast (GCObject **p) { |
| 861 | while (*p != NULL) | 859 | while (*p != NULL) |
| 862 | p = &gch(*p)->next; | 860 | p = &(*p)->next; |
| 863 | return p; | 861 | return p; |
| 864 | } | 862 | } |
| 865 | 863 | ||
| @@ -875,12 +873,12 @@ static void separatetobefnz (global_State *g, int all) { · 9 unmodified lines | |||
| 875 | while ((curr = *p) != NULL) { /* traverse all finalizable objects */ | 873 | while ((curr = *p) != NULL) { /* traverse all finalizable objects */ |
| 876 | lua_assert(tofinalize(curr)); | 874 | lua_assert(tofinalize(curr)); |
| 877 | if (!(iswhite(curr) || all)) /* not being collected? */ | 875 | if (!(iswhite(curr) || all)) /* not being collected? */ |
| 878 | p = &gch(curr)->next; /* don't bother with it */ | 876 | p = &curr->next; /* don't bother with it */ |
| 879 | else { | 877 | else { |
| 880 | *p = gch(curr)->next; /* remove 'curr' from "fin" list */ | 878 | *p = curr->next; /* remove 'curr' from "fin" list */ |
| 881 | gch(curr)->next = *lastnext; /* link at the end of 'tobefnz' list */ | 879 | curr->next = *lastnext; /* link at the end of 'tobefnz' list */ |
| 882 | *lastnext = curr; | 880 | *lastnext = curr; |
| 883 | lastnext = &gch(curr)->next; | 881 | lastnext = &curr->next; |
| 884 | } | 882 | } |
| 885 | } | 883 | } |
| 886 | } | 884 | } |
| @@ -899,15 +897,15 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { · 12 unmodified lines | |||
| 899 | GCObject **p; | 897 | GCObject **p; |
| 900 | if (issweepphase(g)) { | 898 | if (issweepphase(g)) { |
| 901 | makewhite(g, o); /* "sweep" object 'o' */ | 899 | makewhite(g, o); /* "sweep" object 'o' */ |
| 902 | if (g->sweepgc == &o->gch.next) /* shoud not remove 'sweepgc' object */ | 900 | if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */ |
| 903 | g->sweepgc = sweeptolive(L, g->sweepgc, NULL); /* change 'sweepgc' */ | 901 | g->sweepgc = sweeptolive(L, g->sweepgc, NULL); /* change 'sweepgc' */ |
| 904 | } | 902 | } |
| 905 | /* search for pointer pointing to 'o' */ | 903 | /* search for pointer pointing to 'o' */ |
| 906 | for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ } | 904 | for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ } |
| 907 | *p = o->gch.next; /* remove 'o' from 'allgc' list */ | 905 | *p = o->next; /* remove 'o' from 'allgc' list */ |
| 908 | o->gch.next = g->finobj; /* link it in "fin" list */ | 906 | o->next = g->finobj; /* link it in "fin" list */ |
| 909 | g->finobj = o; | 907 | g->finobj = o; |
| 910 | l_setbit(o->gch.marked, FINALIZEDBIT); /* mark it as such */ | 908 | l_setbit(o->marked, FINALIZEDBIT); /* mark it as such */ |
| 911 | } | 909 | } |
| 912 | } | 910 | } |
| 913 | 911 | ||
| @@ -975,7 +973,7 @@ static l_mem atomic (lua_State *L) { · 61 unmodified lines | |||
| 975 | l_mem work; | 973 | l_mem work; |
| 976 | GCObject *origweak, *origall; | 974 | GCObject *origweak, *origall; |
| 977 | g->GCmemtrav = 0; /* start counting work */ | 975 | g->GCmemtrav = 0; /* start counting work */ |
| 978 | lua_assert(!iswhite(obj2gco(g->mainthread))); | 976 | lua_assert(!iswhite(g->mainthread)); |
| 979 | g->gcstate = GCSinsideatomic; | 977 | g->gcstate = GCSinsideatomic; |
| 980 | markobject(g, L); /* mark running thread */ | 978 | markobject(g, L); /* mark running thread */ |
| 981 | /* registry and global metatables may be changed by API */ | 979 | /* registry and global metatables may be changed by API */ |
| @@ -1066,7 +1064,7 @@ static lu_mem singlestep (lua_State *L) { · 84 unmodified lines | |||
| 1066 | return sweepstep(L, g, GCSswpend, NULL); | 1064 | return sweepstep(L, g, GCSswpend, NULL); |
| 1067 | } | 1065 | } |
| 1068 | case GCSswpend: { /* finish sweeps */ | 1066 | case GCSswpend: { /* finish sweeps */ |
| 1069 | makewhite(g, obj2gco(g->mainthread)); /* sweep main thread */ | 1067 | makewhite(g, g->mainthread); /* sweep main thread */ |
| 1070 | checkSizes(L, g); | 1068 | checkSizes(L, g); |
| 1071 | g->gcstate = GCScallfin; | 1069 | g->gcstate = GCScallfin; |
| 1072 | return 0; | 1070 | return 0; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.h,v 2.82 2014/03/19 18:51:16 roberto Exp $ | 2 | ** $Id: lgc.h,v 2.85 2014/07/19 15:14:46 roberto Exp $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -84,19 +84,19 @@ · 78 unmodified lines | |||
| 84 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) | 84 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) |
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | #define iswhite(x) testbits((x)->gch.marked, WHITEBITS) | 87 | #define iswhite(x) testbits((x)->marked, WHITEBITS) |
| 88 | #define isblack(x) testbit((x)->gch.marked, BLACKBIT) | 88 | #define isblack(x) testbit((x)->marked, BLACKBIT) |
| 89 | #define isgray(x) /* neither white nor black */ \ | 89 | #define isgray(x) /* neither white nor black */ \ |
| 90 | (!testbits((x)->gch.marked, WHITEBITS | bitmask(BLACKBIT))) | 90 | (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT))) |
| 91 | 91 | ||
| 92 | #define tofinalize(x) testbit((x)->gch.marked, FINALIZEDBIT) | 92 | #define tofinalize(x) testbit((x)->marked, FINALIZEDBIT) |
| 93 | 93 | ||
| 94 | #define otherwhite(g) ((g)->currentwhite ^ WHITEBITS) | 94 | #define otherwhite(g) ((g)->currentwhite ^ WHITEBITS) |
| 95 | #define isdeadm(ow,m) (!(((m) ^ WHITEBITS) & (ow))) | 95 | #define isdeadm(ow,m) (!(((m) ^ WHITEBITS) & (ow))) |
| 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->gch.marked) | 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->marked) |
| 97 | 97 | ||
| 98 | #define changewhite(x) ((x)->gch.marked ^= WHITEBITS) | 98 | #define changewhite(x) ((x)->marked ^= WHITEBITS) |
| 99 | #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) | 99 | #define gray2black(x) l_setbit((x)->marked, BLACKBIT) |
| 100 | 100 | ||
| 101 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) | 101 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) |
| 102 | 102 | ||
| @@ -107,15 +107,15 @@ · 4 unmodified lines | |||
| 107 | 107 | ||
| 108 | 108 | ||
| 109 | #define luaC_barrier(L,p,v) { \ | 109 | #define luaC_barrier(L,p,v) { \ |
| 110 | if (iscollectable(v) && isblack(obj2gco(p)) && iswhite(gcvalue(v))) \ | 110 | if (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) \ |
| 111 | luaC_barrier_(L,obj2gco(p),gcvalue(v)); } | 111 | luaC_barrier_(L,obj2gco(p),gcvalue(v)); } |
| 112 | 112 | ||
| 113 | #define luaC_barrierback(L,p,v) { \ | 113 | #define luaC_barrierback(L,p,v) { \ |
| 114 | if (iscollectable(v) && isblack(obj2gco(p)) && iswhite(gcvalue(v))) \ | 114 | if (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) \ |
| 115 | luaC_barrierback_(L,obj2gco(p)); } | 115 | luaC_barrierback_(L,p); } |
| 116 | 116 | ||
| 117 | #define luaC_objbarrier(L,p,o) { \ | 117 | #define luaC_objbarrier(L,p,o) { \ |
| 118 | if (isblack(obj2gco(p)) && iswhite(obj2gco(o))) \ | 118 | if (isblack(p) && iswhite(o)) \ |
| 119 | luaC_barrier_(L,obj2gco(p),obj2gco(o)); } | 119 | luaC_barrier_(L,obj2gco(p),obj2gco(o)); } |
| 120 | 120 | ||
| 121 | #define luaC_upvalbarrier(L,uv) \ | 121 | #define luaC_upvalbarrier(L,uv) \ |
| @@ -129,7 +129,7 @@ LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); · 7 unmodified lines | |||
| 129 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); | 129 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); |
| 130 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); | 130 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); |
| 131 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); | 131 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); |
| 132 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); | 132 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o); |
| 133 | LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); | 133 | LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); |
| 134 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); | 134 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); |
| 135 | LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); | 135 | LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 2.126 2014/06/02 03:00:51 roberto Exp $ | 2 | ** $Id: liolib.c,v 2.128 2014/07/29 16:01:00 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 | */ |
| @@ -402,11 +402,11 @@ static int test2 (RN *rn, const char *set) { · 396 unmodified lines | |||
| 402 | 402 | ||
| 403 | 403 | ||
| 404 | /* | 404 | /* |
| 405 | ** Read a sequence of (hexa)digits | 405 | ** Read a sequence of (hex)digits |
| 406 | */ | 406 | */ |
| 407 | static int readdigits (RN *rn, int hexa) { | 407 | static int readdigits (RN *rn, int hex) { |
| 408 | int count = 0; | 408 | int count = 0; |
| 409 | while ((hexa ? isxdigit(rn->c) : isdigit(rn->c)) && nextc(rn)) | 409 | while ((hex ? isxdigit(rn->c) : isdigit(rn->c)) && nextc(rn)) |
| 410 | count++; | 410 | count++; |
| 411 | return count; | 411 | return count; |
| 412 | } | 412 | } |
| @@ -426,7 +426,7 @@ static int readdigits (RN *rn, int hexa) { · 13 unmodified lines | |||
| 426 | static int read_number (lua_State *L, FILE *f) { | 426 | static int read_number (lua_State *L, FILE *f) { |
| 427 | RN rn; | 427 | RN rn; |
| 428 | int count = 0; | 428 | int count = 0; |
| 429 | int hexa = 0; | 429 | int hex = 0; |
| 430 | char decp[2] = "."; | 430 | char decp[2] = "."; |
| 431 | rn.f = f; rn.n = 0; | 431 | rn.f = f; rn.n = 0; |
| 432 | decp[0] = getlocaledecpoint(); /* get decimal point from locale */ | 432 | decp[0] = getlocaledecpoint(); /* get decimal point from locale */ |
| @@ -434,13 +434,13 @@ static int read_number (lua_State *L, FILE *f) { · 1 unmodified line | |||
| 434 | do { rn.c = l_getc(rn.f); } while (isspace(rn.c)); /* skip spaces */ | 434 | do { rn.c = l_getc(rn.f); } while (isspace(rn.c)); /* skip spaces */ |
| 435 | test2(&rn, "-+"); /* optional signal */ | 435 | test2(&rn, "-+"); /* optional signal */ |
| 436 | if (test2(&rn, "0")) { | 436 | if (test2(&rn, "0")) { |
| 437 | if (test2(&rn, "xX")) hexa = 1; /* numeral is hexadecimal */ | 437 | if (test2(&rn, "xX")) hex = 1; /* numeral is hexadecimal */ |
| 438 | else count = 1; /* count initial '0' as a valid digit */ | 438 | else count = 1; /* count initial '0' as a valid digit */ |
| 439 | } | 439 | } |
| 440 | count += readdigits(&rn, hexa); /* integral part */ | 440 | count += readdigits(&rn, hex); /* integral part */ |
| 441 | if (test2(&rn, decp)) /* decimal point? */ | 441 | if (test2(&rn, decp)) /* decimal point? */ |
| 442 | count += readdigits(&rn, hexa); /* fractionary part */ | 442 | count += readdigits(&rn, hex); /* fractional part */ |
| 443 | if (count > 0 && test2(&rn, (hexa ? "pP" : "eE"))) { /* exponent mark? */ | 443 | if (count > 0 && test2(&rn, (hex ? "pP" : "eE"))) { /* exponent mark? */ |
| 444 | test2(&rn, "-+"); /* exponent signal */ | 444 | test2(&rn, "-+"); /* exponent signal */ |
| 445 | readdigits(&rn, 0); /* exponent digits */ | 445 | readdigits(&rn, 0); /* exponent digits */ |
| 446 | } | 446 | } |
| @@ -654,7 +654,7 @@ static int f_setvbuf (lua_State *L) { · 207 unmodified lines | |||
| 654 | FILE *f = tofile(L); | 654 | FILE *f = tofile(L); |
| 655 | int op = luaL_checkoption(L, 2, NULL, modenames); | 655 | int op = luaL_checkoption(L, 2, NULL, modenames); |
| 656 | lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); | 656 | lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); |
| 657 | int res = setvbuf(f, NULL, mode[op], sz); | 657 | int res = setvbuf(f, NULL, mode[op], (size_t)sz); |
| 658 | return luaL_fileresult(L, res == 0, NULL); | 658 | return luaL_fileresult(L, res == 0, NULL); |
| 659 | } | 659 | } |
| 660 | 660 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 2.78 2014/05/21 15:22:02 roberto Exp $ | 2 | ** $Id: llex.c,v 2.80 2014/07/18 13:36:14 roberto Exp $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -71,7 +71,7 @@ void luaX_init (lua_State *L) { · 65 unmodified lines | |||
| 71 | for (i=0; i<NUM_RESERVED; i++) { | 71 | for (i=0; i<NUM_RESERVED; i++) { |
| 72 | TString *ts = luaS_new(L, luaX_tokens[i]); | 72 | TString *ts = luaS_new(L, luaX_tokens[i]); |
| 73 | luaC_fix(L, obj2gco(ts)); /* reserved words are never collected */ | 73 | luaC_fix(L, obj2gco(ts)); /* reserved words are never collected */ |
| 74 | ts->tsv.extra = cast_byte(i+1); /* reserved word */ | 74 | ts->extra = cast_byte(i+1); /* reserved word */ |
| 75 | } | 75 | } |
| 76 | } | 76 | } |
| 77 | 77 | ||
| @@ -137,7 +137,7 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) { · 59 unmodified lines | |||
| 137 | luaC_checkGC(L); | 137 | luaC_checkGC(L); |
| 138 | } | 138 | } |
| 139 | else { /* string already present */ | 139 | else { /* string already present */ |
| 140 | ts = rawtsvalue(keyfromval(o)); /* re-use value previously stored */ | 140 | ts = tsvalue(keyfromval(o)); /* re-use value previously stored */ |
| 141 | } | 141 | } |
| 142 | L->top--; /* remove string from stack */ | 142 | L->top--; /* remove string from stack */ |
| 143 | return ts; | 143 | return ts; |
| @@ -565,7 +565,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { · 421 unmodified lines | |||
| 565 | luaZ_bufflen(ls->buff)); | 565 | luaZ_bufflen(ls->buff)); |
| 566 | seminfo->ts = ts; | 566 | seminfo->ts = ts; |
| 567 | if (isreserved(ts)) /* reserved word? */ | 567 | if (isreserved(ts)) /* reserved word? */ |
| 568 | return ts->tsv.extra - 1 + FIRST_RESERVED; | 568 | return ts->extra - 1 + FIRST_RESERVED; |
| 569 | else { | 569 | else { |
| 570 | return TK_NAME; | 570 | return TK_NAME; |
| 571 | } | 571 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.116 2014/04/15 16:32:49 roberto Exp $ | 2 | ** $Id: llimits.h,v 1.120 2014/07/18 18:29:12 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 | */ |
| @@ -28,36 +28,37 @@ typedef unsigned char lu_byte; · 22 unmodified lines | |||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | /* maximum value for size_t */ | 30 | /* maximum value for size_t */ |
| 31 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) | 31 | #define MAX_SIZET ((size_t)(~(size_t)0)) |
| 32 | 32 | ||
| 33 | /* maximum size visible for Lua (must be representable in a lua_Integer */ | 33 | /* maximum size visible for Lua (must be representable in a lua_Integer */ |
| 34 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ | 34 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ |
| 35 | : (size_t)(LUA_MAXINTEGER)-2) | 35 | : (size_t)(LUA_MAXINTEGER)) |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) | 38 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)) |
| 39 | 39 | ||
| 40 | #define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2)) | 40 | #define MAX_LMEM ((l_mem)(MAX_LUMEM >> 1)) |
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ | 43 | #define MAX_INT INT_MAX /* maximum value of an int */ |
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | /* | 46 | /* |
| 47 | ** conversion of pointer to integer | 47 | ** conversion of pointer to integer: |
| 48 | ** this is for hashing only; there is no problem if the integer | 48 | ** this is for hashing only; there is no problem if the integer |
| 49 | ** cannot hold the whole pointer value | 49 | ** cannot hold the whole pointer value |
| 50 | */ | 50 | */ |
| 51 | #define IntPoint(p) ((unsigned int)(lu_mem)(p)) | 51 | #define point2int(p) ((unsigned int)((lu_mem)(p) & UINT_MAX)) |
| 52 | 52 | ||
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | /* type to ensure maximum alignment */ | 55 | /* type to ensure maximum alignment */ |
| 56 | #if !defined(LUAI_USER_ALIGNMENT_T) | 56 | #if defined(LUAI_USER_ALIGNMENT_T) |
| 57 | #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } | 57 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; |
| 58 | #else | ||
| 59 | typedef union { double u; void *s; lua_Integer i; long l; } L_Umaxalign; | ||
| 58 | #endif | 60 | #endif |
| 59 | 61 | ||
| 60 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; | ||
| 61 | 62 | ||
| 62 | 63 | ||
| 63 | /* types of 'usual argument conversions' for lua_Number and lua_Integer */ | 64 | /* types of 'usual argument conversions' for lua_Number and lua_Integer */ |
| @@ -79,18 +80,15 @@ typedef LUAI_UACINT l_uacInt; · 15 unmodified lines | |||
| 79 | /* | 80 | /* |
| 80 | ** assertion for checking API calls | 81 | ** assertion for checking API calls |
| 81 | */ | 82 | */ |
| 82 | #if !defined(luai_apicheck) | ||
| 83 | |||
| 84 | #if defined(LUA_USE_APICHECK) | 83 | #if defined(LUA_USE_APICHECK) |
| 85 | #include <assert.h> | 84 | #include <assert.h> |
| 86 | #define luai_apicheck(L,e) assert(e) | 85 | #define luai_apicheck(e) assert(e) |
| 87 | #else | 86 | #else |
| 88 | #define luai_apicheck(L,e) lua_assert(e) | 87 | #define luai_apicheck(e) lua_assert(e) |
| 89 | #endif | 88 | #endif |
| 90 | 89 | ||
| 91 | #endif | ||
| 92 | 90 | ||
| 93 | #define api_check(l,e,msg) luai_apicheck(l,(e) && msg) | 91 | #define api_check(e,msg) luai_apicheck((e) && msg) |
| 94 | 92 | ||
| 95 | 93 | ||
| 96 | #if !defined(UNUSED) | 94 | #if !defined(UNUSED) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.103 2014/06/18 12:35:53 roberto Exp $ | 2 | ** $Id: lmathlib.c,v 1.108 2014/07/28 17:35:47 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 | */ |
| @@ -76,39 +76,39 @@ static int math_atan (lua_State *L) { · 70 unmodified lines | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | 78 | ||
| 79 | static int math_ifloor (lua_State *L) { | 79 | static int math_toint (lua_State *L) { |
| 80 | int valid; | 80 | int valid; |
| 81 | lua_Integer n = lua_tointegerx(L, 1, &valid); | 81 | lua_Integer n = lua_tointegerx(L, 1, &valid); |
| 82 | if (valid) | 82 | if (valid) |
| 83 | lua_pushinteger(L, n); /* floor computed by Lua */ | 83 | lua_pushinteger(L, n); |
| 84 | else { | 84 | else { |
| 85 | luaL_checktype(L, 1, LUA_TNUMBER); /* argument must be a number */ | 85 | luaL_checkany(L, 1); |
| 86 | lua_pushnil(L); /* number is not convertible to integer */ | 86 | lua_pushnil(L); /* value is not convertible to integer */ |
| 87 | } | 87 | } |
| 88 | return 1; | 88 | return 1; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | 91 | ||
| 92 | static int math_floor (lua_State *L) { | ||
| 93 | int valid; | ||
| 94 | lua_Integer n = lua_tointegerx(L, 1, &valid); | ||
| 95 | if (valid) | ||
| 96 | lua_pushinteger(L, n); /* floor computed by Lua */ | ||
| 97 | else | ||
| 98 | lua_pushnumber(L, l_mathop(floor)(luaL_checknumber(L, 1))); | ||
| 99 | return 1; | ||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | static void pushnumint (lua_State *L, lua_Number d) { | 92 | static void pushnumint (lua_State *L, lua_Number d) { |
| 104 | lua_Integer n; | 93 | lua_Integer n; |
| 105 | if (lua_numtointeger(d, &n)) /* fits in an integer? */ | 94 | if (lua_numtointeger(d, &n)) /* does 'd' fit in an integer? */ |
| 106 | lua_pushinteger(L, n); /* result is integer */ | 95 | lua_pushinteger(L, n); /* result is integer */ |
| 107 | else | 96 | else |
| 108 | lua_pushnumber(L, d); /* result is float */ | 97 | lua_pushnumber(L, d); /* result is float */ |
| 109 | } | 98 | } |
| 110 | 99 | ||
| 111 | 100 | ||
| 101 | static int math_floor (lua_State *L) { | ||
| 102 | if (lua_isinteger(L, 1)) | ||
| 103 | lua_settop(L, 1); /* integer is its own floor */ | ||
| 104 | else { | ||
| 105 | lua_Number d = l_mathop(floor)(luaL_checknumber(L, 1)); | ||
| 106 | pushnumint(L, d); | ||
| 107 | } | ||
| 108 | return 1; | ||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | static int math_ceil (lua_State *L) { | 112 | static int math_ceil (lua_State *L) { |
| 113 | if (lua_isinteger(L, 1)) | 113 | if (lua_isinteger(L, 1)) |
| 114 | lua_settop(L, 1); /* integer is its own ceil */ | 114 | lua_settop(L, 1); /* integer is its own ceil */ |
| @@ -145,14 +145,14 @@ static int math_fmod (lua_State *L) { · 30 unmodified lines | |||
| 145 | static int math_modf (lua_State *L) { | 145 | static int math_modf (lua_State *L) { |
| 146 | if (lua_isinteger(L ,1)) { | 146 | if (lua_isinteger(L ,1)) { |
| 147 | lua_settop(L, 1); /* number is its own integer part */ | 147 | lua_settop(L, 1); /* number is its own integer part */ |
| 148 | lua_pushnumber(L, 0); /* no fractionary part */ | 148 | lua_pushnumber(L, 0); /* no fractional part */ |
| 149 | } | 149 | } |
| 150 | else { | 150 | else { |
| 151 | lua_Number n = luaL_checknumber(L, 1); | 151 | lua_Number n = luaL_checknumber(L, 1); |
| 152 | /* integer part (rounds toward zero) */ | 152 | /* integer part (rounds toward zero) */ |
| 153 | lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n); | 153 | lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n); |
| 154 | pushnumint(L, ip); | 154 | pushnumint(L, ip); |
| 155 | /* fractionary part (test needed for inf/-inf) */ | 155 | /* fractional part (test needed for inf/-inf) */ |
| 156 | lua_pushnumber(L, (n == ip) ? 0.0 : (n - ip)); | 156 | lua_pushnumber(L, (n == ip) ? 0.0 : (n - ip)); |
| 157 | } | 157 | } |
| 158 | return 2; | 158 | return 2; |
| @@ -164,6 +164,14 @@ static int math_sqrt (lua_State *L) { · 5 unmodified lines | |||
| 164 | return 1; | 164 | return 1; |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | |||
| 168 | static int math_ult (lua_State *L) { | ||
| 169 | lua_Integer a = luaL_checkinteger(L, 1); | ||
| 170 | lua_Integer b = luaL_checkinteger(L, 2); | ||
| 171 | lua_pushboolean(L, (lua_Unsigned)a < (lua_Unsigned)b); | ||
| 172 | return 1; | ||
| 173 | } | ||
| 174 | |||
| 167 | static int math_log (lua_State *L) { | 175 | static int math_log (lua_State *L) { |
| 168 | lua_Number x = luaL_checknumber(L, 1); | 176 | lua_Number x = luaL_checknumber(L, 1); |
| 169 | lua_Number res; | 177 | lua_Number res; |
| @@ -257,22 +265,23 @@ static int math_random (lua_State *L) { · 87 unmodified lines | |||
| 257 | 265 | ||
| 258 | 266 | ||
| 259 | static int math_randomseed (lua_State *L) { | 267 | static int math_randomseed (lua_State *L) { |
| 260 | l_srand((unsigned int)luaL_checkunsigned(L, 1)); | 268 | l_srand((unsigned int)(lua_Integer)luaL_checknumber(L, 1)); |
| 261 | (void)rand(); /* discard first value to avoid undesirable correlations */ | 269 | (void)rand(); /* discard first value to avoid undesirable correlations */ |
| 262 | return 0; | 270 | return 0; |
| 263 | } | 271 | } |
| 264 | 272 | ||
| 265 | 273 | ||
| 266 | static int math_type (lua_State *L) { | 274 | static int math_type (lua_State *L) { |
| 267 | luaL_checkany(L, 1); | ||
| 268 | if (lua_type(L, 1) == LUA_TNUMBER) { | 275 | if (lua_type(L, 1) == LUA_TNUMBER) { |
| 269 | if (lua_isinteger(L, 1)) | 276 | if (lua_isinteger(L, 1)) |
| 270 | lua_pushliteral(L, "integer"); | 277 | lua_pushliteral(L, "integer"); |
| 271 | else | 278 | else |
| 272 | lua_pushliteral(L, "float"); | 279 | lua_pushliteral(L, "float"); |
| 273 | } | 280 | } |
| 274 | else | 281 | else { |
| 282 | luaL_checkany(L, 1); | ||
| 275 | lua_pushnil(L); | 283 | lua_pushnil(L); |
| 284 | } | ||
| 276 | return 1; | 285 | return 1; |
| 277 | } | 286 | } |
| 278 | 287 | ||
| @@ -339,9 +348,10 @@ static const luaL_Reg mathlib[] = { · 60 unmodified lines | |||
| 339 | {"cos", math_cos}, | 348 | {"cos", math_cos}, |
| 340 | {"deg", math_deg}, | 349 | {"deg", math_deg}, |
| 341 | {"exp", math_exp}, | 350 | {"exp", math_exp}, |
| 342 | {"ifloor", math_ifloor}, | 351 | {"tointeger", math_toint}, |
| 343 | {"floor", math_floor}, | 352 | {"floor", math_floor}, |
| 344 | {"fmod", math_fmod}, | 353 | {"fmod", math_fmod}, |
| 354 | {"ult", math_ult}, | ||
| 345 | {"log", math_log}, | 355 | {"log", math_log}, |
| 346 | {"max", math_max}, | 356 | {"max", math_max}, |
| 347 | {"min", math_min}, | 357 | {"min", math_min}, |
| @@ -363,6 +373,11 @@ static const luaL_Reg mathlib[] = { · 15 unmodified lines | |||
| 363 | {"ldexp", math_ldexp}, | 373 | {"ldexp", math_ldexp}, |
| 364 | {"log10", math_log10}, | 374 | {"log10", math_log10}, |
| 365 | #endif | 375 | #endif |
| 376 | /* placeholders */ | ||
| 377 | {"pi", NULL}, | ||
| 378 | {"huge", NULL}, | ||
| 379 | {"maxinteger", NULL}, | ||
| 380 | {"mininteger", NULL}, | ||
| 366 | {NULL, NULL} | 381 | {NULL, NULL} |
| 367 | }; | 382 | }; |
| 368 | 383 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmem.c,v 1.84 2012/05/23 15:41:53 roberto Exp $ | 2 | ** $Id: lmem.c,v 1.86 2014/07/15 21:26:50 roberto Exp $ |
| 3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -83,12 +83,10 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { · 77 unmodified lines | |||
| 83 | #endif | 83 | #endif |
| 84 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); | 84 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); |
| 85 | if (newblock == NULL && nsize > 0) { | 85 | if (newblock == NULL && nsize > 0) { |
| 86 | api_check(L, nsize > realosize, | 86 | api_check( nsize > realosize, |
| 87 | "realloc cannot fail when shrinking a block"); | 87 | "realloc cannot fail when shrinking a block"); |
| 88 | if (g->gcrunning) { | 88 | luaC_fullgc(L, 1); /* try to free some memory... */ |
| 89 | luaC_fullgc(L, 1); /* try to free some memory... */ | 89 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ |
| 90 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ | ||
| 91 | } | ||
| 92 | if (newblock == NULL) | 90 | if (newblock == NULL) |
| 93 | luaD_throw(L, LUA_ERRMEM); | 91 | luaD_throw(L, LUA_ERRMEM); |
| 94 | } | 92 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.113 2014/03/12 20:57:40 roberto Exp $ | 2 | ** $Id: loadlib.c,v 1.116 2014/07/29 16:01:00 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 | ** |
| @@ -97,20 +97,33 @@ · 91 unmodified lines | |||
| 97 | 97 | ||
| 98 | #define LIB_FAIL "open" | 98 | #define LIB_FAIL "open" |
| 99 | 99 | ||
| 100 | |||
| 101 | /* error codes for ll_loadfunc */ | ||
| 102 | #define ERRLIB 1 | ||
| 103 | #define ERRFUNC 2 | ||
| 104 | |||
| 105 | #define setprogdir(L) ((void)0) | 100 | #define setprogdir(L) ((void)0) |
| 106 | 101 | ||
| 107 | 102 | ||
| 108 | /* | 103 | /* |
| 109 | ** system-dependent functions | 104 | ** system-dependent functions |
| 110 | */ | 105 | */ |
| 111 | static void ll_unloadlib (void *lib); | 106 | |
| 112 | static void *ll_load (lua_State *L, const char *path, int seeglb); | 107 | /* |
| 113 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); | 108 | ** unload library 'lib' |
| 109 | */ | ||
| 110 | static void lsys_unloadlib (void *lib); | ||
| 111 | |||
| 112 | /* | ||
| 113 | ** load C library in file 'path'. If 'seeglb', load with all names in | ||
| 114 | ** the library global. | ||
| 115 | ** Returns the library; in case of error, returns NULL plus an | ||
| 116 | ** error string in the stack. | ||
| 117 | */ | ||
| 118 | static void *lsys_load (lua_State *L, const char *path, int seeglb); | ||
| 119 | |||
| 120 | /* | ||
| 121 | ** Try to find a function named 'sym' in library 'lib'. | ||
| 122 | ** Returns the function; in case of error, returns NULL plus an | ||
| 123 | ** error string in the stack. | ||
| 124 | */ | ||
| 125 | static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym); | ||
| 126 | |||
| 114 | 127 | ||
| 115 | 128 | ||
| 116 | 129 | ||
| @@ -126,19 +139,19 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); · 9 unmodified lines | |||
| 126 | 139 | ||
| 127 | #include <dlfcn.h> | 140 | #include <dlfcn.h> |
| 128 | 141 | ||
| 129 | static void ll_unloadlib (void *lib) { | 142 | static void lsys_unloadlib (void *lib) { |
| 130 | dlclose(lib); | 143 | dlclose(lib); |
| 131 | } | 144 | } |
| 132 | 145 | ||
| 133 | 146 | ||
| 134 | static void *ll_load (lua_State *L, const char *path, int seeglb) { | 147 | static void *lsys_load (lua_State *L, const char *path, int seeglb) { |
| 135 | void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL)); | 148 | void *lib = dlopen(path, RTLD_NOW | (seeglb ? RTLD_GLOBAL : RTLD_LOCAL)); |
| 136 | if (lib == NULL) lua_pushstring(L, dlerror()); | 149 | if (lib == NULL) lua_pushstring(L, dlerror()); |
| 137 | return lib; | 150 | return lib; |
| 138 | } | 151 | } |
| 139 | 152 | ||
| 140 | 153 | ||
| 141 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | 154 | static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { |
| 142 | lua_CFunction f = (lua_CFunction)dlsym(lib, sym); | 155 | lua_CFunction f = (lua_CFunction)dlsym(lib, sym); |
| 143 | if (f == NULL) lua_pushstring(L, dlerror()); | 156 | if (f == NULL) lua_pushstring(L, dlerror()); |
| 144 | return f; | 157 | return f; |
| @@ -190,12 +203,12 @@ static void pusherror (lua_State *L) { · 45 unmodified lines | |||
| 190 | lua_pushfstring(L, "system error %d\n", error); | 203 | lua_pushfstring(L, "system error %d\n", error); |
| 191 | } | 204 | } |
| 192 | 205 | ||
| 193 | static void ll_unloadlib (void *lib) { | 206 | static void lsys_unloadlib (void *lib) { |
| 194 | FreeLibrary((HMODULE)lib); | 207 | FreeLibrary((HMODULE)lib); |
| 195 | } | 208 | } |
| 196 | 209 | ||
| 197 | 210 | ||
| 198 | static void *ll_load (lua_State *L, const char *path, int seeglb) { | 211 | static void *lsys_load (lua_State *L, const char *path, int seeglb) { |
| 199 | HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS); | 212 | HMODULE lib = LoadLibraryExA(path, NULL, LUA_LLE_FLAGS); |
| 200 | (void)(seeglb); /* not used: symbols are 'global' by default */ | 213 | (void)(seeglb); /* not used: symbols are 'global' by default */ |
| 201 | if (lib == NULL) pusherror(L); | 214 | if (lib == NULL) pusherror(L); |
| @@ -203,7 +216,7 @@ static void *ll_load (lua_State *L, const char *path, int seeglb) { · 1 unmodified line | |||
| 203 | } | 216 | } |
| 204 | 217 | ||
| 205 | 218 | ||
| 206 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | 219 | static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { |
| 207 | lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym); | 220 | lua_CFunction f = (lua_CFunction)GetProcAddress((HMODULE)lib, sym); |
| 208 | if (f == NULL) pusherror(L); | 221 | if (f == NULL) pusherror(L); |
| 209 | return f; | 222 | return f; |
| @@ -226,19 +239,19 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 16 unmodified lines | |||
| 226 | #define DLMSG "dynamic libraries not enabled; check your Lua installation" | 239 | #define DLMSG "dynamic libraries not enabled; check your Lua installation" |
| 227 | 240 | ||
| 228 | 241 | ||
| 229 | static void ll_unloadlib (void *lib) { | 242 | static void lsys_unloadlib (void *lib) { |
| 230 | (void)(lib); /* not used */ | 243 | (void)(lib); /* not used */ |
| 231 | } | 244 | } |
| 232 | 245 | ||
| 233 | 246 | ||
| 234 | static void *ll_load (lua_State *L, const char *path, int seeglb) { | 247 | static void *lsys_load (lua_State *L, const char *path, int seeglb) { |
| 235 | (void)(path); (void)(seeglb); /* not used */ | 248 | (void)(path); (void)(seeglb); /* not used */ |
| 236 | lua_pushliteral(L, DLMSG); | 249 | lua_pushliteral(L, DLMSG); |
| 237 | return NULL; | 250 | return NULL; |
| 238 | } | 251 | } |
| 239 | 252 | ||
| 240 | 253 | ||
| 241 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | 254 | static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { |
| 242 | (void)(lib); (void)(sym); /* not used */ | 255 | (void)(lib); (void)(sym); /* not used */ |
| 243 | lua_pushliteral(L, DLMSG); | 256 | lua_pushliteral(L, DLMSG); |
| 244 | return NULL; | 257 | return NULL; |
| @@ -248,7 +261,10 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { · 3 unmodified lines | |||
| 248 | #endif | 261 | #endif |
| 249 | 262 | ||
| 250 | 263 | ||
| 251 | static void *ll_checkclib (lua_State *L, const char *path) { | 264 | /* |
| 265 | ** return registry.CLIBS[path] | ||
| 266 | */ | ||
| 267 | static void *checkclib (lua_State *L, const char *path) { | ||
| 252 | void *plib; | 268 | void *plib; |
| 253 | lua_getfield(L, LUA_REGISTRYINDEX, CLIBS); | 269 | lua_getfield(L, LUA_REGISTRYINDEX, CLIBS); |
| 254 | lua_getfield(L, -1, path); | 270 | lua_getfield(L, -1, path); |
| @@ -258,7 +274,11 @@ static void *ll_checkclib (lua_State *L, const char *path) { · 3 unmodified lines | |||
| 258 | } | 274 | } |
| 259 | 275 | ||
| 260 | 276 | ||
| 261 | static void ll_addtoclib (lua_State *L, const char *path, void *plib) { | 277 | /* |
| 278 | ** registry.CLIBS[path] = plib -- for queries | ||
| 279 | ** registry.CLIBS[#CLIBS + 1] = plib -- also keep a list of all libraries | ||
| 280 | */ | ||
| 281 | static void addtoclib (lua_State *L, const char *path, void *plib) { | ||
| 262 | lua_getfield(L, LUA_REGISTRYINDEX, CLIBS); | 282 | lua_getfield(L, LUA_REGISTRYINDEX, CLIBS); |
| 263 | lua_pushlightuserdata(L, plib); | 283 | lua_pushlightuserdata(L, plib); |
| 264 | lua_pushvalue(L, -1); | 284 | lua_pushvalue(L, -1); |
| @@ -269,33 +289,49 @@ static void ll_addtoclib (lua_State *L, const char *path, void *plib) { · 4 unmodified lines | |||
| 269 | 289 | ||
| 270 | 290 | ||
| 271 | /* | 291 | /* |
| 272 | ** __gc tag method for CLIBS table: calls 'll_unloadlib' for all lib | 292 | ** __gc tag method for CLIBS table: calls 'lsys_unloadlib' for all lib |
| 273 | ** handles in list CLIBS | 293 | ** handles in list CLIBS |
| 274 | */ | 294 | */ |
| 275 | static int gctm (lua_State *L) { | 295 | static int gctm (lua_State *L) { |
| 276 | int n = luaL_len(L, 1); | 296 | lua_Integer n = luaL_len(L, 1); |
| 277 | for (; n >= 1; n--) { /* for each handle, in reverse order */ | 297 | for (; n >= 1; n--) { /* for each handle, in reverse order */ |
| 278 | lua_rawgeti(L, 1, n); /* get handle CLIBS[n] */ | 298 | lua_rawgeti(L, 1, n); /* get handle CLIBS[n] */ |
| 279 | ll_unloadlib(lua_touserdata(L, -1)); | 299 | lsys_unloadlib(lua_touserdata(L, -1)); |
| 280 | lua_pop(L, 1); /* pop handle */ | 300 | lua_pop(L, 1); /* pop handle */ |
| 281 | } | 301 | } |
| 282 | return 0; | 302 | return 0; |
| 283 | } | 303 | } |
| 284 | 304 | ||
| 285 | 305 | ||
| 286 | static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { | 306 | |
| 287 | void *reg = ll_checkclib(L, path); /* check loaded C libraries */ | 307 | /* error codes for 'lookforfunc' */ |
| 308 | #define ERRLIB 1 | ||
| 309 | #define ERRFUNC 2 | ||
| 310 | |||
| 311 | /* | ||
| 312 | ** Look for a C function named 'sym' in a dynamically loaded library | ||
| 313 | ** 'path'. | ||
| 314 | ** First, check whether the library is already loaded; if not, try | ||
| 315 | ** to load it. | ||
| 316 | ** Then, if 'sym' is '*', return true (as library has been loaded). | ||
| 317 | ** Otherwise, look for symbol 'sym' in the library and push a | ||
| 318 | ** C function with that symbol. | ||
| 319 | ** Return 0 and 'true' or a function in the stack; in case of | ||
| 320 | ** errors, return an error code and an error message in the stack. | ||
| 321 | */ | ||
| 322 | static int lookforfunc (lua_State *L, const char *path, const char *sym) { | ||
| 323 | void *reg = checkclib(L, path); /* check loaded C libraries */ | ||
| 288 | if (reg == NULL) { /* must load library? */ | 324 | if (reg == NULL) { /* must load library? */ |
| 289 | reg = ll_load(L, path, *sym == '*'); | 325 | reg = lsys_load(L, path, *sym == '*'); /* global symbols if 'sym'=='*' */ |
| 290 | if (reg == NULL) return ERRLIB; /* unable to load library */ | 326 | if (reg == NULL) return ERRLIB; /* unable to load library */ |
| 291 | ll_addtoclib(L, path, reg); | 327 | addtoclib(L, path, reg); |
| 292 | } | 328 | } |
| 293 | if (*sym == '*') { /* loading only library (no function)? */ | 329 | if (*sym == '*') { /* loading only library (no function)? */ |
| 294 | lua_pushboolean(L, 1); /* return 'true' */ | 330 | lua_pushboolean(L, 1); /* return 'true' */ |
| 295 | return 0; /* no errors */ | 331 | return 0; /* no errors */ |
| 296 | } | 332 | } |
| 297 | else { | 333 | else { |
| 298 | lua_CFunction f = ll_sym(L, reg, sym); | 334 | lua_CFunction f = lsys_sym(L, reg, sym); |
| 299 | if (f == NULL) | 335 | if (f == NULL) |
| 300 | return ERRFUNC; /* unable to find function */ | 336 | return ERRFUNC; /* unable to find function */ |
| 301 | lua_pushcfunction(L, f); /* else create new function */ | 337 | lua_pushcfunction(L, f); /* else create new function */ |
| @@ -307,7 +343,7 @@ static int ll_loadfunc (lua_State *L, const char *path, const char *sym) { · 5 unmodified lines | |||
| 307 | static int ll_loadlib (lua_State *L) { | 343 | static int ll_loadlib (lua_State *L) { |
| 308 | const char *path = luaL_checkstring(L, 1); | 344 | const char *path = luaL_checkstring(L, 1); |
| 309 | const char *init = luaL_checkstring(L, 2); | 345 | const char *init = luaL_checkstring(L, 2); |
| 310 | int stat = ll_loadfunc(L, path, init); | 346 | int stat = lookforfunc(L, path, init); |
| 311 | if (stat == 0) /* no errors? */ | 347 | if (stat == 0) /* no errors? */ |
| 312 | return 1; /* return the loaded function */ | 348 | return 1; /* return the loaded function */ |
| 313 | else { /* error; error message is on stack top */ | 349 | else { /* error; error message is on stack top */ |
| @@ -416,21 +452,29 @@ static int searcher_Lua (lua_State *L) { · 102 unmodified lines | |||
| 416 | } | 452 | } |
| 417 | 453 | ||
| 418 | 454 | ||
| 455 | /* | ||
| 456 | ** Try to find a load function for module 'modname' at file 'filename'. | ||
| 457 | ** First, change '.' to '_' in 'modname'; then, if 'modname' has | ||
| 458 | ** the form X-Y (that is, it has an "ignore mark"), build a function | ||
| 459 | ** name "luaopen_X" and look for it. (For compatibility, if that | ||
| 460 | ** fails, it also tries "luaopen_Y".) If there is no ignore mark, | ||
| 461 | ** look for a function named "luaopen_modname". | ||
| 462 | */ | ||
| 419 | static int loadfunc (lua_State *L, const char *filename, const char *modname) { | 463 | static int loadfunc (lua_State *L, const char *filename, const char *modname) { |
| 420 | const char *funcname; | 464 | const char *openfunc; |
| 421 | const char *mark; | 465 | const char *mark; |
| 422 | modname = luaL_gsub(L, modname, ".", LUA_OFSEP); | 466 | modname = luaL_gsub(L, modname, ".", LUA_OFSEP); |
| 423 | mark = strchr(modname, *LUA_IGMARK); | 467 | mark = strchr(modname, *LUA_IGMARK); |
| 424 | if (mark) { | 468 | if (mark) { |
| 425 | int stat; | 469 | int stat; |
| 426 | funcname = lua_pushlstring(L, modname, mark - modname); | 470 | openfunc = lua_pushlstring(L, modname, mark - modname); |
| 427 | funcname = lua_pushfstring(L, LUA_POF"%s", funcname); | 471 | openfunc = lua_pushfstring(L, LUA_POF"%s", openfunc); |
| 428 | stat = ll_loadfunc(L, filename, funcname); | 472 | stat = lookforfunc(L, filename, openfunc); |
| 429 | if (stat != ERRFUNC) return stat; | 473 | if (stat != ERRFUNC) return stat; |
| 430 | modname = mark + 1; /* else go ahead and try old-style name */ | 474 | modname = mark + 1; /* else go ahead and try old-style name */ |
| 431 | } | 475 | } |
| 432 | funcname = lua_pushfstring(L, LUA_POF"%s", modname); | 476 | openfunc = lua_pushfstring(L, LUA_POF"%s", modname); |
| 433 | return ll_loadfunc(L, filename, funcname); | 477 | return lookforfunc(L, filename, openfunc); |
| 434 | } | 478 | } |
| 435 | 479 | ||
| 436 | 480 | ||
| @@ -655,6 +699,12 @@ static const luaL_Reg pk_funcs[] = { · 218 unmodified lines | |||
| 655 | #if defined(LUA_COMPAT_MODULE) | 699 | #if defined(LUA_COMPAT_MODULE) |
| 656 | {"seeall", ll_seeall}, | 700 | {"seeall", ll_seeall}, |
| 657 | #endif | 701 | #endif |
| 702 | /* placeholders */ | ||
| 703 | {"preload", NULL}, | ||
| 704 | {"cpath", NULL}, | ||
| 705 | {"path", NULL}, | ||
| 706 | {"searchers", NULL}, | ||
| 707 | {"loaded", NULL}, | ||
| 658 | {NULL, NULL} | 708 | {NULL, NULL} |
| 659 | }; | 709 | }; |
| 660 | 710 | ||
| @@ -680,24 +730,31 @@ static void createsearcherstable (lua_State *L) { · 19 unmodified lines | |||
| 680 | lua_pushcclosure(L, searchers[i], 1); | 730 | lua_pushcclosure(L, searchers[i], 1); |
| 681 | lua_rawseti(L, -2, i+1); | 731 | lua_rawseti(L, -2, i+1); |
| 682 | } | 732 | } |
| 733 | #if defined(LUA_COMPAT_LOADERS) | ||
| 734 | lua_pushvalue(L, -1); /* make a copy of 'searchers' table */ | ||
| 735 | lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */ | ||
| 736 | #endif | ||
| 737 | lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */ | ||
| 683 | } | 738 | } |
| 684 | 739 | ||
| 685 | 740 | ||
| 686 | LUAMOD_API int luaopen_package (lua_State *L) { | 741 | /* |
| 687 | /* create table CLIBS to keep track of loaded C libraries */ | 742 | ** create table CLIBS to keep track of loaded C libraries, |
| 688 | luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS); | 743 | ** setting a finalizer to close all libraries when closing state. |
| 689 | lua_createtable(L, 0, 1); /* metatable for CLIBS */ | 744 | */ |
| 745 | static void createclibstable (lua_State *L) { | ||
| 746 | luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS); /* create CLIBS table */ | ||
| 747 | lua_createtable(L, 0, 1); /* create metatable for CLIBS */ | ||
| 690 | lua_pushcfunction(L, gctm); | 748 | lua_pushcfunction(L, gctm); |
| 691 | lua_setfield(L, -2, "__gc"); /* set finalizer for CLIBS table */ | 749 | lua_setfield(L, -2, "__gc"); /* set finalizer for CLIBS table */ |
| 692 | lua_setmetatable(L, -2); | 750 | lua_setmetatable(L, -2); |
| 693 | /* create `package' table */ | 751 | } |
| 694 | luaL_newlib(L, pk_funcs); | 752 | |
| 753 | |||
| 754 | LUAMOD_API int luaopen_package (lua_State *L) { | ||
| 755 | createclibstable(L); | ||
| 756 | luaL_newlib(L, pk_funcs); /* create `package' table */ | ||
| 695 | createsearcherstable(L); | 757 | createsearcherstable(L); |
| 696 | #if defined(LUA_COMPAT_LOADERS) | ||
| 697 | lua_pushvalue(L, -1); /* make a copy of 'searchers' table */ | ||
| 698 | lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */ | ||
| 699 | #endif | ||
| 700 | lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */ | ||
| 701 | /* set field 'path' */ | 758 | /* set field 'path' */ |
| 702 | setpath(L, "path", LUA_PATHVARVERSION, LUA_PATH_VAR, LUA_PATH_DEFAULT); | 759 | setpath(L, "path", LUA_PATHVARVERSION, LUA_PATH_VAR, LUA_PATH_DEFAULT); |
| 703 | /* set field 'cpath' */ | 760 | /* set field 'cpath' */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.86 2014/05/12 21:44:17 roberto Exp $ | 2 | ** $Id: lobject.c,v 2.88 2014/07/30 14:00:14 roberto Exp $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -256,7 +256,7 @@ static const char *l_str2d (const char *s, lua_Number *result) { · 250 unmodified lines | |||
| 256 | char *endptr; | 256 | char *endptr; |
| 257 | if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */ | 257 | if (strpbrk(s, "nN")) /* reject 'inf' and 'nan' */ |
| 258 | return NULL; | 258 | return NULL; |
| 259 | else if (strpbrk(s, "xX")) /* hexa? */ | 259 | else if (strpbrk(s, "xX")) /* hex? */ |
| 260 | *result = lua_strx2number(s, &endptr); | 260 | *result = lua_strx2number(s, &endptr); |
| 261 | else | 261 | else |
| 262 | *result = lua_str2number(s, &endptr); | 262 | *result = lua_str2number(s, &endptr); |
| @@ -273,7 +273,7 @@ static const char *l_str2int (const char *s, lua_Integer *result) { · 10 unmodified lines | |||
| 273 | while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */ | 273 | while (lisspace(cast_uchar(*s))) s++; /* skip initial spaces */ |
| 274 | neg = isneg(&s); | 274 | neg = isneg(&s); |
| 275 | if (s[0] == '0' && | 275 | if (s[0] == '0' && |
| 276 | (s[1] == 'x' || s[1] == 'X')) { /* hexa? */ | 276 | (s[1] == 'x' || s[1] == 'X')) { /* hex? */ |
| 277 | s += 2; /* skip '0x' */ | 277 | s += 2; /* skip '0x' */ |
| 278 | for (; lisxdigit(cast_uchar(*s)); s++) { | 278 | for (; lisxdigit(cast_uchar(*s)); s++) { |
| 279 | a = a * 16 + luaO_hexavalue(cast_uchar(*s)); | 279 | a = a * 16 + luaO_hexavalue(cast_uchar(*s)); |
| @@ -327,6 +327,32 @@ int luaO_utf8esc (char *buff, unsigned int x) { · 47 unmodified lines | |||
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | 329 | ||
| 330 | /* maximum length of the conversion of a number to a string */ | ||
| 331 | #define MAXNUMBER2STR 50 | ||
| 332 | |||
| 333 | |||
| 334 | /* | ||
| 335 | ** Convert a number object to a string | ||
| 336 | */ | ||
| 337 | void luaO_tostring (lua_State *L, StkId obj) { | ||
| 338 | char buff[MAXNUMBER2STR]; | ||
| 339 | size_t len; | ||
| 340 | lua_assert(ttisnumber(obj)); | ||
| 341 | if (ttisinteger(obj)) | ||
| 342 | len = lua_integer2str(buff, ivalue(obj)); | ||
| 343 | else { | ||
| 344 | len = lua_number2str(buff, fltvalue(obj)); | ||
| 345 | #if !defined(LUA_COMPAT_FLOATSTRING) | ||
| 346 | if (buff[strspn(buff, "-0123456789")] == '\0') { /* looks like an int? */ | ||
| 347 | buff[len++] = '.'; | ||
| 348 | buff[len++] = '0'; /* adds '.0' to result */ | ||
| 349 | } | ||
| 350 | #endif | ||
| 351 | } | ||
| 352 | setsvalue2s(L, obj, luaS_newlstr(L, buff, len)); | ||
| 353 | } | ||
| 354 | |||
| 355 | |||
| 330 | static void pushstr (lua_State *L, const char *str, size_t l) { | 356 | static void pushstr (lua_State *L, const char *str, size_t l) { |
| 331 | setsvalue2s(L, L->top++, luaS_newlstr(L, str, l)); | 357 | setsvalue2s(L, L->top++, luaS_newlstr(L, str, l)); |
| 332 | } | 358 | } |
| @@ -349,24 +375,23 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { · 16 unmodified lines | |||
| 349 | break; | 375 | break; |
| 350 | } | 376 | } |
| 351 | case 'c': { | 377 | case 'c': { |
| 352 | char buff; | 378 | char buff = cast(char, va_arg(argp, int)); |
| 353 | buff = cast(char, va_arg(argp, int)); | ||
| 354 | pushstr(L, &buff, 1); | 379 | pushstr(L, &buff, 1); |
| 355 | break; | 380 | break; |
| 356 | } | 381 | } |
| 357 | case 'd': { | 382 | case 'd': { |
| 358 | setivalue(L->top++, cast_int(va_arg(argp, int))); | 383 | setivalue(L->top++, va_arg(argp, int)); |
| 359 | luaV_tostring(L, L->top - 1); | 384 | luaO_tostring(L, L->top - 1); |
| 360 | break; | 385 | break; |
| 361 | } | 386 | } |
| 362 | case 'I': { | 387 | case 'I': { |
| 363 | setivalue(L->top++, cast(lua_Integer, va_arg(argp, l_uacInt))); | 388 | setivalue(L->top++, cast(lua_Integer, va_arg(argp, l_uacInt))); |
| 364 | luaV_tostring(L, L->top - 1); | 389 | luaO_tostring(L, L->top - 1); |
| 365 | break; | 390 | break; |
| 366 | } | 391 | } |
| 367 | case 'f': { | 392 | case 'f': { |
| 368 | setfltvalue(L->top++, cast_num(va_arg(argp, l_uacNumber))); | 393 | setfltvalue(L->top++, cast_num(va_arg(argp, l_uacNumber))); |
| 369 | luaV_tostring(L, L->top - 1); | 394 | luaO_tostring(L, L->top - 1); |
| 370 | break; | 395 | break; |
| 371 | } | 396 | } |
| 372 | case 'p': { | 397 | case 'p': { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.94 2014/06/19 18:39:36 roberto Exp $ | 2 | ** $Id: lobject.h,v 2.101 2014/07/30 14:00:14 roberto Exp $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -69,9 +69,9 @@ · 63 unmodified lines | |||
| 69 | 69 | ||
| 70 | 70 | ||
| 71 | /* | 71 | /* |
| 72 | ** Union of all collectable objects | 72 | ** Common type for all collectable objects |
| 73 | */ | 73 | */ |
| 74 | typedef union GCObject GCObject; | 74 | typedef struct GCObject GCObject; |
| 75 | 75 | ||
| 76 | 76 | ||
| 77 | /* | 77 | /* |
| @@ -82,11 +82,11 @@ typedef union GCObject GCObject; · 4 unmodified lines | |||
| 82 | 82 | ||
| 83 | 83 | ||
| 84 | /* | 84 | /* |
| 85 | ** Common header in struct form | 85 | ** Common type has only the common header |
| 86 | */ | 86 | */ |
| 87 | typedef struct GCheader { | 87 | struct GCObject { |
| 88 | CommonHeader; | 88 | CommonHeader; |
| 89 | } GCheader; | 89 | }; |
| 90 | 90 | ||
| 91 | 91 | ||
| 92 | 92 | ||
| @@ -156,10 +156,8 @@ typedef struct lua_TValue TValue; · 63 unmodified lines | |||
| 156 | #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) | 156 | #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) |
| 157 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) | 157 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) |
| 158 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) | 158 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) |
| 159 | #define rawtsvalue(o) check_exp(ttisstring(o), rawgco2ts(val_(o).gc)) | 159 | #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc)) |
| 160 | #define tsvalue(o) (&rawtsvalue(o)->tsv) | 160 | #define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc)) |
| 161 | #define rawuvalue(o) check_exp(ttisfulluserdata(o), rawgco2u(val_(o).gc)) | ||
| 162 | #define uvalue(o) (&rawuvalue(o)->uv) | ||
| 163 | #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc)) | 161 | #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc)) |
| 164 | #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc)) | 162 | #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc)) |
| 165 | #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc)) | 163 | #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc)) |
| @@ -177,7 +175,7 @@ typedef struct lua_TValue TValue; · 11 unmodified lines | |||
| 177 | 175 | ||
| 178 | 176 | ||
| 179 | /* Macros for internal tests */ | 177 | /* Macros for internal tests */ |
| 180 | #define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt) | 178 | #define righttt(obj) (ttype(obj) == gcvalue(obj)->tt) |
| 181 | 179 | ||
| 182 | #define checkliveness(g,obj) \ | 180 | #define checkliveness(g,obj) \ |
| 183 | lua_longassert(!iscollectable(obj) || \ | 181 | lua_longassert(!iscollectable(obj) || \ |
| @@ -206,11 +204,11 @@ typedef struct lua_TValue TValue; · 22 unmodified lines | |||
| 206 | 204 | ||
| 207 | #define setgcovalue(L,obj,x) \ | 205 | #define setgcovalue(L,obj,x) \ |
| 208 | { TValue *io = (obj); GCObject *i_g=(x); \ | 206 | { TValue *io = (obj); GCObject *i_g=(x); \ |
| 209 | val_(io).gc = i_g; settt_(io, ctb(gch(i_g)->tt)); } | 207 | val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); } |
| 210 | 208 | ||
| 211 | #define setsvalue(L,obj,x) \ | 209 | #define setsvalue(L,obj,x) \ |
| 212 | { TValue *io = (obj); TString *x_ = (x); \ | 210 | { TValue *io = (obj); TString *x_ = (x); \ |
| 213 | val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tsv.tt)); \ | 211 | val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \ |
| 214 | checkliveness(G(L),io); } | 212 | checkliveness(G(L),io); } |
| 215 | 213 | ||
| 216 | #define setuvalue(L,obj,x) \ | 214 | #define setuvalue(L,obj,x) \ |
| @@ -243,8 +241,7 @@ typedef struct lua_TValue TValue; · 26 unmodified lines | |||
| 243 | 241 | ||
| 244 | 242 | ||
| 245 | #define setobj(L,obj1,obj2) \ | 243 | #define setobj(L,obj1,obj2) \ |
| 246 | { const TValue *io2=(obj2); TValue *io1=(obj1); \ | 244 | { TValue *io1=(obj1); *io1 = *(obj2); \ |
| 247 | io1->value_ = io2->value_; io1->tt_ = io2->tt_; \ | ||
| 248 | (void)L; checkliveness(G(L),io1); } | 245 | (void)L; checkliveness(G(L),io1); } |
| 249 | 246 | ||
| 250 | 247 | ||
| @@ -299,50 +296,76 @@ typedef TValue *StkId; /* index to stack elements */ · 48 unmodified lines | |||
| 299 | 296 | ||
| 300 | /* | 297 | /* |
| 301 | ** Header for string value; string bytes follow the end of this structure | 298 | ** Header for string value; string bytes follow the end of this structure |
| 299 | ** (aligned according to 'UTString'; see next). | ||
| 302 | */ | 300 | */ |
| 303 | typedef union TString { | 301 | typedef struct TString { |
| 304 | L_Umaxalign dummy; /* ensures maximum alignment for strings */ | 302 | CommonHeader; |
| 305 | struct { | 303 | lu_byte extra; /* reserved words for short strings; "has hash" for longs */ |
| 306 | CommonHeader; | 304 | unsigned int hash; |
| 307 | lu_byte extra; /* reserved words for short strings; "has hash" for longs */ | 305 | size_t len; /* number of characters in string */ |
| 308 | unsigned int hash; | 306 | struct TString *hnext; /* linked list for hash table */ |
| 309 | size_t len; /* number of characters in string */ | ||
| 310 | union TString *hnext; /* linked list for hash table */ | ||
| 311 | } tsv; | ||
| 312 | } TString; | 307 | } TString; |
| 313 | 308 | ||
| 314 | 309 | ||
| 315 | /* get the actual string (array of bytes) from a TString */ | 310 | /* |
| 316 | #define getstr(ts) cast(const char *, (ts) + 1) | 311 | ** Ensures that address after this type is always fully aligned. |
| 312 | */ | ||
| 313 | typedef union UTString { | ||
| 314 | L_Umaxalign dummy; /* ensures maximum alignment for strings */ | ||
| 315 | TString tsv; | ||
| 316 | } UTString; | ||
| 317 | |||
| 318 | |||
| 319 | /* | ||
| 320 | ** Get the actual string (array of bytes) from a 'TString'. | ||
| 321 | ** (Access to 'extra' ensures that value is really a 'TString'.) | ||
| 322 | */ | ||
| 323 | #define getaddrstr(ts) (cast(char *, (ts)) + sizeof(UTString)) | ||
| 324 | #define getstr(ts) \ | ||
| 325 | check_exp(sizeof((ts)->extra), cast(const char*, getaddrstr(ts))) | ||
| 317 | 326 | ||
| 318 | /* get the actual string (array of bytes) from a Lua value */ | 327 | /* get the actual string (array of bytes) from a Lua value */ |
| 319 | #define svalue(o) getstr(rawtsvalue(o)) | 328 | #define svalue(o) getstr(tsvalue(o)) |
| 320 | 329 | ||
| 321 | 330 | ||
| 322 | /* | 331 | /* |
| 323 | ** Header for userdata; memory area follows the end of this structure | 332 | ** Header for userdata; memory area follows the end of this structure |
| 333 | ** (aligned according to 'UUdata'; see next). | ||
| 324 | */ | 334 | */ |
| 325 | typedef union Udata { | 335 | typedef struct Udata { |
| 326 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | 336 | CommonHeader; |
| 327 | struct { | 337 | lu_byte ttuv_; /* user value's tag */ |
| 328 | CommonHeader; | 338 | struct Table *metatable; |
| 329 | lu_byte ttuv_; /* user value's tag */ | 339 | size_t len; /* number of bytes */ |
| 330 | struct Table *metatable; | 340 | union Value user_; /* user value */ |
| 331 | size_t len; /* number of bytes */ | ||
| 332 | union Value user_; /* user value */ | ||
| 333 | } uv; | ||
| 334 | } Udata; | 341 | } Udata; |
| 335 | 342 | ||
| 336 | 343 | ||
| 344 | /* | ||
| 345 | ** Ensures that address after this type is always fully aligned. | ||
| 346 | */ | ||
| 347 | typedef union UUdata { | ||
| 348 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | ||
| 349 | Udata uv; | ||
| 350 | } UUdata; | ||
| 351 | |||
| 352 | |||
| 353 | /* | ||
| 354 | ** Get the address of memory block inside 'Udata'. | ||
| 355 | ** (Access to 'ttuv_' ensures that value is really a 'Udata'.) | ||
| 356 | */ | ||
| 357 | #define getudatamem(u) \ | ||
| 358 | check_exp(sizeof((u)->ttuv_), (cast(char*, (u)) + sizeof(UUdata))) | ||
| 359 | |||
| 337 | #define setuservalue(L,u,o) \ | 360 | #define setuservalue(L,u,o) \ |
| 338 | { const TValue *io=(o); Udata *iu = (u); \ | 361 | { const TValue *io=(o); Udata *iu = (u); \ |
| 339 | iu->uv.user_ = io->value_; iu->uv.ttuv_ = io->tt_; \ | 362 | iu->user_ = io->value_; iu->ttuv_ = io->tt_; \ |
| 340 | checkliveness(G(L),io); } | 363 | checkliveness(G(L),io); } |
| 341 | 364 | ||
| 342 | 365 | ||
| 343 | #define getuservalue(L,u,o) \ | 366 | #define getuservalue(L,u,o) \ |
| 344 | { TValue *io=(o); const Udata *iu = (u); \ | 367 | { TValue *io=(o); const Udata *iu = (u); \ |
| 345 | io->value_ = iu->uv.user_; io->tt_ = iu->uv.ttuv_; \ | 368 | io->value_ = iu->user_; io->tt_ = iu->ttuv_; \ |
| 346 | checkliveness(G(L),io); } | 369 | checkliveness(G(L),io); } |
| 347 | 370 | ||
| 348 | 371 | ||
| @@ -447,6 +470,13 @@ typedef union TKey { · 98 unmodified lines | |||
| 447 | } TKey; | 470 | } TKey; |
| 448 | 471 | ||
| 449 | 472 | ||
| 473 | /* copy a value into a key without messing up field 'next' */ | ||
| 474 | #define setkey(L,key,obj) \ | ||
| 475 | { TKey *k_=(key); const TValue *io_=(obj); \ | ||
| 476 | k_->nk.value_ = io_->value_; k_->nk.tt_ = io_->tt_; \ | ||
| 477 | (void)L; checkliveness(G(L),io_); } | ||
| 478 | |||
| 479 | |||
| 450 | typedef struct Node { | 480 | typedef struct Node { |
| 451 | TValue i_val; | 481 | TValue i_val; |
| 452 | TKey i_key; | 482 | TKey i_key; |
| @@ -497,6 +527,7 @@ LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1, · 44 unmodified lines | |||
| 497 | const TValue *p2, TValue *res); | 527 | const TValue *p2, TValue *res); |
| 498 | LUAI_FUNC size_t luaO_str2num (const char *s, TValue *o); | 528 | LUAI_FUNC size_t luaO_str2num (const char *s, TValue *o); |
| 499 | LUAI_FUNC int luaO_hexavalue (int c); | 529 | LUAI_FUNC int luaO_hexavalue (int c); |
| 530 | LUAI_FUNC void luaO_tostring (lua_State *L, StkId obj); | ||
| 500 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, | 531 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, |
| 501 | va_list argp); | 532 | va_list argp); |
| 502 | LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); | 533 | LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 2.139 2014/06/19 18:27:20 roberto Exp $ | 2 | ** $Id: lparser.c,v 2.142 2014/07/21 16:02:10 roberto Exp $ |
| 3 | ** Lua Parser | 3 | ** Lua Parser |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 2.121 2014/02/18 13:46:26 roberto Exp $ | 2 | ** $Id: lstate.c,v 2.125 2014/07/24 16:17:56 roberto Exp $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -53,9 +53,7 @@ · 47 unmodified lines | |||
| 53 | ** thread state + extra space | 53 | ** thread state + extra space |
| 54 | */ | 54 | */ |
| 55 | typedef struct LX { | 55 | typedef struct LX { |
| 56 | #if defined(LUAI_EXTRASPACE) | 56 | lu_byte extra_[LUA_EXTRASPACE]; |
| 57 | char buff[LUAI_EXTRASPACE]; | ||
| 58 | #endif | ||
| 59 | lua_State l; | 57 | lua_State l; |
| 60 | } LX; | 58 | } LX; |
| 61 | 59 | ||
| @@ -252,7 +250,7 @@ static void close_state (lua_State *L) { · 190 unmodified lines | |||
| 252 | 250 | ||
| 253 | 251 | ||
| 254 | LUA_API lua_State *lua_newthread (lua_State *L) { | 252 | LUA_API lua_State *lua_newthread (lua_State *L) { |
| 255 | global_State *g = G(L); | 253 | global_State *g = G(L); |
| 256 | lua_State *L1; | 254 | lua_State *L1; |
| 257 | lua_lock(L); | 255 | lua_lock(L); |
| 258 | luaC_checkGC(L); | 256 | luaC_checkGC(L); |
| @@ -263,6 +261,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 4 unmodified lines | |||
| 263 | /* link it on list 'allgc' */ | 261 | /* link it on list 'allgc' */ |
| 264 | L1->next = g->allgc; | 262 | L1->next = g->allgc; |
| 265 | g->allgc = obj2gco(L1); | 263 | g->allgc = obj2gco(L1); |
| 264 | /* anchor it on L stack */ | ||
| 266 | setthvalue(L, L->top, L1); | 265 | setthvalue(L, L->top, L1); |
| 267 | api_incr_top(L); | 266 | api_incr_top(L); |
| 268 | preinit_thread(L1, g); | 267 | preinit_thread(L1, g); |
| @@ -270,6 +269,9 @@ LUA_API lua_State *lua_newthread (lua_State *L) { · 1 unmodified line | |||
| 270 | L1->basehookcount = L->basehookcount; | 269 | L1->basehookcount = L->basehookcount; |
| 271 | L1->hook = L->hook; | 270 | L1->hook = L->hook; |
| 272 | resethookcount(L1); | 271 | resethookcount(L1); |
| 272 | /* initialize L1 extra space */ | ||
| 273 | memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread), | ||
| 274 | LUA_EXTRASPACE); | ||
| 273 | luai_userstatethread(L, L1); | 275 | luai_userstatethread(L, L1); |
| 274 | stack_init(L1, L); /* init stack */ | 276 | stack_init(L1, L); /* init stack */ |
| 275 | lua_unlock(L); | 277 | lua_unlock(L); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 2.107 2014/06/12 19:07:30 roberto Exp $ | 2 | ** $Id: lstate.h,v 2.114 2014/07/23 17:15:43 roberto Exp $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -60,9 +60,6 @@ typedef struct CallInfo { · 54 unmodified lines | |||
| 60 | StkId func; /* function index in the stack */ | 60 | StkId func; /* function index in the stack */ |
| 61 | StkId top; /* top for this function */ | 61 | StkId top; /* top for this function */ |
| 62 | struct CallInfo *previous, *next; /* dynamic call link */ | 62 | struct CallInfo *previous, *next; /* dynamic call link */ |
| 63 | ptrdiff_t extra; | ||
| 64 | short nresults; /* expected number of results from this function */ | ||
| 65 | lu_byte callstatus; | ||
| 66 | union { | 63 | union { |
| 67 | struct { /* only for Lua functions */ | 64 | struct { /* only for Lua functions */ |
| 68 | StkId base; /* base for this function */ | 65 | StkId base; /* base for this function */ |
| @@ -71,9 +68,12 @@ typedef struct CallInfo { · 2 unmodified lines | |||
| 71 | struct { /* only for C functions */ | 68 | struct { /* only for C functions */ |
| 72 | lua_KFunction k; /* continuation in case of yields */ | 69 | lua_KFunction k; /* continuation in case of yields */ |
| 73 | ptrdiff_t old_errfunc; | 70 | ptrdiff_t old_errfunc; |
| 74 | int ctx; /* context info. in case of yields */ | 71 | lua_Ctx ctx; /* context info. in case of yields */ |
| 75 | } c; | 72 | } c; |
| 76 | } u; | 73 | } u; |
| 74 | ptrdiff_t extra; | ||
| 75 | short nresults; /* expected number of results from this function */ | ||
| 76 | lu_byte callstatus; | ||
| 77 | } CallInfo; | 77 | } CallInfo; |
| 78 | 78 | ||
| 79 | 79 | ||
| @@ -149,20 +149,20 @@ struct lua_State { · 69 unmodified lines | |||
| 149 | const Instruction *oldpc; /* last pc traced */ | 149 | const Instruction *oldpc; /* last pc traced */ |
| 150 | StkId stack_last; /* last free slot in the stack */ | 150 | StkId stack_last; /* last free slot in the stack */ |
| 151 | StkId stack; /* stack base */ | 151 | StkId stack; /* stack base */ |
| 152 | int stacksize; | ||
| 153 | unsigned short nny; /* number of non-yieldable calls in stack */ | ||
| 154 | unsigned short nCcalls; /* number of nested C calls */ | ||
| 155 | lu_byte hookmask; | ||
| 156 | lu_byte allowhook; | ||
| 157 | int basehookcount; | ||
| 158 | int hookcount; | ||
| 159 | lua_Hook hook; | ||
| 160 | UpVal *openupval; /* list of open upvalues in this stack */ | 152 | UpVal *openupval; /* list of open upvalues in this stack */ |
| 161 | GCObject *gclist; | 153 | GCObject *gclist; |
| 162 | struct lua_State *twups; /* list of threads with open upvalues */ | 154 | struct lua_State *twups; /* list of threads with open upvalues */ |
| 163 | struct lua_longjmp *errorJmp; /* current error recover point */ | 155 | struct lua_longjmp *errorJmp; /* current error recover point */ |
| 164 | ptrdiff_t errfunc; /* current error handling function (stack index) */ | ||
| 165 | CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ | 156 | CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ |
| 157 | lua_Hook hook; | ||
| 158 | ptrdiff_t errfunc; /* current error handling function (stack index) */ | ||
| 159 | int stacksize; | ||
| 160 | int basehookcount; | ||
| 161 | int hookcount; | ||
| 162 | unsigned short nny; /* number of non-yieldable calls in stack */ | ||
| 163 | unsigned short nCcalls; /* number of nested C calls */ | ||
| 164 | lu_byte hookmask; | ||
| 165 | lu_byte allowhook; | ||
| 166 | }; | 166 | }; |
| 167 | 167 | ||
| 168 | 168 | ||
| @@ -170,12 +170,12 @@ struct lua_State { · 1 unmodified line | |||
| 170 | 170 | ||
| 171 | 171 | ||
| 172 | /* | 172 | /* |
| 173 | ** Union of all collectable objects | 173 | ** Union of all collectable objects (only for conversions) |
| 174 | */ | 174 | */ |
| 175 | union GCObject { | 175 | union GCUnion { |
| 176 | GCheader gch; /* common header */ | 176 | GCObject gc; /* common header */ |
| 177 | union TString ts; | 177 | struct TString ts; |
| 178 | union Udata u; | 178 | struct Udata u; |
| 179 | union Closure cl; | 179 | union Closure cl; |
| 180 | struct Table h; | 180 | struct Table h; |
| 181 | struct Proto p; | 181 | struct Proto p; |
| @@ -183,24 +183,24 @@ union GCObject { · 1 unmodified line | |||
| 183 | }; | 183 | }; |
| 184 | 184 | ||
| 185 | 185 | ||
| 186 | #define gch(o) (&(o)->gch) | 186 | #define cast_u(o) cast(union GCUnion *, (o)) |
| 187 | 187 | ||
| 188 | /* macros to convert a GCObject into a specific value */ | 188 | /* macros to convert a GCObject into a specific value */ |
| 189 | #define rawgco2ts(o) \ | 189 | #define gco2ts(o) \ |
| 190 | check_exp(novariant((o)->gch.tt) == LUA_TSTRING, &((o)->ts)) | 190 | check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts)) |
| 191 | #define gco2ts(o) (&rawgco2ts(o)->tsv) | 191 | #define gco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u)) |
| 192 | #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) | 192 | #define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l)) |
| 193 | #define gco2u(o) (&rawgco2u(o)->uv) | 193 | #define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c)) |
| 194 | #define gco2lcl(o) check_exp((o)->gch.tt == LUA_TLCL, &((o)->cl.l)) | ||
| 195 | #define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c)) | ||
| 196 | #define gco2cl(o) \ | 194 | #define gco2cl(o) \ |
| 197 | check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl)) | 195 | check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl)) |
| 198 | #define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) | 196 | #define gco2t(o) check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h)) |
| 199 | #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) | 197 | #define gco2p(o) check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p)) |
| 200 | #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) | 198 | #define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th)) |
| 199 | |||
| 201 | 200 | ||
| 202 | /* macro to convert any Lua object into a GCObject */ | 201 | /* macro to convert a Lua object into a GCObject */ |
| 203 | #define obj2gco(v) (cast(GCObject *, (v))) | 202 | #define obj2gco(v) \ |
| 203 | check_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc))) | ||
| 204 | 204 | ||
| 205 | 205 | ||
| 206 | /* actual number of total bytes allocated */ | 206 | /* actual number of total bytes allocated */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 2.40 2014/06/18 22:59:29 roberto Exp $ | 2 | ** $Id: lstring.c,v 2.44 2014/07/21 16:02:10 roberto Exp $ |
| 3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -34,10 +34,10 @@ · 28 unmodified lines | |||
| 34 | ** equality for long strings | 34 | ** equality for long strings |
| 35 | */ | 35 | */ |
| 36 | int luaS_eqlngstr (TString *a, TString *b) { | 36 | int luaS_eqlngstr (TString *a, TString *b) { |
| 37 | size_t len = a->tsv.len; | 37 | size_t len = a->len; |
| 38 | lua_assert(a->tsv.tt == LUA_TLNGSTR && b->tsv.tt == LUA_TLNGSTR); | 38 | lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR); |
| 39 | return (a == b) || /* same instance or... */ | 39 | return (a == b) || /* same instance or... */ |
| 40 | ((len == b->tsv.len) && /* equal length and ... */ | 40 | ((len == b->len) && /* equal length and ... */ |
| 41 | (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */ | 41 | (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */ |
| 42 | } | 42 | } |
| 43 | 43 | ||
| @@ -67,9 +67,9 @@ void luaS_resize (lua_State *L, int newsize) { · 23 unmodified lines | |||
| 67 | TString *p = tb->hash[i]; | 67 | TString *p = tb->hash[i]; |
| 68 | tb->hash[i] = NULL; | 68 | tb->hash[i] = NULL; |
| 69 | while (p) { /* for each node in the list */ | 69 | while (p) { /* for each node in the list */ |
| 70 | TString *hnext = p->tsv.hnext; /* save next */ | 70 | TString *hnext = p->hnext; /* save next */ |
| 71 | unsigned int h = lmod(p->tsv.hash, newsize); /* new position */ | 71 | unsigned int h = lmod(p->hash, newsize); /* new position */ |
| 72 | p->tsv.hnext = tb->hash[h]; /* chain it */ | 72 | p->hnext = tb->hash[h]; /* chain it */ |
| 73 | tb->hash[h] = p; | 73 | tb->hash[h] = p; |
| 74 | p = hnext; | 74 | p = hnext; |
| 75 | } | 75 | } |
| @@ -92,24 +92,24 @@ static TString *createstrobj (lua_State *L, const char *str, size_t l, · 16 unmodified lines | |||
| 92 | TString *ts; | 92 | TString *ts; |
| 93 | GCObject *o; | 93 | GCObject *o; |
| 94 | size_t totalsize; /* total size of TString object */ | 94 | size_t totalsize; /* total size of TString object */ |
| 95 | totalsize = sizeof(TString) + ((l + 1) * sizeof(char)); | 95 | totalsize = sizelstring(l); |
| 96 | o = luaC_newobj(L, tag, totalsize); | 96 | o = luaC_newobj(L, tag, totalsize); |
| 97 | ts = rawgco2ts(o); | 97 | ts = gco2ts(o); |
| 98 | ts->tsv.len = l; | 98 | ts->len = l; |
| 99 | ts->tsv.hash = h; | 99 | ts->hash = h; |
| 100 | ts->tsv.extra = 0; | 100 | ts->extra = 0; |
| 101 | memcpy(ts+1, str, l*sizeof(char)); | 101 | memcpy(getaddrstr(ts), str, l * sizeof(char)); |
| 102 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ | 102 | getaddrstr(ts)[l] = '\0'; /* ending 0 */ |
| 103 | return ts; | 103 | return ts; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | 106 | ||
| 107 | void luaS_remove (lua_State *L, TString *ts) { | 107 | void luaS_remove (lua_State *L, TString *ts) { |
| 108 | stringtable *tb = &G(L)->strt; | 108 | stringtable *tb = &G(L)->strt; |
| 109 | TString **p = &tb->hash[lmod(ts->tsv.hash, tb->size)]; | 109 | TString **p = &tb->hash[lmod(ts->hash, tb->size)]; |
| 110 | while (*p != ts) /* find previous element */ | 110 | while (*p != ts) /* find previous element */ |
| 111 | p = &(*p)->tsv.hnext; | 111 | p = &(*p)->hnext; |
| 112 | *p = (*p)->tsv.hnext; /* remove element from its list */ | 112 | *p = (*p)->hnext; /* remove element from its list */ |
| 113 | tb->nuse--; | 113 | tb->nuse--; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| @@ -122,12 +122,12 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { · 6 unmodified lines | |||
| 122 | global_State *g = G(L); | 122 | global_State *g = G(L); |
| 123 | unsigned int h = luaS_hash(str, l, g->seed); | 123 | unsigned int h = luaS_hash(str, l, g->seed); |
| 124 | TString **list = &g->strt.hash[lmod(h, g->strt.size)]; | 124 | TString **list = &g->strt.hash[lmod(h, g->strt.size)]; |
| 125 | for (ts = *list; ts != NULL; ts = ts->tsv.hnext) { | 125 | for (ts = *list; ts != NULL; ts = ts->hnext) { |
| 126 | if (l == ts->tsv.len && | 126 | if (l == ts->len && |
| 127 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { | 127 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { |
| 128 | /* found! */ | 128 | /* found! */ |
| 129 | if (isdead(g, obj2gco(ts))) /* dead (but not collected yet)? */ | 129 | if (isdead(g, ts)) /* dead (but not collected yet)? */ |
| 130 | changewhite(obj2gco(ts)); /* resurrect it */ | 130 | changewhite(ts); /* resurrect it */ |
| 131 | return ts; | 131 | return ts; |
| 132 | } | 132 | } |
| 133 | } | 133 | } |
| @@ -136,7 +136,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { · 2 unmodified lines | |||
| 136 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ | 136 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ |
| 137 | } | 137 | } |
| 138 | ts = createstrobj(L, str, l, LUA_TSHRSTR, h); | 138 | ts = createstrobj(L, str, l, LUA_TSHRSTR, h); |
| 139 | ts->tsv.hnext = *list; | 139 | ts->hnext = *list; |
| 140 | *list = ts; | 140 | *list = ts; |
| 141 | g->strt.nuse++; | 141 | g->strt.nuse++; |
| 142 | return ts; | 142 | return ts; |
| @@ -170,10 +170,10 @@ Udata *luaS_newudata (lua_State *L, size_t s) { · 27 unmodified lines | |||
| 170 | GCObject *o; | 170 | GCObject *o; |
| 171 | if (s > MAX_SIZE - sizeof(Udata)) | 171 | if (s > MAX_SIZE - sizeof(Udata)) |
| 172 | luaM_toobig(L); | 172 | luaM_toobig(L); |
| 173 | o = luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s); | 173 | o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s)); |
| 174 | u = rawgco2u(o); | 174 | u = gco2u(o); |
| 175 | u->uv.len = s; | 175 | u->len = s; |
| 176 | u->uv.metatable = NULL; | 176 | u->metatable = NULL; |
| 177 | setuservalue(L, u, luaO_nilobject); | 177 | setuservalue(L, u, luaO_nilobject); |
| 178 | return u; | 178 | return u; |
| 179 | } | 179 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.h,v 1.54 2014/03/19 18:51:42 roberto Exp $ | 2 | ** $Id: lstring.h,v 1.56 2014/07/18 14:46:47 roberto Exp $ |
| 3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -12,9 +12,11 @@ · 6 unmodified lines | |||
| 12 | #include "lstate.h" | 12 | #include "lstate.h" |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) |
| 16 | #define sizestring(s) sizelstring((s)->len) | ||
| 16 | 17 | ||
| 17 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) | 18 | #define sizeludata(l) (sizeof(union UUdata) + (l)) |
| 19 | #define sizeudata(u) sizeludata((u)->len) | ||
| 18 | 20 | ||
| 19 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ | 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ |
| 20 | (sizeof(s)/sizeof(char))-1)) | 22 | (sizeof(s)/sizeof(char))-1)) |
| @@ -23,13 +25,13 @@ · 2 unmodified lines | |||
| 23 | /* | 25 | /* |
| 24 | ** test whether a string is a reserved word | 26 | ** test whether a string is a reserved word |
| 25 | */ | 27 | */ |
| 26 | #define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0) | 28 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) |
| 27 | 29 | ||
| 28 | 30 | ||
| 29 | /* | 31 | /* |
| 30 | ** equality for short strings, which are always internalized | 32 | ** equality for short strings, which are always internalized |
| 31 | */ | 33 | */ |
| 32 | #define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b)) | 34 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) |
| 33 | 35 | ||
| 34 | 36 | ||
| 35 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); | 37 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.198 2014/04/27 14:42:26 roberto Exp $ | 2 | ** $Id: lstrlib.c,v 1.200 2014/07/30 13:59:24 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 | */ |
| @@ -59,7 +59,7 @@ static int str_sub (lua_State *L) { · 53 unmodified lines | |||
| 59 | if (start < 1) start = 1; | 59 | if (start < 1) start = 1; |
| 60 | if (end > (lua_Integer)l) end = l; | 60 | if (end > (lua_Integer)l) end = l; |
| 61 | if (start <= end) | 61 | if (start <= end) |
| 62 | lua_pushlstring(L, s + start - 1, end - start + 1); | 62 | lua_pushlstring(L, s + start - 1, (size_t)(end - start + 1)); |
| 63 | else lua_pushliteral(L, ""); | 63 | else lua_pushliteral(L, ""); |
| 64 | return 1; | 64 | return 1; |
| 65 | } | 65 | } |
| @@ -119,7 +119,7 @@ static int str_rep (lua_State *L) { · 53 unmodified lines | |||
| 119 | else if (l + lsep < l || l + lsep > MAXSIZE / n) /* may overflow? */ | 119 | else if (l + lsep < l || l + lsep > MAXSIZE / n) /* may overflow? */ |
| 120 | return luaL_error(L, "resulting string too large"); | 120 | return luaL_error(L, "resulting string too large"); |
| 121 | else { | 121 | else { |
| 122 | size_t totallen = n * l + (n - 1) * lsep; | 122 | size_t totallen = (size_t)n * l + (size_t)(n - 1) * lsep; |
| 123 | luaL_Buffer b; | 123 | luaL_Buffer b; |
| 124 | char *p = luaL_buffinitsize(L, &b, totallen); | 124 | char *p = luaL_buffinitsize(L, &b, totallen); |
| 125 | while (n-- > 1) { /* first n-1 copies (followed by separator) */ | 125 | while (n-- > 1) { /* first n-1 copies (followed by separator) */ |
| @@ -594,7 +594,7 @@ static int str_find_aux (lua_State *L, int find) { · 468 unmodified lines | |||
| 594 | /* explicit request or no special characters? */ | 594 | /* explicit request or no special characters? */ |
| 595 | if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) { | 595 | if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) { |
| 596 | /* do a plain search */ | 596 | /* do a plain search */ |
| 597 | const char *s2 = lmemfind(s + init - 1, ls - init + 1, p, lp); | 597 | const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp); |
| 598 | if (s2) { | 598 | if (s2) { |
| 599 | lua_pushinteger(L, s2 - s + 1); | 599 | lua_pushinteger(L, s2 - s + 1); |
| 600 | lua_pushinteger(L, s2 - s + lp); | 600 | lua_pushinteger(L, s2 - s + lp); |
| @@ -685,7 +685,8 @@ static int gmatch (lua_State *L) { · 84 unmodified lines | |||
| 685 | static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, | 685 | static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, |
| 686 | const char *e) { | 686 | const char *e) { |
| 687 | size_t l, i; | 687 | size_t l, i; |
| 688 | const char *news = lua_tolstring(ms->L, 3, &l); | 688 | lua_State *L = ms->L; |
| 689 | const char *news = lua_tolstring(L, 3, &l); | ||
| 689 | for (i = 0; i < l; i++) { | 690 | for (i = 0; i < l; i++) { |
| 690 | if (news[i] != L_ESC) | 691 | if (news[i] != L_ESC) |
| 691 | luaL_addchar(b, news[i]); | 692 | luaL_addchar(b, news[i]); |
| @@ -693,14 +694,16 @@ static void add_s (MatchState *ms, luaL_Buffer *b, const char *s, · 1 unmodified line | |||
| 693 | i++; /* skip ESC */ | 694 | i++; /* skip ESC */ |
| 694 | if (!isdigit(uchar(news[i]))) { | 695 | if (!isdigit(uchar(news[i]))) { |
| 695 | if (news[i] != L_ESC) | 696 | if (news[i] != L_ESC) |
| 696 | luaL_error(ms->L, "invalid use of " LUA_QL("%c") | 697 | luaL_error(L, "invalid use of " LUA_QL("%c") |
| 697 | " in replacement string", L_ESC); | 698 | " in replacement string", L_ESC); |
| 698 | luaL_addchar(b, news[i]); | 699 | luaL_addchar(b, news[i]); |
| 699 | } | 700 | } |
| 700 | else if (news[i] == '0') | 701 | else if (news[i] == '0') |
| 701 | luaL_addlstring(b, s, e - s); | 702 | luaL_addlstring(b, s, e - s); |
| 702 | else { | 703 | else { |
| 703 | push_onecapture(ms, news[i] - '1', s, e); | 704 | push_onecapture(ms, news[i] - '1', s, e); |
| 705 | luaL_tolstring(L, -1, NULL); /* if number, convert it to string */ | ||
| 706 | lua_remove(L, -2); /* remove original value */ | ||
| 704 | luaL_addvalue(b); /* add capture to accumulated result */ | 707 | luaL_addvalue(b); /* add capture to accumulated result */ |
| 705 | } | 708 | } |
| 706 | } | 709 | } |
| @@ -744,9 +747,9 @@ static int str_gsub (lua_State *L) { · 37 unmodified lines | |||
| 744 | const char *src = luaL_checklstring(L, 1, &srcl); | 747 | const char *src = luaL_checklstring(L, 1, &srcl); |
| 745 | const char *p = luaL_checklstring(L, 2, &lp); | 748 | const char *p = luaL_checklstring(L, 2, &lp); |
| 746 | int tr = lua_type(L, 3); | 749 | int tr = lua_type(L, 3); |
| 747 | size_t max_s = luaL_optinteger(L, 4, srcl+1); | 750 | lua_Integer max_s = luaL_optinteger(L, 4, srcl + 1); |
| 748 | int anchor = (*p == '^'); | 751 | int anchor = (*p == '^'); |
| 749 | size_t n = 0; | 752 | lua_Integer n = 0; |
| 750 | MatchState ms; | 753 | MatchState ms; |
| 751 | luaL_Buffer b; | 754 | luaL_Buffer b; |
| 752 | luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || | 755 | luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.90 2014/06/18 22:59:29 roberto Exp $ | 2 | ** $Id: ltable.c,v 2.93 2014/07/29 16:22:24 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 | */ |
| @@ -52,7 +52,7 @@ · 46 unmodified lines | |||
| 52 | 52 | ||
| 53 | #define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) | 53 | #define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t)))) |
| 54 | 54 | ||
| 55 | #define hashstr(t,str) hashpow2(t, (str)->tsv.hash) | 55 | #define hashstr(t,str) hashpow2(t, (str)->hash) |
| 56 | #define hashboolean(t,p) hashpow2(t, p) | 56 | #define hashboolean(t,p) hashpow2(t, p) |
| 57 | #define hashint(t,i) hashpow2(t, i) | 57 | #define hashint(t,i) hashpow2(t, i) |
| 58 | 58 | ||
| @@ -64,7 +64,7 @@ · 5 unmodified lines | |||
| 64 | #define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) | 64 | #define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1)))) |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | #define hashpointer(t,p) hashmod(t, IntPoint(p)) | 67 | #define hashpointer(t,p) hashmod(t, point2int(p)) |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | #define dummynode (&dummynode_) | 70 | #define dummynode (&dummynode_) |
| @@ -116,14 +116,14 @@ static Node *mainposition (const Table *t, const TValue *key) { · 45 unmodified lines | |||
| 116 | case LUA_TNUMFLT: | 116 | case LUA_TNUMFLT: |
| 117 | return hashfloat(t, fltvalue(key)); | 117 | return hashfloat(t, fltvalue(key)); |
| 118 | case LUA_TSHRSTR: | 118 | case LUA_TSHRSTR: |
| 119 | return hashstr(t, rawtsvalue(key)); | 119 | return hashstr(t, tsvalue(key)); |
| 120 | case LUA_TLNGSTR: { | 120 | case LUA_TLNGSTR: { |
| 121 | TString *s = rawtsvalue(key); | 121 | TString *s = tsvalue(key); |
| 122 | if (s->tsv.extra == 0) { /* no hash? */ | 122 | if (s->extra == 0) { /* no hash? */ |
| 123 | s->tsv.hash = luaS_hash(getstr(s), s->tsv.len, s->tsv.hash); | 123 | s->hash = luaS_hash(getstr(s), s->len, s->hash); |
| 124 | s->tsv.extra = 1; /* now it has its hash */ | 124 | s->extra = 1; /* now it has its hash */ |
| 125 | } | 125 | } |
| 126 | return hashstr(t, rawtsvalue(key)); | 126 | return hashstr(t, tsvalue(key)); |
| 127 | } | 127 | } |
| 128 | case LUA_TBOOLEAN: | 128 | case LUA_TBOOLEAN: |
| 129 | return hashboolean(t, bvalue(key)); | 129 | return hashboolean(t, bvalue(key)); |
| @@ -309,7 +309,7 @@ static void setnodevector (lua_State *L, Table *t, int size) { · 179 unmodified lines | |||
| 309 | for (i=0; i<size; i++) { | 309 | for (i=0; i<size; i++) { |
| 310 | Node *n = gnode(t, i); | 310 | Node *n = gnode(t, i); |
| 311 | gnext(n) = 0; | 311 | gnext(n) = 0; |
| 312 | setnilvalue(gkey(n)); | 312 | setnilvalue(wgkey(n)); |
| 313 | setnilvalue(gval(n)); | 313 | setnilvalue(gval(n)); |
| 314 | } | 314 | } |
| 315 | } | 315 | } |
| @@ -466,7 +466,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) { · 150 unmodified lines | |||
| 466 | mp = f; | 466 | mp = f; |
| 467 | } | 467 | } |
| 468 | } | 468 | } |
| 469 | setobj2t(L, gkey(mp), key); | 469 | setkey(L, &mp->i_key, key); |
| 470 | luaC_barrierback(L, t, key); | 470 | luaC_barrierback(L, t, key); |
| 471 | lua_assert(ttisnil(gval(mp))); | 471 | lua_assert(ttisnil(gval(mp))); |
| 472 | return gval(mp); | 472 | return gval(mp); |
| @@ -501,9 +501,10 @@ const TValue *luaH_getint (Table *t, lua_Integer key) { · 28 unmodified lines | |||
| 501 | */ | 501 | */ |
| 502 | const TValue *luaH_getstr (Table *t, TString *key) { | 502 | const TValue *luaH_getstr (Table *t, TString *key) { |
| 503 | Node *n = hashstr(t, key); | 503 | Node *n = hashstr(t, key); |
| 504 | lua_assert(key->tsv.tt == LUA_TSHRSTR); | 504 | lua_assert(key->tt == LUA_TSHRSTR); |
| 505 | for (;;) { /* check whether `key' is somewhere in the chain */ | 505 | for (;;) { /* check whether `key' is somewhere in the chain */ |
| 506 | if (ttisshrstring(gkey(n)) && eqshrstr(rawtsvalue(gkey(n)), key)) | 506 | const TValue *k = gkey(n); |
| 507 | if (ttisshrstring(k) && eqshrstr(tsvalue(k), key)) | ||
| 507 | return gval(n); /* that's it */ | 508 | return gval(n); /* that's it */ |
| 508 | else { | 509 | else { |
| 509 | int nx = gnext(n); | 510 | int nx = gnext(n); |
| @@ -520,7 +521,7 @@ const TValue *luaH_getstr (Table *t, TString *key) { · 10 unmodified lines | |||
| 520 | */ | 521 | */ |
| 521 | const TValue *luaH_get (Table *t, const TValue *key) { | 522 | const TValue *luaH_get (Table *t, const TValue *key) { |
| 522 | switch (ttype(key)) { | 523 | switch (ttype(key)) { |
| 523 | case LUA_TSHRSTR: return luaH_getstr(t, rawtsvalue(key)); | 524 | case LUA_TSHRSTR: return luaH_getstr(t, tsvalue(key)); |
| 524 | case LUA_TNUMINT: return luaH_getint(t, ivalue(key)); | 525 | case LUA_TNUMINT: return luaH_getint(t, ivalue(key)); |
| 525 | case LUA_TNIL: return luaO_nilobject; | 526 | case LUA_TNIL: return luaO_nilobject; |
| 526 | case LUA_TNUMFLT: { | 527 | case LUA_TNUMFLT: { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.h,v 2.18 2013/08/30 16:01:37 roberto Exp $ | 2 | ** $Id: ltable.h,v 2.19 2014/07/29 16:22:24 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 | */ |
| @@ -11,10 +11,15 @@ · 5 unmodified lines | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | #define gnode(t,i) (&(t)->node[i]) | 13 | #define gnode(t,i) (&(t)->node[i]) |
| 14 | #define gkey(n) (&(n)->i_key.tvk) | ||
| 15 | #define gval(n) (&(n)->i_val) | 14 | #define gval(n) (&(n)->i_val) |
| 16 | #define gnext(n) ((n)->i_key.nk.next) | 15 | #define gnext(n) ((n)->i_key.nk.next) |
| 17 | 16 | ||
| 17 | |||
| 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ | ||
| 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) | ||
| 20 | |||
| 21 | #define wgkey(n) (&(n)->i_key.nk) | ||
| 22 | |||
| 18 | #define invalidateTMcache(t) ((t)->flags = 0) | 23 | #define invalidateTMcache(t) ((t)->flags = 0) |
| 19 | 24 | ||
| 20 | 25 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltablib.c,v 1.70 2014/05/16 18:53:25 roberto Exp $ | 2 | ** $Id: ltablib.c,v 1.73 2014/07/29 16:01:00 roberto Exp $ |
| 3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -17,8 +17,56 @@ · 11 unmodified lines | |||
| 17 | #include "lualib.h" | 17 | #include "lualib.h" |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | #define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_len(L, n)) | ||
| 21 | 20 | ||
| 21 | /* | ||
| 22 | ** Structure with table-access functions | ||
| 23 | */ | ||
| 24 | typedef struct { | ||
| 25 | int (*geti) (lua_State *L, int idx, lua_Integer n); | ||
| 26 | void (*seti) (lua_State *L, int idx, lua_Integer n); | ||
| 27 | } TabA; | ||
| 28 | |||
| 29 | |||
| 30 | /* | ||
| 31 | ** equivalent to 'lua_rawgeti', but not raw | ||
| 32 | */ | ||
| 33 | static int geti (lua_State *L, int idx, lua_Integer n) { | ||
| 34 | lua_pushinteger(L, n); | ||
| 35 | return lua_gettable(L, idx); /* assume 'idx' is not negative */ | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | /* | ||
| 40 | ** equivalent to 'lua_rawseti', but not raw | ||
| 41 | */ | ||
| 42 | static void seti (lua_State *L, int idx, lua_Integer n) { | ||
| 43 | lua_pushinteger(L, n); | ||
| 44 | lua_rotate(L, -2, 1); /* exchange key and value */ | ||
| 45 | lua_settable(L, idx); /* assume 'idx' is not negative */ | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | /* | ||
| 50 | ** Check that 'arg' has a table and set access functions in 'ta' to raw | ||
| 51 | ** or non-raw according to the presence of corresponding metamethods. | ||
| 52 | */ | ||
| 53 | static void checktab (lua_State *L, int arg, TabA *ta) { | ||
| 54 | luaL_checktype(L, arg, LUA_TTABLE); | ||
| 55 | if (!lua_getmetatable(L, arg)) { /* fast track */ | ||
| 56 | ta->geti = lua_rawgeti; /* with no metatable, all is raw */ | ||
| 57 | ta->seti = lua_rawseti; | ||
| 58 | } | ||
| 59 | else { | ||
| 60 | lua_pushliteral(L, "__index"); /* 'index' metamethod */ | ||
| 61 | ta->geti = (lua_rawget(L, -2) == LUA_TNIL) ? lua_rawgeti : geti; | ||
| 62 | lua_pushliteral(L, "__newindex"); /* 'newindex' metamethod */ | ||
| 63 | ta->seti = (lua_rawget(L, -3) == LUA_TNIL) ? lua_rawseti : seti; | ||
| 64 | lua_pop(L, 3); /* pop metatable plus both metamethods */ | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | #define aux_getn(L,n,ta) (checktab(L, n, ta), luaL_len(L, n)) | ||
| 22 | 70 | ||
| 23 | 71 | ||
| 24 | #if defined(LUA_COMPAT_MAXN) | 72 | #if defined(LUA_COMPAT_MAXN) |
| @@ -40,7 +88,8 @@ static int maxn (lua_State *L) { · 15 unmodified lines | |||
| 40 | 88 | ||
| 41 | 89 | ||
| 42 | static int tinsert (lua_State *L) { | 90 | static int tinsert (lua_State *L) { |
| 43 | lua_Integer e = aux_getn(L, 1) + 1; /* first empty element */ | 91 | TabA ta; |
| 92 | lua_Integer e = aux_getn(L, 1, &ta) + 1; /* first empty element */ | ||
| 44 | lua_Integer pos; /* where to insert new element */ | 93 | lua_Integer pos; /* where to insert new element */ |
| 45 | switch (lua_gettop(L)) { | 94 | switch (lua_gettop(L)) { |
| 46 | case 2: { /* called with only 2 arguments */ | 95 | case 2: { /* called with only 2 arguments */ |
| @@ -52,8 +101,8 @@ static int tinsert (lua_State *L) { · 5 unmodified lines | |||
| 52 | pos = luaL_checkinteger(L, 2); /* 2nd argument is the position */ | 101 | pos = luaL_checkinteger(L, 2); /* 2nd argument is the position */ |
| 53 | luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds"); | 102 | luaL_argcheck(L, 1 <= pos && pos <= e, 2, "position out of bounds"); |
| 54 | for (i = e; i > pos; i--) { /* move up elements */ | 103 | for (i = e; i > pos; i--) { /* move up elements */ |
| 55 | lua_rawgeti(L, 1, i-1); | 104 | (*ta.geti)(L, 1, i - 1); |
| 56 | lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ | 105 | (*ta.seti)(L, 1, i); /* t[i] = t[i - 1] */ |
| 57 | } | 106 | } |
| 58 | break; | 107 | break; |
| 59 | } | 108 | } |
| @@ -61,29 +110,67 @@ static int tinsert (lua_State *L) { · 1 unmodified line | |||
| 61 | return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); | 110 | return luaL_error(L, "wrong number of arguments to " LUA_QL("insert")); |
| 62 | } | 111 | } |
| 63 | } | 112 | } |
| 64 | lua_rawseti(L, 1, pos); /* t[pos] = v */ | 113 | (*ta.seti)(L, 1, pos); /* t[pos] = v */ |
| 65 | return 0; | 114 | return 0; |
| 66 | } | 115 | } |
| 67 | 116 | ||
| 68 | 117 | ||
| 69 | static int tremove (lua_State *L) { | 118 | static int tremove (lua_State *L) { |
| 70 | lua_Integer size = aux_getn(L, 1); | 119 | TabA ta; |
| 120 | lua_Integer size = aux_getn(L, 1, &ta); | ||
| 71 | lua_Integer pos = luaL_optinteger(L, 2, size); | 121 | lua_Integer pos = luaL_optinteger(L, 2, size); |
| 72 | if (pos != size) /* validate 'pos' if given */ | 122 | if (pos != size) /* validate 'pos' if given */ |
| 73 | luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds"); | 123 | luaL_argcheck(L, 1 <= pos && pos <= size + 1, 1, "position out of bounds"); |
| 74 | lua_rawgeti(L, 1, pos); /* result = t[pos] */ | 124 | (*ta.geti)(L, 1, pos); /* result = t[pos] */ |
| 75 | for ( ; pos < size; pos++) { | 125 | for ( ; pos < size; pos++) { |
| 76 | lua_rawgeti(L, 1, pos+1); | 126 | (*ta.geti)(L, 1, pos + 1); |
| 77 | lua_rawseti(L, 1, pos); /* t[pos] = t[pos+1] */ | 127 | (*ta.seti)(L, 1, pos); /* t[pos] = t[pos + 1] */ |
| 78 | } | 128 | } |
| 79 | lua_pushnil(L); | 129 | lua_pushnil(L); |
| 80 | lua_rawseti(L, 1, pos); /* t[pos] = nil */ | 130 | (*ta.seti)(L, 1, pos); /* t[pos] = nil */ |
| 131 | return 1; | ||
| 132 | } | ||
| 133 | |||
| 134 | |||
| 135 | static int tcopy (lua_State *L) { | ||
| 136 | TabA ta; | ||
| 137 | lua_Integer f = luaL_checkinteger(L, 2); | ||
| 138 | lua_Integer e = luaL_checkinteger(L, 3); | ||
| 139 | lua_Integer t; | ||
| 140 | int tt = 4; /* destination table */ | ||
| 141 | /* the following restriction avoids several problems with overflows */ | ||
| 142 | luaL_argcheck(L, f > 0, 2, "initial position must be positive"); | ||
| 143 | if (lua_istable(L, tt)) | ||
| 144 | t = luaL_checkinteger(L, 5); | ||
| 145 | else { | ||
| 146 | tt = 1; /* destination table is equal to source */ | ||
| 147 | t = luaL_checkinteger(L, 4); | ||
| 148 | } | ||
| 149 | if (e >= f) { /* otherwise, nothing to move */ | ||
| 150 | lua_Integer n, i; | ||
| 151 | ta.geti = (!luaL_getmetafield(L, 1, "__index")) ? lua_rawgeti : geti; | ||
| 152 | ta.seti = (!luaL_getmetafield(L, tt, "__newindex")) ? lua_rawseti : seti; | ||
| 153 | n = e - f + 1; /* number of elements to move */ | ||
| 154 | if (t > f) { | ||
| 155 | for (i = n - 1; i >= 0; i--) { | ||
| 156 | (*ta.geti)(L, 1, f + i); | ||
| 157 | (*ta.seti)(L, tt, t + i); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | else { | ||
| 161 | for (i = 0; i < n; i++) { | ||
| 162 | (*ta.geti)(L, 1, f + i); | ||
| 163 | (*ta.seti)(L, tt, t + i); | ||
| 164 | } | ||
| 165 | } | ||
| 166 | } | ||
| 167 | lua_pushvalue(L, tt); /* return "to table" */ | ||
| 81 | return 1; | 168 | return 1; |
| 82 | } | 169 | } |
| 83 | 170 | ||
| 84 | 171 | ||
| 85 | static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) { | 172 | static void addfield (lua_State *L, luaL_Buffer *b, TabA *ta, lua_Integer i) { |
| 86 | lua_rawgeti(L, 1, i); | 173 | (*ta->geti)(L, 1, i); |
| 87 | if (!lua_isstring(L, -1)) | 174 | if (!lua_isstring(L, -1)) |
| 88 | luaL_error(L, "invalid value (%s) at index %d in table for " | 175 | luaL_error(L, "invalid value (%s) at index %d in table for " |
| 89 | LUA_QL("concat"), luaL_typename(L, -1), i); | 176 | LUA_QL("concat"), luaL_typename(L, -1), i); |
| @@ -92,20 +179,21 @@ static void addfield (lua_State *L, luaL_Buffer *b, lua_Integer i) { · 2 unmodified lines | |||
| 92 | 179 | ||
| 93 | 180 | ||
| 94 | static int tconcat (lua_State *L) { | 181 | static int tconcat (lua_State *L) { |
| 182 | TabA ta; | ||
| 95 | luaL_Buffer b; | 183 | luaL_Buffer b; |
| 96 | size_t lsep; | 184 | size_t lsep; |
| 97 | lua_Integer i, last; | 185 | lua_Integer i, last; |
| 98 | const char *sep = luaL_optlstring(L, 2, "", &lsep); | 186 | const char *sep = luaL_optlstring(L, 2, "", &lsep); |
| 99 | luaL_checktype(L, 1, LUA_TTABLE); | 187 | checktab(L, 1, &ta); |
| 100 | i = luaL_optinteger(L, 3, 1); | 188 | i = luaL_optinteger(L, 3, 1); |
| 101 | last = luaL_opt(L, luaL_checkinteger, 4, luaL_len(L, 1)); | 189 | last = luaL_opt(L, luaL_checkinteger, 4, luaL_len(L, 1)); |
| 102 | luaL_buffinit(L, &b); | 190 | luaL_buffinit(L, &b); |
| 103 | for (; i < last; i++) { | 191 | for (; i < last; i++) { |
| 104 | addfield(L, &b, i); | 192 | addfield(L, &b, &ta, i); |
| 105 | luaL_addlstring(&b, sep, lsep); | 193 | luaL_addlstring(&b, sep, lsep); |
| 106 | } | 194 | } |
| 107 | if (i == last) /* add last value (if interval was not empty) */ | 195 | if (i == last) /* add last value (if interval was not empty) */ |
| 108 | addfield(L, &b, i); | 196 | addfield(L, &b, &ta, i); |
| 109 | luaL_pushresult(&b); | 197 | luaL_pushresult(&b); |
| 110 | return 1; | 198 | return 1; |
| 111 | } | 199 | } |
| @@ -131,20 +219,21 @@ static int pack (lua_State *L) { · 19 unmodified lines | |||
| 131 | 219 | ||
| 132 | 220 | ||
| 133 | static int unpack (lua_State *L) { | 221 | static int unpack (lua_State *L) { |
| 222 | TabA ta; | ||
| 134 | lua_Integer i, e; | 223 | lua_Integer i, e; |
| 135 | lua_Unsigned n; | 224 | lua_Unsigned n; |
| 136 | luaL_checktype(L, 1, LUA_TTABLE); | 225 | checktab(L, 1, &ta); |
| 137 | i = luaL_optinteger(L, 2, 1); | 226 | i = luaL_optinteger(L, 2, 1); |
| 138 | e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1)); | 227 | e = luaL_opt(L, luaL_checkinteger, 3, luaL_len(L, 1)); |
| 139 | if (i > e) return 0; /* empty range */ | 228 | if (i > e) return 0; /* empty range */ |
| 140 | n = (lua_Unsigned)e - i; /* number of elements minus 1 (avoid overflows) */ | 229 | n = (lua_Unsigned)e - i; /* number of elements minus 1 (avoid overflows) */ |
| 141 | if (n >= (unsigned int)INT_MAX || !lua_checkstack(L, ++n)) | 230 | if (n >= (unsigned int)INT_MAX || !lua_checkstack(L, (int)(++n))) |
| 142 | return luaL_error(L, "too many results to unpack"); | 231 | return luaL_error(L, "too many results to unpack"); |
| 143 | do { /* must have at least one element */ | 232 | do { /* must have at least one element */ |
| 144 | lua_rawgeti(L, 1, i); /* push arg[i..e] */ | 233 | (*ta.geti)(L, 1, i); /* push arg[i..e] */ |
| 145 | } while (i++ < e); | 234 | } while (i++ < e); |
| 146 | 235 | ||
| 147 | return n; | 236 | return (int)n; |
| 148 | } | 237 | } |
| 149 | 238 | ||
| 150 | /* }====================================================== */ | 239 | /* }====================================================== */ |
| @@ -160,9 +249,9 @@ static int unpack (lua_State *L) { · 9 unmodified lines | |||
| 160 | */ | 249 | */ |
| 161 | 250 | ||
| 162 | 251 | ||
| 163 | static void set2 (lua_State *L, int i, int j) { | 252 | static void set2 (lua_State *L, TabA *ta, int i, int j) { |
| 164 | lua_rawseti(L, 1, i); | 253 | (*ta->seti)(L, 1, i); |
| 165 | lua_rawseti(L, 1, j); | 254 | (*ta->seti)(L, 1, j); |
| 166 | } | 255 | } |
| 167 | 256 | ||
| 168 | static int sort_comp (lua_State *L, int a, int b) { | 257 | static int sort_comp (lua_State *L, int a, int b) { |
| @@ -180,45 +269,45 @@ static int sort_comp (lua_State *L, int a, int b) { · 11 unmodified lines | |||
| 180 | return lua_compare(L, a, b, LUA_OPLT); | 269 | return lua_compare(L, a, b, LUA_OPLT); |
| 181 | } | 270 | } |
| 182 | 271 | ||
| 183 | static void auxsort (lua_State *L, int l, int u) { | 272 | static void auxsort (lua_State *L, TabA *ta, int l, int u) { |
| 184 | while (l < u) { /* for tail recursion */ | 273 | while (l < u) { /* for tail recursion */ |
| 185 | int i, j; | 274 | int i, j; |
| 186 | /* sort elements a[l], a[(l+u)/2] and a[u] */ | 275 | /* sort elements a[l], a[(l+u)/2] and a[u] */ |
| 187 | lua_rawgeti(L, 1, l); | 276 | (*ta->geti)(L, 1, l); |
| 188 | lua_rawgeti(L, 1, u); | 277 | (*ta->geti)(L, 1, u); |
| 189 | if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */ | 278 | if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */ |
| 190 | set2(L, l, u); /* swap a[l] - a[u] */ | 279 | set2(L, ta, l, u); /* swap a[l] - a[u] */ |
| 191 | else | 280 | else |
| 192 | lua_pop(L, 2); | 281 | lua_pop(L, 2); |
| 193 | if (u-l == 1) break; /* only 2 elements */ | 282 | if (u-l == 1) break; /* only 2 elements */ |
| 194 | i = (l+u)/2; | 283 | i = (l+u)/2; |
| 195 | lua_rawgeti(L, 1, i); | 284 | (*ta->geti)(L, 1, i); |
| 196 | lua_rawgeti(L, 1, l); | 285 | (*ta->geti)(L, 1, l); |
| 197 | if (sort_comp(L, -2, -1)) /* a[i]<a[l]? */ | 286 | if (sort_comp(L, -2, -1)) /* a[i]<a[l]? */ |
| 198 | set2(L, i, l); | 287 | set2(L, ta, i, l); |
| 199 | else { | 288 | else { |
| 200 | lua_pop(L, 1); /* remove a[l] */ | 289 | lua_pop(L, 1); /* remove a[l] */ |
| 201 | lua_rawgeti(L, 1, u); | 290 | (*ta->geti)(L, 1, u); |
| 202 | if (sort_comp(L, -1, -2)) /* a[u]<a[i]? */ | 291 | if (sort_comp(L, -1, -2)) /* a[u]<a[i]? */ |
| 203 | set2(L, i, u); | 292 | set2(L, ta, i, u); |
| 204 | else | 293 | else |
| 205 | lua_pop(L, 2); | 294 | lua_pop(L, 2); |
| 206 | } | 295 | } |
| 207 | if (u-l == 2) break; /* only 3 elements */ | 296 | if (u-l == 2) break; /* only 3 elements */ |
| 208 | lua_rawgeti(L, 1, i); /* Pivot */ | 297 | (*ta->geti)(L, 1, i); /* Pivot */ |
| 209 | lua_pushvalue(L, -1); | 298 | lua_pushvalue(L, -1); |
| 210 | lua_rawgeti(L, 1, u-1); | 299 | (*ta->geti)(L, 1, u-1); |
| 211 | set2(L, i, u-1); | 300 | set2(L, ta, i, u-1); |
| 212 | /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */ | 301 | /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */ |
| 213 | i = l; j = u-1; | 302 | i = l; j = u-1; |
| 214 | for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ | 303 | for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ |
| 215 | /* repeat ++i until a[i] >= P */ | 304 | /* repeat ++i until a[i] >= P */ |
| 216 | while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { | 305 | while ((*ta->geti)(L, 1, ++i), sort_comp(L, -1, -2)) { |
| 217 | if (i>=u) luaL_error(L, "invalid order function for sorting"); | 306 | if (i>=u) luaL_error(L, "invalid order function for sorting"); |
| 218 | lua_pop(L, 1); /* remove a[i] */ | 307 | lua_pop(L, 1); /* remove a[i] */ |
| 219 | } | 308 | } |
| 220 | /* repeat --j until a[j] <= P */ | 309 | /* repeat --j until a[j] <= P */ |
| 221 | while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { | 310 | while ((*ta->geti)(L, 1, --j), sort_comp(L, -3, -1)) { |
| 222 | if (j<=l) luaL_error(L, "invalid order function for sorting"); | 311 | if (j<=l) luaL_error(L, "invalid order function for sorting"); |
| 223 | lua_pop(L, 1); /* remove a[j] */ | 312 | lua_pop(L, 1); /* remove a[j] */ |
| 224 | } | 313 | } |
| @@ -226,11 +315,11 @@ static void auxsort (lua_State *L, int l, int u) { · 1 unmodified line | |||
| 226 | lua_pop(L, 3); /* pop pivot, a[i], a[j] */ | 315 | lua_pop(L, 3); /* pop pivot, a[i], a[j] */ |
| 227 | break; | 316 | break; |
| 228 | } | 317 | } |
| 229 | set2(L, i, j); | 318 | set2(L, ta, i, j); |
| 230 | } | 319 | } |
| 231 | lua_rawgeti(L, 1, u-1); | 320 | (*ta->geti)(L, 1, u-1); |
| 232 | lua_rawgeti(L, 1, i); | 321 | (*ta->geti)(L, 1, i); |
| 233 | set2(L, u-1, i); /* swap pivot (a[u-1]) with a[i] */ | 322 | set2(L, ta, u-1, i); /* swap pivot (a[u-1]) with a[i] */ |
| 234 | /* a[l..i-1] <= a[i] == P <= a[i+1..u] */ | 323 | /* a[l..i-1] <= a[i] == P <= a[i+1..u] */ |
| 235 | /* adjust so that smaller half is in [j..i] and larger one in [l..u] */ | 324 | /* adjust so that smaller half is in [j..i] and larger one in [l..u] */ |
| 236 | if (i-l < u-i) { | 325 | if (i-l < u-i) { |
| @@ -239,17 +328,18 @@ static void auxsort (lua_State *L, int l, int u) { · 2 unmodified lines | |||
| 239 | else { | 328 | else { |
| 240 | j=i+1; i=u; u=j-2; | 329 | j=i+1; i=u; u=j-2; |
| 241 | } | 330 | } |
| 242 | auxsort(L, j, i); /* call recursively the smaller one */ | 331 | auxsort(L, ta, j, i); /* call recursively the smaller one */ |
| 243 | } /* repeat the routine for the larger one */ | 332 | } /* repeat the routine for the larger one */ |
| 244 | } | 333 | } |
| 245 | 334 | ||
| 246 | static int sort (lua_State *L) { | 335 | static int sort (lua_State *L) { |
| 247 | int n = aux_getn(L, 1); | 336 | TabA ta; |
| 248 | luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */ | 337 | int n = (int)aux_getn(L, 1, &ta); |
| 338 | luaL_checkstack(L, 50, ""); /* assume array is smaller than 2^50 */ | ||
| 249 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ | 339 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ |
| 250 | luaL_checktype(L, 2, LUA_TFUNCTION); | 340 | luaL_checktype(L, 2, LUA_TFUNCTION); |
| 251 | lua_settop(L, 2); /* make sure there is two arguments */ | 341 | lua_settop(L, 2); /* make sure there are two arguments */ |
| 252 | auxsort(L, 1, n); | 342 | auxsort(L, &ta, 1, n); |
| 253 | return 0; | 343 | return 0; |
| 254 | } | 344 | } |
| 255 | 345 | ||
| @@ -265,6 +355,7 @@ static const luaL_Reg tab_funcs[] = { · 9 unmodified lines | |||
| 265 | {"pack", pack}, | 355 | {"pack", pack}, |
| 266 | {"unpack", unpack}, | 356 | {"unpack", unpack}, |
| 267 | {"remove", tremove}, | 357 | {"remove", tremove}, |
| 358 | {"copy", tcopy}, | ||
| 268 | {"sort", sort}, | 359 | {"sort", sort}, |
| 269 | {NULL, NULL} | 360 | {NULL, NULL} |
| 270 | }; | 361 | }; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 2.27 2014/06/10 18:53:18 roberto Exp $ | 2 | ** $Id: ltm.c,v 2.29 2014/07/18 13:36:14 roberto Exp $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.211 2014/06/05 20:42:06 roberto Exp $ | 2 | ** $Id: lua.c,v 1.213 2014/06/30 19:48:08 roberto Exp $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -115,7 +115,7 @@ static void lstop (lua_State *L, lua_Debug *ar) { · 109 unmodified lines | |||
| 115 | 115 | ||
| 116 | /* | 116 | /* |
| 117 | ** Function to be called at a C signal. Because a C signal cannot | 117 | ** Function to be called at a C signal. Because a C signal cannot |
| 118 | ** just change a Lua state (as there is no proper syncronization), | 118 | ** just change a Lua state (as there is no proper synchronization), |
| 119 | ** this function only sets a hook that, when called, will stop the | 119 | ** this function only sets a hook that, when called, will stop the |
| 120 | ** interpreter. | 120 | ** interpreter. |
| 121 | */ | 121 | */ |
| @@ -284,7 +284,7 @@ static const char *get_prompt (lua_State *L, int firstline) { · 162 unmodified lines | |||
| 284 | /* | 284 | /* |
| 285 | ** Check whether 'status' signals a syntax error and the error | 285 | ** Check whether 'status' signals a syntax error and the error |
| 286 | ** message at the top of the stack ends with the above mark for | 286 | ** message at the top of the stack ends with the above mark for |
| 287 | ** incoplete statements. | 287 | ** incomplete statements. |
| 288 | */ | 288 | */ |
| 289 | static int incomplete (lua_State *L, int status) { | 289 | static int incomplete (lua_State *L, int status) { |
| 290 | if (status == LUA_ERRSYNTAX) { | 290 | if (status == LUA_ERRSYNTAX) { |
| @@ -417,25 +417,31 @@ static void doREPL (lua_State *L) { · 126 unmodified lines | |||
| 417 | 417 | ||
| 418 | 418 | ||
| 419 | /* | 419 | /* |
| 420 | ** Push on the stack 'n' strings from 'argv' | 420 | ** Push on the stack the contents of table 'arg' from 1 to #arg |
| 421 | */ | 421 | */ |
| 422 | static void pushargs (lua_State *L, char **argv, int n) { | 422 | static int pushargs (lua_State *L) { |
| 423 | int i; | 423 | int i, n; |
| 424 | lua_getglobal(L, "arg"); | ||
| 425 | if (!lua_istable(L, -1)) | ||
| 426 | luaL_error(L, "'arg' is not a table"); | ||
| 427 | n = (int)luaL_len(L, -1); | ||
| 424 | luaL_checkstack(L, n + 3, "too many arguments to script"); | 428 | luaL_checkstack(L, n + 3, "too many arguments to script"); |
| 425 | for (i = 1; i < n; i++) /* skip 0 (the script name) */ | 429 | for (i = 1; i <= n; i++) |
| 426 | lua_pushstring(L, argv[i]); | 430 | lua_rawgeti(L, -i, i); |
| 431 | lua_remove(L, -i); /* remove table from the stack */ | ||
| 432 | return n; | ||
| 427 | } | 433 | } |
| 428 | 434 | ||
| 429 | 435 | ||
| 430 | static int handle_script (lua_State *L, char **argv, int n) { | 436 | static int handle_script (lua_State *L, char **argv) { |
| 431 | int status; | 437 | int status; |
| 432 | const char *fname = argv[0]; | 438 | const char *fname = argv[0]; |
| 433 | if (strcmp(fname, "-") == 0 && strcmp(argv[-1], "--") != 0) | 439 | if (strcmp(fname, "-") == 0 && strcmp(argv[-1], "--") != 0) |
| 434 | fname = NULL; /* stdin */ | 440 | fname = NULL; /* stdin */ |
| 435 | status = luaL_loadfile(L, fname); | 441 | status = luaL_loadfile(L, fname); |
| 436 | if (status == LUA_OK) { | 442 | if (status == LUA_OK) { |
| 437 | pushargs(L, argv, n); /* push arguments to script */ | 443 | int n = pushargs(L); /* push arguments to script */ |
| 438 | status = docall(L, n - 1, LUA_MULTRET); | 444 | status = docall(L, n, LUA_MULTRET); |
| 439 | } | 445 | } |
| 440 | return report(L, status); | 446 | return report(L, status); |
| 441 | } | 447 | } |
| @@ -570,7 +576,7 @@ static int pmain (lua_State *L) { · 128 unmodified lines | |||
| 570 | if (!runargs(L, argv, script)) /* execute arguments -e and -l */ | 576 | if (!runargs(L, argv, script)) /* execute arguments -e and -l */ |
| 571 | return 0; /* something failed */ | 577 | return 0; /* something failed */ |
| 572 | if (script < argc && /* execute main script (if there is one) */ | 578 | if (script < argc && /* execute main script (if there is one) */ |
| 573 | handle_script(L, argv + script, argc - script) != LUA_OK) | 579 | handle_script(L, argv + script) != LUA_OK) |
| 574 | return 0; | 580 | return 0; |
| 575 | if (args & has_i) /* -i option? */ | 581 | if (args & has_i) /* -i option? */ |
| 576 | doREPL(L); /* do read-eval-print loop */ | 582 | doREPL(L); /* do read-eval-print loop */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.307 2014/06/10 17:41:38 roberto Exp $ | 2 | ** $Id: lua.h,v 1.312 2014/07/31 13:44:30 roberto Exp $ |
| 3 | ** Lua - A Scripting Language | 3 | ** Lua - A Scripting Language |
| 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
| 5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
| @@ -19,7 +19,7 @@ · 13 unmodified lines | |||
| 19 | #define LUA_VERSION_MAJOR "5" | 19 | #define LUA_VERSION_MAJOR "5" |
| 20 | #define LUA_VERSION_MINOR "3" | 20 | #define LUA_VERSION_MINOR "3" |
| 21 | #define LUA_VERSION_NUM 503 | 21 | #define LUA_VERSION_NUM 503 |
| 22 | #define LUA_VERSION_RELEASE "0 (work3)" | 22 | #define LUA_VERSION_RELEASE "0 (alpha)" |
| 23 | 23 | ||
| 24 | #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR | 24 | #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR |
| 25 | #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE | 25 | #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE |
| @@ -53,30 +53,6 @@ · 27 unmodified lines | |||
| 53 | 53 | ||
| 54 | typedef struct lua_State lua_State; | 54 | typedef struct lua_State lua_State; |
| 55 | 55 | ||
| 56 | /* | ||
| 57 | ** Type for C functions registered with Lua | ||
| 58 | */ | ||
| 59 | typedef int (*lua_CFunction) (lua_State *L); | ||
| 60 | |||
| 61 | /* | ||
| 62 | ** Type for continuation functions | ||
| 63 | */ | ||
| 64 | typedef int (*lua_KFunction) (lua_State *L, int status, int ctx); | ||
| 65 | |||
| 66 | |||
| 67 | /* | ||
| 68 | ** functions that read/write blocks when loading/dumping Lua chunks | ||
| 69 | */ | ||
| 70 | typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); | ||
| 71 | |||
| 72 | typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud); | ||
| 73 | |||
| 74 | |||
| 75 | /* | ||
| 76 | ** prototype for memory-allocation functions | ||
| 77 | */ | ||
| 78 | typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); | ||
| 79 | |||
| 80 | 56 | ||
| 81 | /* | 57 | /* |
| 82 | ** basic types | 58 | ** basic types |
| @@ -117,6 +93,34 @@ typedef LUA_INTEGER lua_Integer; · 34 unmodified lines | |||
| 117 | /* unsigned integer type */ | 93 | /* unsigned integer type */ |
| 118 | typedef LUA_UNSIGNED lua_Unsigned; | 94 | typedef LUA_UNSIGNED lua_Unsigned; |
| 119 | 95 | ||
| 96 | /* type for continuation-function contexts */ | ||
| 97 | typedef LUA_CTXT lua_Ctx; | ||
| 98 | |||
| 99 | |||
| 100 | /* | ||
| 101 | ** Type for C functions registered with Lua | ||
| 102 | */ | ||
| 103 | typedef int (*lua_CFunction) (lua_State *L); | ||
| 104 | |||
| 105 | /* | ||
| 106 | ** Type for continuation functions | ||
| 107 | */ | ||
| 108 | typedef int (*lua_KFunction) (lua_State *L, int status, lua_Ctx ctx); | ||
| 109 | |||
| 110 | |||
| 111 | /* | ||
| 112 | ** Type for functions that read/write blocks when loading/dumping Lua chunks | ||
| 113 | */ | ||
| 114 | typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); | ||
| 115 | |||
| 116 | typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud); | ||
| 117 | |||
| 118 | |||
| 119 | /* | ||
| 120 | ** Type for memory-allocation functions | ||
| 121 | */ | ||
| 122 | typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); | ||
| 123 | |||
| 120 | 124 | ||
| 121 | 125 | ||
| 122 | /* | 126 | /* |
| @@ -154,7 +158,6 @@ LUA_API int (lua_gettop) (lua_State *L); · 31 unmodified lines | |||
| 154 | LUA_API void (lua_settop) (lua_State *L, int idx); | 158 | LUA_API void (lua_settop) (lua_State *L, int idx); |
| 155 | LUA_API void (lua_pushvalue) (lua_State *L, int idx); | 159 | LUA_API void (lua_pushvalue) (lua_State *L, int idx); |
| 156 | LUA_API void (lua_rotate) (lua_State *L, int idx, int n); | 160 | LUA_API void (lua_rotate) (lua_State *L, int idx, int n); |
| 157 | LUA_API void (lua_replace) (lua_State *L, int idx); | ||
| 158 | LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx); | 161 | LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx); |
| 159 | LUA_API int (lua_checkstack) (lua_State *L, int sz); | 162 | LUA_API int (lua_checkstack) (lua_State *L, int sz); |
| 160 | 163 | ||
| @@ -175,7 +178,6 @@ LUA_API const char *(lua_typename) (lua_State *L, int tp); · 14 unmodified lines | |||
| 175 | 178 | ||
| 176 | LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum); | 179 | LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum); |
| 177 | LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum); | 180 | LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum); |
| 178 | LUA_API lua_Unsigned (lua_tounsignedx) (lua_State *L, int idx, int *isnum); | ||
| 179 | LUA_API int (lua_toboolean) (lua_State *L, int idx); | 181 | LUA_API int (lua_toboolean) (lua_State *L, int idx); |
| 180 | LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); | 182 | LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); |
| 181 | LUA_API size_t (lua_rawlen) (lua_State *L, int idx); | 183 | LUA_API size_t (lua_rawlen) (lua_State *L, int idx); |
| @@ -220,7 +222,6 @@ LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op); · 38 unmodified lines | |||
| 220 | LUA_API void (lua_pushnil) (lua_State *L); | 222 | LUA_API void (lua_pushnil) (lua_State *L); |
| 221 | LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); | 223 | LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); |
| 222 | LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); | 224 | LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); |
| 223 | LUA_API void (lua_pushunsigned) (lua_State *L, lua_Unsigned n); | ||
| 224 | LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l); | 225 | LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l); |
| 225 | LUA_API const char *(lua_pushstring) (lua_State *L, const char *s); | 226 | LUA_API const char *(lua_pushstring) (lua_State *L, const char *s); |
| 226 | LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, | 227 | LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, |
| @@ -264,12 +265,12 @@ LUA_API void (lua_setuservalue) (lua_State *L, int idx); · 37 unmodified lines | |||
| 264 | /* | 265 | /* |
| 265 | ** 'load' and 'call' functions (load and run Lua code) | 266 | ** 'load' and 'call' functions (load and run Lua code) |
| 266 | */ | 267 | */ |
| 267 | LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, int ctx, | 268 | LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, lua_Ctx ctx, |
| 268 | lua_KFunction k); | 269 | lua_KFunction k); |
| 269 | #define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL) | 270 | #define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL) |
| 270 | 271 | ||
| 271 | LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, | 272 | LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, |
| 272 | int ctx, lua_KFunction k); | 273 | lua_Ctx ctx, lua_KFunction k); |
| 273 | #define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL) | 274 | #define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL) |
| 274 | 275 | ||
| 275 | LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, | 276 | LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, |
| @@ -282,7 +283,7 @@ LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip); · 6 unmodified lines | |||
| 282 | /* | 283 | /* |
| 283 | ** coroutine functions | 284 | ** coroutine functions |
| 284 | */ | 285 | */ |
| 285 | LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx, | 286 | LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_Ctx ctx, |
| 286 | lua_KFunction k); | 287 | lua_KFunction k); |
| 287 | #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL) | 288 | #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL) |
| 288 | LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg); | 289 | LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg); |
| @@ -326,14 +327,15 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); · 37 unmodified lines | |||
| 326 | 327 | ||
| 327 | 328 | ||
| 328 | /* | 329 | /* |
| 329 | ** =============================================================== | 330 | ** {============================================================== |
| 330 | ** some useful macros | 331 | ** some useful macros |
| 331 | ** =============================================================== | 332 | ** =============================================================== |
| 332 | */ | 333 | */ |
| 333 | 334 | ||
| 335 | #define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE)) | ||
| 336 | |||
| 334 | #define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL) | 337 | #define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL) |
| 335 | #define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL) | 338 | #define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL) |
| 336 | #define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL) | ||
| 337 | 339 | ||
| 338 | #define lua_pop(L,n) lua_settop(L, -(n)-1) | 340 | #define lua_pop(L,n) lua_settop(L, -(n)-1) |
| 339 | 341 | ||
| @@ -365,6 +367,24 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); · 25 unmodified lines | |||
| 365 | 367 | ||
| 366 | #define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1)) | 368 | #define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1)) |
| 367 | 369 | ||
| 370 | #define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1)) | ||
| 371 | |||
| 372 | /* }============================================================== */ | ||
| 373 | |||
| 374 | |||
| 375 | /* | ||
| 376 | ** {============================================================== | ||
| 377 | ** compatibility macros for unsigned conversions | ||
| 378 | ** =============================================================== | ||
| 379 | */ | ||
| 380 | #if defined(LUA_COMPAT_APIUNSIGNED) | ||
| 381 | |||
| 382 | #define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n)) | ||
| 383 | #define lua_tounsignedx(L,i,is) ((lua_Integer)lua_tointegerx(L,i,is)) | ||
| 384 | #define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL) | ||
| 385 | |||
| 386 | #endif | ||
| 387 | /* }============================================================== */ | ||
| 368 | 388 | ||
| 369 | /* | 389 | /* |
| 370 | ** {====================================================================== | 390 | ** {====================================================================== |
| @@ -203,7 +203,7 @@ int main(int argc, char* argv[]) · 202 unmodified lines | |||
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | /* | 205 | /* |
| 206 | ** $Id: print.c,v 1.73 2014/06/12 02:41:25 lhf Exp $ | 206 | ** $Id: print.c,v 1.74 2014/07/21 01:41:45 lhf Exp $ |
| 207 | ** print bytecodes | 207 | ** print bytecodes |
| 208 | ** See Copyright Notice in lua.h | 208 | ** See Copyright Notice in lua.h |
| 209 | */ | 209 | */ |
| @@ -223,7 +223,7 @@ int main(int argc, char* argv[]) · 13 unmodified lines | |||
| 223 | static void PrintString(const TString* ts) | 223 | static void PrintString(const TString* ts) |
| 224 | { | 224 | { |
| 225 | const char* s=getstr(ts); | 225 | const char* s=getstr(ts); |
| 226 | size_t i,n=ts->tsv.len; | 226 | size_t i,n=ts->len; |
| 227 | printf("%c",'"'); | 227 | printf("%c",'"'); |
| 228 | for (i=0; i<n; i++) | 228 | for (i=0; i<n; i++) |
| 229 | { | 229 | { |
| @@ -266,7 +266,7 @@ static void PrintConstant(const Proto* f, int i) · 36 unmodified lines | |||
| 266 | printf(LUA_INTEGER_FMT,ivalue(o)); | 266 | printf(LUA_INTEGER_FMT,ivalue(o)); |
| 267 | break; | 267 | break; |
| 268 | case LUA_TSHRSTR: case LUA_TLNGSTR: | 268 | case LUA_TSHRSTR: case LUA_TLNGSTR: |
| 269 | PrintString(rawtsvalue(o)); | 269 | PrintString(tsvalue(o)); |
| 270 | break; | 270 | break; |
| 271 | default: /* cannot happen */ | 271 | default: /* cannot happen */ |
| 272 | printf("? type=%d",ttype(o)); | 272 | printf("? type=%d",ttype(o)); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luaconf.h,v 1.207 2014/06/10 19:21:20 roberto Exp $ | 2 | ** $Id: luaconf.h,v 1.212 2014/07/24 19:33:29 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 | */ |
| @@ -210,6 +210,14 @@ · 204 unmodified lines | |||
| 210 | 210 | ||
| 211 | 211 | ||
| 212 | 212 | ||
| 213 | /* | ||
| 214 | @@ LUA_EXTRASPACE defines the size of a raw memory area associated with | ||
| 215 | ** a Lua state with very fast access. | ||
| 216 | ** CHANGE it if you need a different size. | ||
| 217 | */ | ||
| 218 | #define LUA_EXTRASPACE (sizeof(void *)) | ||
| 219 | |||
| 220 | |||
| 213 | /* | 221 | /* |
| 214 | @@ LUA_QL describes how error messages quote program elements. | 222 | @@ LUA_QL describes how error messages quote program elements. |
| 215 | ** CHANGE it if you want a different appearance. | 223 | ** CHANGE it if you want a different appearance. |
| @@ -254,6 +262,22 @@ · 38 unmodified lines | |||
| 254 | #define LUAI_MAXSHORTLEN 40 | 262 | #define LUAI_MAXSHORTLEN 40 |
| 255 | 263 | ||
| 256 | 264 | ||
| 265 | /* | ||
| 266 | @@ LUA_CTXT is the type of the context ('ctx') for continuation functions. | ||
| 267 | @@ It must be a numerical type; Lua will use 'intptr_t' if available. | ||
| 268 | */ | ||
| 269 | #if defined (LUA_USE_C99) | ||
| 270 | #include <stdint.h> | ||
| 271 | #if defined (INTPTR_MAX) /* even in C99 this type is optional */ | ||
| 272 | #define LUA_CTXT intptr_t | ||
| 273 | #endif | ||
| 274 | #endif | ||
| 275 | |||
| 276 | #if !defined(LUA_CTXT) | ||
| 277 | /* default definition (the nearest thing to 'intptr_t' in C89) */ | ||
| 278 | #define LUA_CTXT ptrdiff_t | ||
| 279 | #endif | ||
| 280 | |||
| 257 | 281 | ||
| 258 | /* | 282 | /* |
| 259 | ** {================================================================== | 283 | ** {================================================================== |
| @@ -280,6 +304,17 @@ · 20 unmodified lines | |||
| 280 | */ | 304 | */ |
| 281 | #define LUA_COMPAT_BITLIB | 305 | #define LUA_COMPAT_BITLIB |
| 282 | 306 | ||
| 307 | /* | ||
| 308 | @@ LUA_COMPAT_IPAIRS controls the effectivness of the __ipairs metamethod. | ||
| 309 | */ | ||
| 310 | #define LUA_COMPAT_IPAIRS | ||
| 311 | |||
| 312 | /* | ||
| 313 | @@ LUA_COMPAT_APIUNSIGNED controls the presence of macros for | ||
| 314 | ** manipulating unsigned integers (lua_pushunsigned, lua_tounsigned, etc.) | ||
| 315 | */ | ||
| 316 | #define LUA_COMPAT_APIUNSIGNED | ||
| 317 | |||
| 283 | 318 | ||
| 284 | /* | 319 | /* |
| 285 | @@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a | 320 | @@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a |
| @@ -569,7 +604,6 @@ · 283 unmodified lines | |||
| 569 | @@ LUA_INTEGER_FMT is the format for writing integers. | 604 | @@ LUA_INTEGER_FMT is the format for writing integers. |
| 570 | @@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. | 605 | @@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. |
| 571 | @@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. | 606 | @@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. |
| 572 | @@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED. | ||
| 573 | @@ lua_integer2str converts an integer to a string. | 607 | @@ lua_integer2str converts an integer to a string. |
| 574 | */ | 608 | */ |
| 575 | 609 | ||
| @@ -595,7 +629,6 @@ · 19 unmodified lines | |||
| 595 | #define LUA_INTEGER int | 629 | #define LUA_INTEGER int |
| 596 | #define LUA_INTEGER_FRMLEN "" | 630 | #define LUA_INTEGER_FRMLEN "" |
| 597 | 631 | ||
| 598 | #define LUA_MAXUNSIGNED UINT_MAX | ||
| 599 | #define LUA_MAXINTEGER INT_MAX | 632 | #define LUA_MAXINTEGER INT_MAX |
| 600 | #define LUA_MININTEGER INT_MIN | 633 | #define LUA_MININTEGER INT_MIN |
| 601 | 634 | ||
| @@ -604,7 +637,6 @@ · 2 unmodified lines | |||
| 604 | #define LUA_INTEGER long | 637 | #define LUA_INTEGER long |
| 605 | #define LUA_INTEGER_FRMLEN "l" | 638 | #define LUA_INTEGER_FRMLEN "l" |
| 606 | 639 | ||
| 607 | #define LUA_MAXUNSIGNED ULONG_MAX | ||
| 608 | #define LUA_MAXINTEGER LONG_MAX | 640 | #define LUA_MAXINTEGER LONG_MAX |
| 609 | #define LUA_MININTEGER LONG_MIN | 641 | #define LUA_MININTEGER LONG_MIN |
| 610 | 642 | ||
| @@ -615,7 +647,6 @@ · 4 unmodified lines | |||
| 615 | #define LUA_INTEGER __int64 | 647 | #define LUA_INTEGER __int64 |
| 616 | #define LUA_INTEGER_FRMLEN "I64" | 648 | #define LUA_INTEGER_FRMLEN "I64" |
| 617 | 649 | ||
| 618 | #define LUA_MAXUNSIGNED _UI64_MAX | ||
| 619 | #define LUA_MAXINTEGER _I64_MAX | 650 | #define LUA_MAXINTEGER _I64_MAX |
| 620 | #define LUA_MININTEGER _I64_MIN | 651 | #define LUA_MININTEGER _I64_MIN |
| 621 | 652 | ||
| @@ -624,7 +655,6 @@ · 2 unmodified lines | |||
| 624 | #define LUA_INTEGER long long | 655 | #define LUA_INTEGER long long |
| 625 | #define LUA_INTEGER_FRMLEN "ll" | 656 | #define LUA_INTEGER_FRMLEN "ll" |
| 626 | 657 | ||
| 627 | #define LUA_MAXUNSIGNED ULLONG_MAX | ||
| 628 | #define LUA_MAXINTEGER LLONG_MAX | 658 | #define LUA_MAXINTEGER LLONG_MAX |
| 629 | #define LUA_MININTEGER LLONG_MIN | 659 | #define LUA_MININTEGER LLONG_MIN |
| 630 | 660 | ||
| @@ -639,7 +669,6 @@ · 8 unmodified lines | |||
| 639 | #define LUA_INTEGER short int | 669 | #define LUA_INTEGER short int |
| 640 | #define LUA_INTEGER_FRMLEN "" | 670 | #define LUA_INTEGER_FRMLEN "" |
| 641 | 671 | ||
| 642 | #define LUA_MAXUNSIGNED ((LUA_UNSIGNED)USHRT_MAX) | ||
| 643 | #define LUA_MAXINTEGER SHRT_MAX | 672 | #define LUA_MAXINTEGER SHRT_MAX |
| 644 | #define LUA_MININTEGER SHRT_MIN | 673 | #define LUA_MININTEGER SHRT_MIN |
| 645 | 674 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lutf8lib.c,v 1.9 2014/05/14 18:33:37 roberto Exp $ | 2 | ** $Id: lutf8lib.c,v 1.10 2014/07/16 13:56:14 roberto Exp $ |
| 3 | ** Standard library for UTF-8 manipulation | 3 | ** Standard library for UTF-8 manipulation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -238,6 +238,8 @@ static struct luaL_Reg funcs[] = { · 232 unmodified lines | |||
| 238 | {"char", utfchar}, | 238 | {"char", utfchar}, |
| 239 | {"len", utflen}, | 239 | {"len", utflen}, |
| 240 | {"codes", iter_codes}, | 240 | {"codes", iter_codes}, |
| 241 | /* placeholders */ | ||
| 242 | {"charpatt", NULL}, | ||
| 241 | {NULL, NULL} | 243 | {NULL, NULL} |
| 242 | }; | 244 | }; |
| 243 | 245 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.216 2014/06/19 18:27:20 roberto Exp $ | 2 | ** $Id: lvm.c,v 2.222 2014/07/30 14:42:44 roberto Exp $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -33,10 +33,6 @@ · 27 unmodified lines | |||
| 33 | #define MAXTAGLOOP 2000 | 33 | #define MAXTAGLOOP 2000 |
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | /* maximum length of the conversion of a number to a string */ | ||
| 37 | #define MAXNUMBER2STR 50 | ||
| 38 | |||
| 39 | |||
| 40 | /* | 36 | /* |
| 41 | ** Similar to 'tonumber', but does not attempt to convert strings and | 37 | ** Similar to 'tonumber', but does not attempt to convert strings and |
| 42 | ** ensure correct precision (no extra bits). Used in comparisons. | 38 | ** ensure correct precision (no extra bits). Used in comparisons. |
| @@ -70,7 +66,7 @@ int luaV_tonumber_ (const TValue *obj, lua_Number *n) { · 27 unmodified lines | |||
| 70 | *n = fltvalue(obj); | 66 | *n = fltvalue(obj); |
| 71 | return 1; | 67 | return 1; |
| 72 | } | 68 | } |
| 73 | else if (ttisstring(obj) && /* string convertible to number? */ | 69 | else if (cvt2num(obj) && /* string convertible to number? */ |
| 74 | luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { | 70 | luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { |
| 75 | obj = &v; | 71 | obj = &v; |
| 76 | goto again; /* convert result from 'luaO_str2num' to a float */ | 72 | goto again; /* convert result from 'luaO_str2num' to a float */ |
| @@ -80,21 +76,29 @@ int luaV_tonumber_ (const TValue *obj, lua_Number *n) { · 3 unmodified lines | |||
| 80 | 76 | ||
| 81 | 77 | ||
| 82 | /* | 78 | /* |
| 83 | ** try to convert a value to an integer, rounding up if 'up' is true | 79 | ** try to convert a value to an integer, rounding according to 'mode': |
| 80 | ** mode == 0: accepts only integral values | ||
| 81 | ** mode < 0: takes the floor of the number | ||
| 82 | ** mode > 0: takes the ceil of the number | ||
| 84 | */ | 83 | */ |
| 85 | static int tointeger_aux (const TValue *obj, lua_Integer *p, int up) { | 84 | static int tointeger_aux (const TValue *obj, lua_Integer *p, int mode) { |
| 86 | TValue v; | 85 | TValue v; |
| 87 | again: | 86 | again: |
| 88 | if (ttisfloat(obj)) { | 87 | if (ttisfloat(obj)) { |
| 89 | lua_Number n = fltvalue(obj); | 88 | lua_Number n = fltvalue(obj); |
| 90 | n = (up ? -l_floor(-n) : l_floor(n)); | 89 | lua_Number f = l_floor(n); |
| 91 | return lua_numtointeger(n, p); | 90 | if (n != f) { /* not an integral value? */ |
| 91 | if (mode == 0) return 0; /* fails if mode demands integral value */ | ||
| 92 | else if (mode > 0) /* needs ceil? */ | ||
| 93 | f += 1; /* convert floor to ceil (remember: n != f) */ | ||
| 94 | } | ||
| 95 | return lua_numtointeger(f, p); | ||
| 92 | } | 96 | } |
| 93 | else if (ttisinteger(obj)) { | 97 | else if (ttisinteger(obj)) { |
| 94 | *p = ivalue(obj); | 98 | *p = ivalue(obj); |
| 95 | return 1; | 99 | return 1; |
| 96 | } | 100 | } |
| 97 | else if (ttisstring(obj) && | 101 | else if (cvt2num(obj) && |
| 98 | luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { | 102 | luaO_str2num(svalue(obj), &v) == tsvalue(obj)->len + 1) { |
| 99 | obj = &v; | 103 | obj = &v; |
| 100 | goto again; /* convert result from 'luaO_str2num' to an integer */ | 104 | goto again; /* convert result from 'luaO_str2num' to an integer */ |
| @@ -104,39 +108,13 @@ static int tointeger_aux (const TValue *obj, lua_Integer *p, int up) { · 3 unmodified lines | |||
| 104 | 108 | ||
| 105 | 109 | ||
| 106 | /* | 110 | /* |
| 107 | ** try to convert a non-integer value to an integer, rounding down | 111 | ** try to convert a value to an integer |
| 108 | */ | 112 | */ |
| 109 | int luaV_tointeger_ (const TValue *obj, lua_Integer *p) { | 113 | int luaV_tointeger_ (const TValue *obj, lua_Integer *p) { |
| 110 | return tointeger_aux(obj, p, 0); | 114 | return tointeger_aux(obj, p, 0); |
| 111 | } | 115 | } |
| 112 | 116 | ||
| 113 | 117 | ||
| 114 | /* | ||
| 115 | ** Convert a number object to a string | ||
| 116 | */ | ||
| 117 | int luaV_tostring (lua_State *L, StkId obj) { | ||
| 118 | if (!ttisnumber(obj)) | ||
| 119 | return 0; | ||
| 120 | else { | ||
| 121 | char buff[MAXNUMBER2STR]; | ||
| 122 | size_t len; | ||
| 123 | if (ttisinteger(obj)) | ||
| 124 | len = lua_integer2str(buff, ivalue(obj)); | ||
| 125 | else { | ||
| 126 | len = lua_number2str(buff, fltvalue(obj)); | ||
| 127 | #if !defined(LUA_COMPAT_FLOATSTRING) | ||
| 128 | if (buff[strspn(buff, "-0123456789")] == '\0') { /* looks like an int? */ | ||
| 129 | buff[len++] = '.'; | ||
| 130 | buff[len++] = '0'; /* adds '.0' to result */ | ||
| 131 | } | ||
| 132 | #endif | ||
| 133 | } | ||
| 134 | setsvalue2s(L, obj, luaS_newlstr(L, buff, len)); | ||
| 135 | return 1; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | |||
| 140 | /* | 118 | /* |
| 141 | ** Try to convert a 'for' limit to an integer, preserving the | 119 | ** Try to convert a 'for' limit to an integer, preserving the |
| 142 | ** semantics of the loop. | 120 | ** semantics of the loop. |
| @@ -155,7 +133,7 @@ int luaV_tostring (lua_State *L, StkId obj) { · 12 unmodified lines | |||
| 155 | static int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step, | 133 | static int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step, |
| 156 | int *stopnow) { | 134 | int *stopnow) { |
| 157 | *stopnow = 0; /* usually, let loops run */ | 135 | *stopnow = 0; /* usually, let loops run */ |
| 158 | if (!tointeger_aux(obj, p, (step < 0))) { /* does not fit in integer? */ | 136 | if (!tointeger_aux(obj, p, (step < 0 ? 1 : -1))) { /* not fit in integer? */ |
| 159 | lua_Number n; /* try to convert to float */ | 137 | lua_Number n; /* try to convert to float */ |
| 160 | if (!tonumber(obj, &n)) /* cannot convert to float? */ | 138 | if (!tonumber(obj, &n)) /* cannot convert to float? */ |
| 161 | return 0; /* not a number */ | 139 | return 0; /* not a number */ |
| @@ -239,7 +217,7 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { · 77 unmodified lines | |||
| 239 | luaT_callTM(L, tm, t, key, val, 0); | 217 | luaT_callTM(L, tm, t, key, val, 0); |
| 240 | return; | 218 | return; |
| 241 | } | 219 | } |
| 242 | t = tm; /* else repeat assginment over 'tm' */ | 220 | t = tm; /* else repeat assignment over 'tm' */ |
| 243 | } | 221 | } |
| 244 | luaG_runerror(L, "settable chain too long; possible loop"); | 222 | luaG_runerror(L, "settable chain too long; possible loop"); |
| 245 | } | 223 | } |
| @@ -254,9 +232,9 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { · 8 unmodified lines | |||
| 254 | */ | 232 | */ |
| 255 | static int l_strcmp (const TString *ls, const TString *rs) { | 233 | static int l_strcmp (const TString *ls, const TString *rs) { |
| 256 | const char *l = getstr(ls); | 234 | const char *l = getstr(ls); |
| 257 | size_t ll = ls->tsv.len; | 235 | size_t ll = ls->len; |
| 258 | const char *r = getstr(rs); | 236 | const char *r = getstr(rs); |
| 259 | size_t lr = rs->tsv.len; | 237 | size_t lr = rs->len; |
| 260 | for (;;) { /* for each segment */ | 238 | for (;;) { /* for each segment */ |
| 261 | int temp = strcoll(l, r); | 239 | int temp = strcoll(l, r); |
| 262 | if (temp != 0) /* not equal? */ | 240 | if (temp != 0) /* not equal? */ |
| @@ -286,7 +264,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { · 23 unmodified lines | |||
| 286 | else if (tofloat(l, &nl) && tofloat(r, &nr)) /* both are numbers? */ | 264 | else if (tofloat(l, &nl) && tofloat(r, &nr)) /* both are numbers? */ |
| 287 | return luai_numlt(nl, nr); | 265 | return luai_numlt(nl, nr); |
| 288 | else if (ttisstring(l) && ttisstring(r)) /* both are strings? */ | 266 | else if (ttisstring(l) && ttisstring(r)) /* both are strings? */ |
| 289 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; | 267 | return l_strcmp(tsvalue(l), tsvalue(r)) < 0; |
| 290 | else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0) /* no metamethod? */ | 268 | else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0) /* no metamethod? */ |
| 291 | luaG_ordererror(L, l, r); /* error */ | 269 | luaG_ordererror(L, l, r); /* error */ |
| 292 | return res; | 270 | return res; |
| @@ -304,7 +282,7 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { · 11 unmodified lines | |||
| 304 | else if (tofloat(l, &nl) && tofloat(r, &nr)) /* both are numbers? */ | 282 | else if (tofloat(l, &nl) && tofloat(r, &nr)) /* both are numbers? */ |
| 305 | return luai_numle(nl, nr); | 283 | return luai_numle(nl, nr); |
| 306 | else if (ttisstring(l) && ttisstring(r)) /* both are strings? */ | 284 | else if (ttisstring(l) && ttisstring(r)) /* both are strings? */ |
| 307 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; | 285 | return l_strcmp(tsvalue(l), tsvalue(r)) <= 0; |
| 308 | else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */ | 286 | else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */ |
| 309 | return res; | 287 | return res; |
| 310 | else if ((res = luaT_callorderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */ | 288 | else if ((res = luaT_callorderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */ |
| @@ -337,8 +315,8 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { · 26 unmodified lines | |||
| 337 | case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ | 315 | case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ |
| 338 | case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); | 316 | case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); |
| 339 | case LUA_TLCF: return fvalue(t1) == fvalue(t2); | 317 | case LUA_TLCF: return fvalue(t1) == fvalue(t2); |
| 340 | case LUA_TSHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2)); | 318 | case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2)); |
| 341 | case LUA_TLNGSTR: return luaS_eqlngstr(rawtsvalue(t1), rawtsvalue(t2)); | 319 | case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2)); |
| 342 | case LUA_TUSERDATA: { | 320 | case LUA_TUSERDATA: { |
| 343 | if (uvalue(t1) == uvalue(t2)) return 1; | 321 | if (uvalue(t1) == uvalue(t2)) return 1; |
| 344 | else if (L == NULL) return 0; | 322 | else if (L == NULL) return 0; |
| @@ -366,7 +344,8 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { · 21 unmodified lines | |||
| 366 | 344 | ||
| 367 | 345 | ||
| 368 | /* macro used by 'luaV_concat' to ensure that element at 'o' is a string */ | 346 | /* macro used by 'luaV_concat' to ensure that element at 'o' is a string */ |
| 369 | #define tostring(L,o) (ttisstring(o) || (luaV_tostring(L, o))) | 347 | #define tostring(L,o) \ |
| 348 | (ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1))) | ||
| 370 | 349 | ||
| 371 | /* | 350 | /* |
| 372 | ** Main operation for concatenation: concat 'total' values in the stack, | 351 | ** Main operation for concatenation: concat 'total' values in the stack, |
| @@ -377,7 +356,7 @@ void luaV_concat (lua_State *L, int total) { · 4 unmodified lines | |||
| 377 | do { | 356 | do { |
| 378 | StkId top = L->top; | 357 | StkId top = L->top; |
| 379 | int n = 2; /* number of elements handled in this pass (at least 2) */ | 358 | int n = 2; /* number of elements handled in this pass (at least 2) */ |
| 380 | if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) | 359 | if (!(ttisstring(top-2) || cvt2str(top-2)) || !tostring(L, top-1)) |
| 381 | luaT_trybinTM(L, top-2, top-1, top-2, TM_CONCAT); | 360 | luaT_trybinTM(L, top-2, top-1, top-2, TM_CONCAT); |
| 382 | else if (tsvalue(top-1)->len == 0) /* second operand is empty? */ | 361 | else if (tsvalue(top-1)->len == 0) /* second operand is empty? */ |
| 383 | cast_void(tostring(L, top - 2)); /* result is first operand */ | 362 | cast_void(tostring(L, top - 2)); /* result is first operand */ |
| @@ -541,7 +520,7 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base, · 157 unmodified lines | |||
| 541 | ncl->upvals[i]->refcount++; | 520 | ncl->upvals[i]->refcount++; |
| 542 | /* new closure is white, so we do not need a barrier here */ | 521 | /* new closure is white, so we do not need a barrier here */ |
| 543 | } | 522 | } |
| 544 | if (!isblack(obj2gco(p))) /* cache will not break GC invariant? */ | 523 | if (!isblack(p)) /* cache will not break GC invariant? */ |
| 545 | p->cache = ncl; /* save it on cache for reuse */ | 524 | p->cache = ncl; /* save it on cache for reuse */ |
| 546 | } | 525 | } |
| 547 | 526 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.h,v 2.31 2014/05/26 17:10:22 roberto Exp $ | 2 | ** $Id: lvm.h,v 2.33 2014/07/30 14:42:44 roberto Exp $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -13,6 +13,20 @@ · 7 unmodified lines | |||
| 13 | #include "ltm.h" | 13 | #include "ltm.h" |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | #if !defined(LUA_NOCVTN2S) | ||
| 17 | #define cvt2str(o) ttisnumber(o) | ||
| 18 | #else | ||
| 19 | #define cvt2str(o) 0 /* no convertion from numbers to strings */ | ||
| 20 | #endif | ||
| 21 | |||
| 22 | |||
| 23 | #if !defined(LUA_NOCVTS2N) | ||
| 24 | #define cvt2num(o) ttisstring(o) | ||
| 25 | #else | ||
| 26 | #define cvt2num(o) 0 /* no convertion from strings to numbers */ | ||
| 27 | #endif | ||
| 28 | |||
| 29 | |||
| 16 | #define tonumber(o,n) \ | 30 | #define tonumber(o,n) \ |
| 17 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) | 31 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) |
| 18 | 32 | ||
| @@ -29,7 +43,6 @@ LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); · 10 unmodified lines | |||
| 29 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); | 43 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); |
| 30 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); | 44 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); |
| 31 | LUAI_FUNC int luaV_tointeger_ (const TValue *obj, lua_Integer *p); | 45 | LUAI_FUNC int luaV_tointeger_ (const TValue *obj, lua_Integer *p); |
| 32 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); | ||
| 33 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, | 46 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, |
| 34 | StkId val); | 47 | StkId val); |
| 35 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, | 48 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, |