History

Lua 5.2.0-alpha-rc1

Lua Team committed 16 years ago

Commit dbe8dcf1 parent 2ce62c019 files · +286 −286Browse files

Unified · Split

19 files
  1. README +1 −1
  2. doc/contents.html +7 −7
  3. doc/manual.html +36 −64
  4. doc/readme.html +8 −7
  5. src/Makefile +2 −2
  6. src/lapi.c +3 −3
  7. src/lauxlib.c +11 −5
  8. src/lauxlib.h +2 −2
  9. src/lbitlib.c +2 −2
  10. src/ldblib.c +10 −3
  11. src/linit.c +1 −4
  12. src/liolib.c +28 −16
  13. src/llimits.h +91 −1
  14. src/lmathlib.c +38 −28
  15. src/loadlib.c +4 −14
  16. src/lstrlib.c +25 −8
  17. src/ltable.c +3 −3
  18. src/lua.h +1 −1
  19. src/luaconf.h +13 −115
README+1−1
@@ -1,5 +1,5 @@
11
2−This is Lua 5.2 (work5), released on 30 Oct 2010.
2+This is Lua 5.2 (alpha), released on 16 Nov 2010.
33
44 For installation instructions, license details, and
55 further information about Lua, see doc/readme.html.
doc/contents.html+7−7
@@ -22,8 +22,8 @@ Lua 5.2 Reference Manual · 21 unmodified lines
2222
2323 <P>
2424 <IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
25−<EM>This is a work version of Lua 5.2.
26−Everything may change in the final version.</EM>
25+<EM>This is an alpha version of Lua 5.2.
26+Some details may change in the final version.</EM>
2727
2828 <P>
2929 The reference manual is the official definition of the Lua language.
@@ -52,7 +52,7 @@ Freely available under the terms of the · 22 unmodified lines
5252 <LI><A HREF="manual.html#2.1">2.1 &ndash; Values and Types</A>
5353 <LI><A HREF="manual.html#2.2">2.2 &ndash; Environments and the Global Environment</A>
5454 <LI><A HREF="manual.html#2.3">2.3 &ndash; Error Handling</A>
55−<LI><A HREF="manual.html#2.4">2.4 &ndash; Metatables</A>
55+<LI><A HREF="manual.html#2.4">2.4 &ndash; Metatables and Metamethods</A>
5656 <LI><A HREF="manual.html#2.5">2.5 &ndash; Garbage Collection</A>
5757 <UL>
5858 <LI><A HREF="manual.html#2.5.1">2.5.1 &ndash; Garbage-Collection Metamethods</A>
@@ -484,7 +484,6 @@ Freely available under the terms of the · 425 unmodified lines
484484 <A HREF="manual.html#luaL_newlib">luaL_newlib</A><BR>
485485 <A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
486486 <A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
487−<A HREF="manual.html#luaL_setfuncs">luaL_setfuncs</A><BR>
488487 <A HREF="manual.html#luaL_openlibs">luaL_openlibs</A><BR>
489488 <A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
490489 <A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>
@@ -497,11 +496,12 @@ Freely available under the terms of the · 6 unmodified lines
497496 <A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
498497 <A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
499498 <A HREF="manual.html#luaL_requiref">luaL_requiref</A><BR>
499+<A HREF="manual.html#luaL_setfuncs">luaL_setfuncs</A><BR>
500+<A HREF="manual.html#luaL_setmetatable">luaL_setmetatable</A><BR>
500501 <A HREF="manual.html#luaL_testudata">luaL_testudata</A><BR>
501502 <A HREF="manual.html#luaL_tolstring">luaL_tolstring</A><BR>
502503 <A HREF="manual.html#luaL_traceback">luaL_traceback</A><BR>
503504 <A HREF="manual.html#luaL_typename">luaL_typename</A><BR>
504−<A HREF="manual.html#luaL_typeerror">luaL_typeerror</A><BR>
505505 <A HREF="manual.html#luaL_unref">luaL_unref</A><BR>
506506 <A HREF="manual.html#luaL_where">luaL_where</A><BR>
507507
@@ -512,10 +512,10 @@ Freely available under the terms of the · 4 unmodified lines
512512 <HR>
513513 <SMALL>
514514 Last update:
515−Sat Oct 30 21:34:44 BRST 2010
515+Tue Nov 16 09:56:07 BRST 2010
516516 </SMALL>
517517 <!--
518−Last change: revised for Lua 5.2.0 (work5)
518+Last change: revised for Lua 5.2.0 (alpha)
519519 -->
520520
521521 </BODY>
doc/manual.html+36−64
@@ -17,8 +17,8 @@ Lua 5.2 Reference Manual · 16 unmodified lines
1717 </h1>
1818
1919 <IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
20−<EM>This is a work version of Lua 5.2.
21−Everything may change in the final version.</EM>
20+<EM>This is an alpha version of Lua 5.2.
21+Some details may change in the final version.</EM>
2222 <P>
2323
2424 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
@@ -38,7 +38,7 @@ Freely available under the terms of the · 13 unmodified lines
3838 <!-- ====================================================================== -->
3939 <p>
4040
41−<!-- $Id: manual.of,v 1.61 2010/10/29 12:51:39 roberto Exp $ -->
41+<!-- $Id: manual.of,v 1.62 2010/11/16 11:38:25 roberto Exp $ -->
4242
4343
4444
@@ -287,7 +287,7 @@ you can use the <a href="#pdf-pcall"><code>pcall</code></a> function. · 242 unmodified lines
287287
288288
289289
290−<h2>2.4 &ndash; <a name="2.4">Metatables</a></h2>
290+<h2>2.4 &ndash; <a name="2.4">Metatables and Metamethods</a></h2>
291291
292292 <p>
293293 Every value in Lua can have a <em>metatable</em>.
@@ -305,7 +305,7 @@ Lua calls this function to perform the addition. · 11 unmodified lines
305305 <p>
306306 We call the keys in a metatable <em>events</em>
307307 and the values <em>metamethods</em>.
308−In the previous example, the event is <code>"add"</code>
308+In the previous example, the event is <code>"__add"</code>
309309 and the metamethod is the function that performs the addition.
310310
311311
@@ -383,7 +383,7 @@ and the access to objects with no metatables does not fail · 71 unmodified lines
383383
384384 <p>
385385 For the unary <code>-</code> and <code>#</code> operators,
386−the metamethod is called repeating the first argument as a second argument.
386+the metamethod is called with a dummy second argument.
387387 This extra argument is only to simplify Lua's internals;
388388 it may be removed in future versions and therefore it is not present
389389 in the following code.
@@ -2731,13 +2731,12 @@ It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newst · 2341 unmodified lines
27312731 return realloc(ptr, nsize);
27322732 }
27332733 </pre><p>
2734−This code assumes
2734+Note that ANSI&nbsp;C ensures
27352735 that <code>free(NULL)</code> has no effect and that
27362736 <code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.
2737−ANSI&nbsp;C ensures both behaviors.
2738−It also assumes that <code>realloc</code> does not fail when shrinking a block.
2739−(ANSI&nbsp;C does not ensure this behavior,
2740−but it seems a safe assumption.)
2737+This code assumes that <code>realloc</code> does not fail when shrinking a block.
2738+ANSI&nbsp;C does not ensure this behavior,
2739+but it seems a safe assumption.
27412740
27422741
27432742
@@ -5989,6 +5988,19 @@ These values are popped from the stack after the registration. · 3245 unmodified lines
59895988
59905989
59915990
5991+<hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p>
5992+<span class="apii">[-0, +0, <em>-</em>]</span>
5993+<pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre>
5994+
5995+<p>
5996+Sets the metatable of the object at the top of the stack
5997+as the metatable associated with name <code>tname</code>
5998+in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
5999+
6000+
6001+
6002+
6003+
59926004 <hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p>
59936005 <span class="apii">[-0, +0, <em>e</em>]</span>
59946006 <pre>void luaL_openlibs (lua_State *L);</pre>
@@ -6280,24 +6292,6 @@ Returns the name of the type of the value at the given index. · 285 unmodified lines
62806292
62816293
62826294
6283−<hr><h3><a name="luaL_typeerror"><code>luaL_typeerror</code></a></h3><p>
6284−<span class="apii">[-0, +0, <em>v</em>]</span>
6285−<pre>int luaL_typeerror (lua_State *L, int narg, const char *tname);</pre>
6286−
6287−<p>
6288−Generates an error with a message like the following:
6289−
6290−<pre>
6291− <em>location</em>: bad argument <em>narg</em> to '<em>func</em>' (<em>tname</em> expected, got <em>rt</em>)
6292−</pre><p>
6293−where <code><em>location</em></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,
6294−<code><em>func</em></code> is the name of the current function,
6295−and <code><em>rt</em></code> is the type name of the actual argument.
6296−
6297−
6298−
6299−
6300−
63016295 <hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p>
63026296 <span class="apii">[-0, +0, <em>-</em>]</span>
63036297 <pre>void luaL_unref (lua_State *L, int t, int ref);</pre>
@@ -7020,8 +7014,6 @@ In case of error, propagates the error. · 716 unmodified lines
70207014
70217015 <p>
70227016 Suspends the execution of the calling coroutine.
7023−The coroutine cannot be running a C&nbsp;function,
7024−a metamethod, or an iterator.
70257017 Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>.
70267018
70277019
@@ -8586,20 +8578,13 @@ instead of returning an error code. · 1558 unmodified lines
85868578
85878579
85888580 <p>
8589−<hr><h3><a name="pdf-io.lines"><code>io.lines ([filename] [, keepNL])</code></a></h3>
8581+<hr><h3><a name="pdf-io.lines"><code>io.lines ([filename] &middot;&middot;&middot;)</code></a></h3>
85908582
85918583
85928584 <p>
85938585 Opens the given file name in read mode
8594−and returns an iterator function that,
8595−each time it is called,
8596−returns a new line from the file.
8597−Therefore, the construction
8598−
8599−<pre>
8600− for line in io.lines(filename) do <em>body</em> end
8601−</pre><p>
8602−will iterate over all lines of the file.
8586+and returns an iterator function that
8587+works like <code>file:lines(&middot;&middot;&middot;)</code> over the oppened file.
86038588 When the iterator function detects the end of file,
86048589 it returns <b>nil</b> (to finish the loop) and automatically closes the file.
86058590
@@ -8611,11 +8596,6 @@ that is, it iterates over the lines of the default input file. · 5 unmodified lines
86118596 In this case it does not close the file when the loop ends.
86128597
86138598
8614−<p>
8615−By default, <code>lines</code> removes the newline at the end of each line.
8616−If <code>keepNL</code> is <b>true</b>, it will keep the newlines.
8617−
8618−
86198599
86208600
86218601 <p>
@@ -8750,29 +8730,26 @@ Saves any written data to <code>file</code>. · 128 unmodified lines
87508730
87518731
87528732 <p>
8753−<hr><h3><a name="pdf-file:lines"><code>file:lines ([keepNL])</code></a></h3>
8733+<hr><h3><a name="pdf-file:lines"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>
87548734
87558735
87568736 <p>
87578737 Returns an iterator function that,
87588738 each time it is called,
8759−returns a new line from the file.
8739+reads the file according to the given formats.
8740+When no format is given,
8741+uses "*l" as a default.
87608742 Therefore, the construction
87618743
87628744 <pre>
8763− for line in file:lines() do <em>body</em> end
8745+ for c in file:lines(1) do <em>body</em> end
87648746 </pre><p>
8765−will iterate over all lines of the file,
8747+will iterate over all characters of the file,
87668748 starting at the current position.
87678749 (Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
87688750 when the loop ends.)
87698751
87708752
8771−<p>
8772−By default, <code>lines</code> removes the newline at the end of each line.
8773−If <code>keepNL</code> is <b>true</b>, it will keep the newlines.
8774−
8775−
87768753
87778754
87788755 <p>
@@ -9673,11 +9650,6 @@ Modules are not expected to set global variables anymore, · 894 unmodified lines
96739650 and it is easy to set up a module with regular Lua code.
96749651 </li>
96759652
9676−<li>
9677−The debug library is not loaded by default.
9678−You must explicitly require it.
9679−</li>
9680−
96819653 <li>
96829654 Functions <code>setfenv</code> and <code>getfenv</code> are deprecated.
96839655 To set the environment of a Lua function,
@@ -9767,8 +9739,8 @@ even if it is set later. · 83 unmodified lines
97679739 </li>
97689740
97699741 <li>
9770−<code>luaL_typerror</code> was renamed <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>,
9771−to have a correct spelling.
9742+<code>luaL_typerror</code> was deprecated.
9743+Write your own version if you need it.
97729744 </li>
97739745
97749746 <li>
@@ -9873,10 +9845,10 @@ Here is the complete syntax of Lua in extended BNF. · 98 unmodified lines
98739845 <HR>
98749846 <SMALL>
98759847 Last update:
9876−Sat Oct 30 21:36:20 BRST 2010
9848+Tue Nov 16 09:52:41 BRST 2010
98779849 </SMALL>
98789850 <!--
9879−Last change: revised for Lua 5.2.0 (work5)
9851+Last change: revised for Lua 5.2.0 (alpha)
98809852 -->
98819853
98829854 </body></html>
doc/readme.html+8−7
@@ -27,13 +27,13 @@ tt, kbd, code { · 26 unmodified lines
2727 <HR>
2828 <H1>
2929 <A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
30−Welcome to Lua 5.2 (work5)
30+Welcome to Lua 5.2 (alpha)
3131 </H1>
3232
3333 <P>
3434 <IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
35−<EM>This is a work version of Lua 5.2.
36−Everything may change in the final version.</EM>
35+<EM>This is an alpha version of Lua 5.2.
36+Some details may change in the final version.</EM>
3737
3838 <P>
3939 <A HREF="#about">about</A>
@@ -323,12 +323,13 @@ Here are the other changes introduced in Lua 5.2: · 283 unmodified lines
323323 <LI> new <CODE>lua_compare</CODE>, <CODE>lua_arith</CODE>, and <CODE>lua_len</CODE>
324324 <LI> new <CODE>lua_version</CODE> and <CODE>luaL_version</CODE>
325325 <LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string
326−<LI> new <CODE>luaL_testudata</CODE>
326+<LI> new <CODE>luaL_testudata</CODE> and <CODE>luaL_setmetatable</CODE>
327327 <LI> new <CODE>luaL_tolstring</CODE>
328328 <LI> new <CODE>lua_copy</CODE>
329329 <LI> new <CODE>lua_absindex</CODE>
330330 <LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>
331331 <LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API
332+<LI> new <CODE>lua_Unsigned</CODE>
332333 </UL>
333334
334335 <H3>Implementation</H3>
@@ -337,7 +338,7 @@ Here are the other changes introduced in Lua 5.2: · 2 unmodified lines
337338 <LI> internal (immutable) version of ctypes
338339 <LI> simpler implementation for string buffers
339340 <LI> udata with finalizers are kept in a separated list for the GC
340−<LI> <CODE>CallInfo</CODE>stack now is a linked list
341+<LI> <CODE>CallInfo</CODE> stack now is a linked list
341342 <LI> parser uses much less C-stack space (no more auto arrays)
342343 <LI> new hash for floats
343344 <LI> handling of non-string error messages in the standalone interpreter
@@ -390,10 +391,10 @@ THE SOFTWARE. · 46 unmodified lines
390391 <HR>
391392 <SMALL>
392393 Last update:
393−Sat Oct 30 21:36:38 BRST 2010
394+Thu Nov 11 15:16:22 BRST 2010
394395 </SMALL>
395396 <!--
396−Last change: revised for Lua 5.2.0 (work5)
397+Last change: revised for Lua 5.2.0 (alpha)
397398 -->
398399
399400 </BODY>
src/Makefile+2−2
@@ -7,7 +7,7 @@ · 6 unmodified lines
77 PLAT= none
88
99 CC= gcc
10−CFLAGS= -O2 -Wall $(MYCFLAGS)
10+CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(MYCFLAGS)
1111 LIBS= -lm $(MYLIBS)
1212
1313 AR= ar rcu
@@ -97,7 +97,7 @@ freebsd: · 83 unmodified lines
9797 generic: $(ALL)
9898
9999 linux:
100− $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline -lncurses"
100+ $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline"
101101
102102 macosx:
103103 $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_MACOSX" MYLIBS="-lreadline"
src/lapi.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lapi.c,v 2.139 2010/10/25 20:31:11 roberto Exp $
2+** $Id: lapi.c,v 2.140 2010/11/03 15:16:17 roberto Exp $
33 ** Lua API
44 ** See Copyright Notice in lua.h
55 */
@@ -353,7 +353,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) { · 347 unmodified lines
353353 if (tonumber(o, &n)) {
354354 lua_Unsigned res;
355355 lua_Number num = nvalue(o);
356− lua_number2uint(res, num);
356+ lua_number2unsigned(res, num);
357357 if (isnum) *isnum = 1;
358358 return res;
359359 }
@@ -472,7 +472,7 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { · 112 unmodified lines
472472 LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) {
473473 lua_Number n;
474474 lua_lock(L);
475− n = lua_uint2number(u);
475+ n = lua_unsigned2number(u);
476476 setnvalue(L->top, n);
477477 api_incr_top(L);
478478 lua_unlock(L);
src/lauxlib.c+11−5
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.c,v 1.224 2010/10/29 12:52:21 roberto Exp $
2+** $Id: lauxlib.c,v 1.227 2010/11/10 18:05:36 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -168,7 +168,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { · 162 unmodified lines
168168 }
169169
170170
171−LUALIB_API int luaL_typeerror (lua_State *L, int narg, const char *tname) {
171+static int typeerror (lua_State *L, int narg, const char *tname) {
172172 const char *msg = lua_pushfstring(L, "%s expected, got %s",
173173 tname, luaL_typename(L, narg));
174174 return luaL_argerror(L, narg, msg);
@@ -176,7 +176,7 @@ LUALIB_API int luaL_typeerror (lua_State *L, int narg, const char *tname) { · 1 unmodified line
176176
177177
178178 static void tag_error (lua_State *L, int narg, int tag) {
179− luaL_typeerror(L, narg, lua_typename(L, tag));
179+ typeerror(L, narg, lua_typename(L, tag));
180180 }
181181
182182
@@ -224,6 +224,12 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { · 41 unmodified lines
224224 }
225225
226226
227+LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {
228+ luaL_getmetatable(L, tname);
229+ lua_setmetatable(L, -2);
230+}
231+
232+
227233 LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
228234 void *p = lua_touserdata(L, ud);
229235 if (p != NULL) { /* value is a userdata? */
@@ -241,7 +247,7 @@ LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { · 11 unmodified lines
241247
242248 LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
243249 void *p = luaL_testudata(L, ud, tname);
244− if (p == NULL) luaL_typeerror(L, ud, tname);
250+ if (p == NULL) typeerror(L, ud, tname);
245251 return p;
246252 }
247253
@@ -377,7 +383,7 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) { · 129 unmodified lines
377383 if (newsize - B->n < sz) /* not bit enough? */
378384 newsize = B->n + sz;
379385 if (newsize < B->n || newsize - B->n < sz)
380− luaL_error(L, "string too large");
386+ luaL_error(L, "buffer too large");
381387 newbuff = (char *)lua_newuserdata(L, newsize); /* create larger buffer */
382388 memcpy(newbuff, B->b, B->n); /* move content to new buffer */
383389 if (buffonstack(B))
src/lauxlib.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lauxlib.h,v 1.109 2010/10/25 20:31:11 roberto Exp $
2+** $Id: lauxlib.h,v 1.111 2010/11/10 18:05:36 roberto Exp $
33 ** Auxiliary functions for building Lua libraries
44 ** See Copyright Notice in lua.h
55 */
@@ -32,7 +32,6 @@ LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver); · 26 unmodified lines
3232 LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
3333 LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
3434 LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
35−LUALIB_API int (luaL_typeerror) (lua_State *L, int narg, const char *tname);
3635 LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
3736 LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
3837 size_t *l);
@@ -53,6 +52,7 @@ LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); · 14 unmodified lines
5352 LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
5453
5554 LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
55+LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
5656 LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
5757 LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
5858
src/lbitlib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbitlib.c,v 1.10 2010/10/28 15:17:29 roberto Exp $
2+** $Id: lbitlib.c,v 1.11 2010/11/08 16:31:22 roberto Exp $
33 ** Standard library for bitwise operations
44 ** See Copyright Notice in lua.h
55 */
@@ -108,7 +108,7 @@ static int b_rshift (lua_State *L) { · 102 unmodified lines
108108 static int b_arshift (lua_State *L) {
109109 b_uint r = getuintarg(L, 1);
110110 int i = luaL_checkint(L, 2);
111− if (i < 0 || !(r & (1 << (NBITS - 1))))
111+ if (i < 0 || !(r & ((b_uint)1 << (NBITS - 1))))
112112 return b_shift(L, r, -i);
113113 else { /* arithmetic shift for 'negative' number */
114114 if (i >= NBITS) r = ALLONES;
src/ldblib.c+10−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldblib.c,v 1.124 2010/07/25 15:18:19 roberto Exp $
2+** $Id: ldblib.c,v 1.125 2010/11/10 18:06:10 roberto Exp $
33 ** Interface from Lua to its debug API
44 ** See Copyright Notice in lua.h
55 */
@@ -44,15 +44,22 @@ static int db_setmetatable (lua_State *L) { · 38 unmodified lines
4444 }
4545
4646
47+static void checkudata (lua_State *L, int narg) {
48+ if (lua_type(L, narg) == LUA_TLIGHTUSERDATA)
49+ luaL_argerror(L, narg, "full userdata expected, got light userdata");
50+ luaL_checktype(L, narg, LUA_TUSERDATA);
51+}
52+
53+
4754 static int db_getuservalue (lua_State *L) {
48− luaL_checktype(L, 1, LUA_TUSERDATA);
55+ checkudata(L, 1);
4956 lua_getuservalue(L, 1);
5057 return 1;
5158 }
5259
5360
5461 static int db_setuservalue (lua_State *L) {
55− luaL_checktype(L, 1, LUA_TUSERDATA);
62+ checkudata(L, 1);
5663 if (!lua_isnoneornil(L, 2))
5764 luaL_checktype(L, 2, LUA_TTABLE);
5865 lua_settop(L, 2);
src/linit.c+1−4
@@ -1,5 +1,5 @@
11 /*
2−** $Id: linit.c,v 1.29 2010/10/25 14:32:36 roberto Exp $
2+** $Id: linit.c,v 1.30 2010/11/12 15:48:30 roberto Exp $
33 ** Initialization of libraries for lua.c and other clients
44 ** See Copyright Notice in lua.h
55 */
@@ -36,9 +36,7 @@ static const luaL_Reg loadedlibs[] = { · 30 unmodified lines
3636 {LUA_STRLIBNAME, luaopen_string},
3737 {LUA_BITLIBNAME, luaopen_bit32},
3838 {LUA_MATHLIBNAME, luaopen_math},
39−#if defined(LUA_COMPAT_DEBUGLIB)
4039 {LUA_DBLIBNAME, luaopen_debug},
41−#endif
4240 {NULL, NULL}
4341 };
4442
@@ -47,7 +45,6 @@ static const luaL_Reg loadedlibs[] = { · 2 unmodified lines
4745 ** these libs are preloaded and must be required before used
4846 */
4947 static const luaL_Reg preloadedlibs[] = {
50− {LUA_DBLIBNAME, luaopen_debug},
5148 {NULL, NULL}
5249 };
5350
src/liolib.c+28−16
@@ -1,5 +1,5 @@
11 /*
2−** $Id: liolib.c,v 2.92 2010/10/25 19:01:37 roberto Exp $
2+** $Id: liolib.c,v 2.95 2010/11/10 18:05:36 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -19,6 +19,9 @@ · 13 unmodified lines
1919 #include "lualib.h"
2020
2121
22+#define MAX_SIZE_T (~(size_t)0)
23+
24+
2225 /*
2326 ** lua_popen spawns a new process connected to the current one through
2427 ** the file streams.
@@ -111,8 +114,7 @@ static FILE *tofile (lua_State *L) { · 86 unmodified lines
111114 static FILE **newprefile (lua_State *L) {
112115 FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
113116 *pf = NULL; /* file handle is currently `closed' */
114− luaL_getmetatable(L, LUA_FILEHANDLE);
115− lua_setmetatable(L, -2);
117+ luaL_setmetatable(L, LUA_FILEHANDLE);
116118 return pf;
117119 }
118120
@@ -371,22 +373,32 @@ static int read_line (lua_State *L, FILE *f, int chop) { · 252 unmodified lines
371373 }
372374
373375
374−static int read_chars (lua_State *L, FILE *f, size_t n) {
375− size_t tbr = n; /* number of chars to be read */
376− size_t rlen; /* how much to read in each cycle */
377− size_t nr; /* number of chars actually read in each cycle */
376+static void read_all (lua_State *L, FILE *f) {
377+ size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
378378 luaL_Buffer b;
379379 luaL_buffinit(L, &b);
380− rlen = LUAL_BUFFERSIZE; /* try to read that much each time */
381− do {
382− char *p = luaL_prepbuffer(&b);
383− if (rlen > tbr) rlen = tbr; /* cannot read more than asked */
384− nr = fread(p, sizeof(char), rlen, f);
380+ for (;;) {
381+ char *p = luaL_prepbuffsize(&b, rlen);
382+ size_t nr = fread(p, sizeof(char), rlen, f);
385383 luaL_addsize(&b, nr);
386− tbr -= nr; /* still have to read 'tbr' chars */
387− } while (tbr > 0 && nr == rlen); /* until end of count or eof */
384+ if (nr < rlen) break; /* eof? */
385+ else if (rlen <= (MAX_SIZE_T / 4)) /* avoid buffers too large */
386+ rlen *= 2; /* double buffer size at each iteration */
387+ }
388+ luaL_pushresult(&b); /* close buffer */
389+}
390+
391+
392+static int read_chars (lua_State *L, FILE *f, size_t n) {
393+ size_t nr; /* number of chars actually read */
394+ char *p;
395+ luaL_Buffer b;
396+ luaL_buffinit(L, &b);
397+ p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */
398+ nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */
399+ luaL_addsize(&b, nr);
388400 luaL_pushresult(&b); /* close buffer */
389− return (tbr < n); /* true iff read something */
401+ return (nr > 0); /* true iff read something */
390402 }
391403
392404
@@ -421,7 +433,7 @@ static int g_read (lua_State *L, FILE *f, int first) { · 28 unmodified lines
421433 success = read_line(L, f, 0);
422434 break;
423435 case 'a': /* file */
424− read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */
436+ read_all(L, f); /* read entire file */
425437 success = 1; /* always success */
426438 break;
427439 default:
src/llimits.h+91−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: llimits.h,v 1.82 2010/05/31 16:08:55 roberto Exp $
2+** $Id: llimits.h,v 1.84 2010/11/08 16:33:20 roberto Exp $
33 ** Limits, basic types, and some other `installation-dependent' definitions
44 ** See Copyright Notice in lua.h
55 */
@@ -168,6 +168,96 @@ typedef lu_int32 Instruction; · 162 unmodified lines
168168 #define luai_userstateyield(L,n) ((void)L)
169169 #endif
170170
171+/*
172+** lua_number2int is a macro to convert lua_Number to int.
173+** lua_number2integer is a macro to convert lua_Number to lua_Integer.
174+** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned.
175+** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number.
176+*/
177+
178+#if defined(MS_ASMTRICK) /* { */
179+/* trick with Microsoft assembler for X86 */
180+
181+#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
182+#define lua_number2integer(i,n) lua_number2int(i, n)
183+#define lua_number2unsigned(i,n) \
184+ {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
185+
186+
187+#elif defined(LUA_IEEE754TRICK) /* }{ */
188+/* the next trick should work on any machine using IEEE754 with
189+ a 32-bit integer type */
190+
191+union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
192+
193+#if !defined(LUA_IEEEENDIAN) /* { */
194+#define LUAI_EXTRAIEEE \
195+ static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
196+#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33)
197+#else
198+#define LUAI_EXTRAIEEE /* empty */
199+#endif /* } */
200+
201+#define lua_number2int32(i,n,t) \
202+ { LUAI_EXTRAIEEE \
203+ volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
204+ (i) = (t)u.l_p[LUA_IEEEENDIAN]; }
205+
206+#define lua_number2int(i,n) lua_number2int32(i, n, int)
207+#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
208+#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
209+
210+#endif /* } */
211+
212+
213+/* the following definitions always work, but may be slow */
214+
215+#if !defined(lua_number2int)
216+#define lua_number2int(i,n) ((i)=(int)(n))
217+#endif
218+
219+#if !defined(lua_number2integer)
220+#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
221+#endif
222+
223+#if !defined(lua_number2unsigned) /* { */
224+/* the following definition assures proper modulo behavior */
225+#if defined(LUA_NUMBER_DOUBLE)
226+#include <math.h>
227+#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
228+#define lua_number2unsigned(i,n) \
229+ ((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
230+#else
231+#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n))
232+#endif
233+#endif /* } */
234+
235+
236+#if !defined(lua_unsigned2number)
237+/* on several machines, coercion from unsigned to double is slow,
238+ so it may be worth to avoid */
239+#define lua_unsigned2number(u) \
240+ (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
241+#endif
242+
243+
244+/*
245+** luai_hashnum is a macro do hash a lua_Number value into an integer.
246+** The hash must be deterministic and give reasonable values for
247+** both small and large values (outside the range of integers).
248+** It is used only in ltable.c.
249+*/
250+
251+#if !defined(luai_hashnum) /* { */
252+
253+#include <float.h>
254+#include <math.h>
255+
256+#define luai_hashnum(i,n) { int e; \
257+ n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
258+ lua_number2int(i, n); i += e; }
259+
260+#endif /* } */
171261
172262
173263
src/lmathlib.c+38−28
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lmathlib.c,v 1.76 2010/10/25 20:31:11 roberto Exp $
2+** $Id: lmathlib.c,v 1.78 2010/11/12 15:47:34 roberto Exp $
33 ** Standard mathematical library
44 ** See Copyright Notice in lua.h
55 */
@@ -22,92 +22,101 @@ · 16 unmodified lines
2222 #define RADIANS_PER_DEGREE (PI/180.0)
2323
2424
25+/* macro 'l_tg' allows the addition of an 'l' or 'f' to all math operations */
26+#if !defined(l_tg)
27+#define l_tg(x) (x)
28+#endif
29+
30+
2531
2632 static int math_abs (lua_State *L) {
27− lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));
33+ lua_pushnumber(L, l_tg(fabs)(luaL_checknumber(L, 1)));
2834 return 1;
2935 }
3036
3137 static int math_sin (lua_State *L) {
32− lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
38+ lua_pushnumber(L, l_tg(sin)(luaL_checknumber(L, 1)));
3339 return 1;
3440 }
3541
3642 static int math_sinh (lua_State *L) {
37− lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
43+ lua_pushnumber(L, l_tg(sinh)(luaL_checknumber(L, 1)));
3844 return 1;
3945 }
4046
4147 static int math_cos (lua_State *L) {
42− lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
48+ lua_pushnumber(L, l_tg(cos)(luaL_checknumber(L, 1)));
4349 return 1;
4450 }
4551
4652 static int math_cosh (lua_State *L) {
47− lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));
53+ lua_pushnumber(L, l_tg(cosh)(luaL_checknumber(L, 1)));
4854 return 1;
4955 }
5056
5157 static int math_tan (lua_State *L) {
52− lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
58+ lua_pushnumber(L, l_tg(tan)(luaL_checknumber(L, 1)));
5359 return 1;
5460 }
5561
5662 static int math_tanh (lua_State *L) {
57− lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));
63+ lua_pushnumber(L, l_tg(tanh)(luaL_checknumber(L, 1)));
5864 return 1;
5965 }
6066
6167 static int math_asin (lua_State *L) {
62− lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
68+ lua_pushnumber(L, l_tg(asin)(luaL_checknumber(L, 1)));
6369 return 1;
6470 }
6571
6672 static int math_acos (lua_State *L) {
67− lua_pushnumber(L, acos(luaL_checknumber(L, 1)));
73+ lua_pushnumber(L, l_tg(acos)(luaL_checknumber(L, 1)));
6874 return 1;
6975 }
7076
7177 static int math_atan (lua_State *L) {
72− lua_pushnumber(L, atan(luaL_checknumber(L, 1)));
78+ lua_pushnumber(L, l_tg(atan)(luaL_checknumber(L, 1)));
7379 return 1;
7480 }
7581
7682 static int math_atan2 (lua_State *L) {
77− lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
83+ lua_pushnumber(L, l_tg(atan2)(luaL_checknumber(L, 1),
84+ luaL_checknumber(L, 2)));
7885 return 1;
7986 }
8087
8188 static int math_ceil (lua_State *L) {
82− lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
89+ lua_pushnumber(L, l_tg(ceil)(luaL_checknumber(L, 1)));
8390 return 1;
8491 }
8592
8693 static int math_floor (lua_State *L) {
87− lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
94+ lua_pushnumber(L, l_tg(floor)(luaL_checknumber(L, 1)));
8895 return 1;
8996 }
9097
9198 static int math_fmod (lua_State *L) {
92− lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
99+ lua_pushnumber(L, l_tg(fmod)(luaL_checknumber(L, 1),
100+ luaL_checknumber(L, 2)));
93101 return 1;
94102 }
95103
96104 static int math_modf (lua_State *L) {
97− double ip;
98− double fp = modf(luaL_checknumber(L, 1), &ip);
105+ lua_Number ip;
106+ lua_Number fp = l_tg(modf)(luaL_checknumber(L, 1), &ip);
99107 lua_pushnumber(L, ip);
100108 lua_pushnumber(L, fp);
101109 return 2;
102110 }
103111
104112 static int math_sqrt (lua_State *L) {
105− lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));
113+ lua_pushnumber(L, l_tg(sqrt)(luaL_checknumber(L, 1)));
106114 return 1;
107115 }
108116
109117 static int math_pow (lua_State *L) {
110− lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
118+ lua_pushnumber(L, l_tg(pow)(luaL_checknumber(L, 1),
119+ luaL_checknumber(L, 2)));
111120 return 1;
112121 }
113122
@@ -115,11 +124,11 @@ static int math_log (lua_State *L) { · 1 unmodified line
115124 lua_Number x = luaL_checknumber(L, 1);
116125 lua_Number res;
117126 if (lua_isnoneornil(L, 2))
118− res = log(x);
127+ res = l_tg(log)(x);
119128 else {
120129 lua_Number base = luaL_checknumber(L, 2);
121− if (base == 10.0) res = log10(x);
122− else res = log(x)/log(base);
130+ if (base == 10.0) res = l_tg(log10)(x);
131+ else res = l_tg(log)(x)/l_tg(log)(base);
123132 }
124133 lua_pushnumber(L, res);
125134 return 1;
@@ -130,12 +139,12 @@ static int math_log10 (lua_State *L) { · 4 unmodified lines
130139 luaL_error(L, "function " LUA_QL("log10")
131140 " is deprecated; use log(x, 10) instead");
132141 #endif
133− lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
142+ lua_pushnumber(L, l_tg(log10)(luaL_checknumber(L, 1)));
134143 return 1;
135144 }
136145
137146 static int math_exp (lua_State *L) {
138− lua_pushnumber(L, exp(luaL_checknumber(L, 1)));
147+ lua_pushnumber(L, l_tg(exp)(luaL_checknumber(L, 1)));
139148 return 1;
140149 }
141150
@@ -151,13 +160,14 @@ static int math_rad (lua_State *L) { · 9 unmodified lines
151160
152161 static int math_frexp (lua_State *L) {
153162 int e;
154− lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
163+ lua_pushnumber(L, l_tg(frexp)(luaL_checknumber(L, 1), &e));
155164 lua_pushinteger(L, e);
156165 return 2;
157166 }
158167
159168 static int math_ldexp (lua_State *L) {
160− lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
169+ lua_pushnumber(L, l_tg(ldexp)(luaL_checknumber(L, 1),
170+ luaL_checkint(L, 2)));
161171 return 1;
162172 }
163173
@@ -203,14 +213,14 @@ static int math_random (lua_State *L) { · 39 unmodified lines
203213 case 1: { /* only upper limit */
204214 lua_Number u = luaL_checknumber(L, 1);
205215 luaL_argcheck(L, 1.0 <= u, 1, "interval is empty");
206− lua_pushnumber(L, floor(r*u) + 1.0); /* int between 1 and `u' */
216+ lua_pushnumber(L, l_tg(floor)(r*u) + 1.0); /* int in [1, u] */
207217 break;
208218 }
209219 case 2: { /* lower and upper limits */
210220 lua_Number l = luaL_checknumber(L, 1);
211221 lua_Number u = luaL_checknumber(L, 2);
212222 luaL_argcheck(L, l <= u, 2, "interval is empty");
213− lua_pushnumber(L, floor(r*(u-l+1)) + l); /* int between `l' and `u' */
223+ lua_pushnumber(L, l_tg(floor)(r*(u-l+1)) + l); /* int in [l, u] */
214224 break;
215225 }
216226 default: return luaL_error(L, "wrong number of arguments");
src/loadlib.c+4−14
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loadlib.c,v 1.92 2010/10/29 14:35:09 roberto Exp $
2+** $Id: loadlib.c,v 1.94 2010/11/10 20:00:04 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 **
@@ -239,8 +239,7 @@ static void **ll_register (lua_State *L, const char *path) { · 233 unmodified lines
239239 lua_pop(L, 1); /* remove result from gettable */
240240 plib = (void **)lua_newuserdata(L, sizeof(const void *));
241241 *plib = NULL;
242− luaL_getmetatable(L, "_LOADLIB");
243− lua_setmetatable(L, -2);
242+ luaL_setmetatable(L, "_LOADLIB");
244243 lua_pushfstring(L, "%s%s", LIBPREFIX, path);
245244 lua_pushvalue(L, -2);
246245 lua_settable(L, LUA_REGISTRYINDEX);
@@ -435,21 +434,14 @@ static int loader_preload (lua_State *L) { · 188 unmodified lines
435434 }
436435
437436
438−static const int sentinel_ = 0;
439−#define sentinel ((void *)&sentinel_)
440−
441−
442437 static int ll_require (lua_State *L) {
443438 const char *name = luaL_checkstring(L, 1);
444439 int i;
445440 lua_settop(L, 1); /* _LOADED table will be at index 2 */
446441 lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
447442 lua_getfield(L, 2, name);
448− if (lua_toboolean(L, -1)) { /* is it there? */
449− if (lua_touserdata(L, -1) == sentinel) /* check loops */
450− luaL_error(L, "loop or previous error loading module " LUA_QS, name);
443+ if (lua_toboolean(L, -1)) /* is it there? */
451444 return 1; /* package is already loaded */
452− }
453445 /* else must load it; iterate over available loaders */
454446 lua_getfield(L, lua_upvalueindex(1), "loaders");
455447 if (!lua_istable(L, -1))
@@ -469,14 +461,12 @@ static int ll_require (lua_State *L) { · 13 unmodified lines
469461 else
470462 lua_pop(L, 1);
471463 }
472− lua_pushlightuserdata(L, sentinel);
473− lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
474464 lua_pushstring(L, name); /* pass name as argument to module */
475465 lua_call(L, 1, 1); /* run loaded module */
476466 if (!lua_isnil(L, -1)) /* non-nil return? */
477467 lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
478468 lua_getfield(L, 2, name);
479− if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
469+ if (lua_isnil(L, -1)) { /* module did not set a value? */
480470 lua_pushboolean(L, 1); /* use true as result */
481471 lua_pushvalue(L, -1); /* extra copy to be returned */
482472 lua_setfield(L, 2, name); /* _LOADED[name] = true */
src/lstrlib.c+25−8
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lstrlib.c,v 1.156 2010/10/29 17:52:46 roberto Exp $
2+** $Id: lstrlib.c,v 1.157 2010/11/08 17:38:37 roberto Exp $
33 ** Standard library for string operations and pattern-matching
44 ** See Copyright Notice in lua.h
55 */
@@ -722,6 +722,7 @@ static int str_gsub (lua_State *L) { · 716 unmodified lines
722722 ** 'string.format'; LUA_INTFRM_T is the integer type corresponding to
723723 ** the previous length
724724 */
725+#if !defined(LUA_INTFRMLEN) /* { */
725726 #if defined(LUA_USELONGLONG)
726727
727728 #define LUA_INTFRMLEN "ll"
@@ -732,6 +733,20 @@ static int str_gsub (lua_State *L) { · 4 unmodified lines
732733 #define LUA_INTFRMLEN "l"
733734 #define LUA_INTFRM_T long
734735
736+#endif
737+#endif /* } */
738+
739+
740+/*
741+** LUA_FLTFRMLEN is the length modifier for float conversions in
742+** 'string.format'; LUA_FLTFRM_T is the float type corresponding to
743+** the previous length
744+*/
745+#if !defined(LUA_FLTFRMLEN)
746+
747+#define LUA_FLTFRMLEN ""
748+#define LUA_FLTFRM_T double
749+
735750 #endif
736751
737752
@@ -793,14 +808,15 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { · 55 unmodified lines
793808
794809
795810 /*
796−** add length modifier into integer formats
811+** add length modifier into formats
797812 */
798−static void addintlen (char *form) {
813+static void addlenmod (char *form, const char *lenmod) {
799814 size_t l = strlen(form);
815+ size_t lm = strlen(lenmod);
800816 char spec = form[l - 1];
801− strcpy(form + l - 1, LUA_INTFRMLEN);
802− form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
803− form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
817+ strcpy(form + l - 1, lenmod);
818+ form[l + lm - 1] = spec;
819+ form[l + lm] = '\0';
804820 }
805821
806822
@@ -834,13 +850,14 @@ static int str_format (lua_State *L) { · 27 unmodified lines
834850 lua_Number n = luaL_checknumber(L, arg);
835851 LUA_INTFRM_T r = (n < 0) ? (LUA_INTFRM_T)n :
836852 (LUA_INTFRM_T)(unsigned LUA_INTFRM_T)n;
837− addintlen(form);
853+ addlenmod(form, LUA_INTFRMLEN);
838854 nb = sprintf(buff, form, r);
839855 break;
840856 }
841857 case 'e': case 'E': case 'f':
842858 case 'g': case 'G': {
843− nb = sprintf(buff, form, (double)luaL_checknumber(L, arg));
859+ addlenmod(form, LUA_FLTFRMLEN);
860+ nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
844861 break;
845862 }
846863 case 'q': {
src/ltable.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ltable.c,v 2.52 2010/06/25 12:18:10 roberto Exp $
2+** $Id: ltable.c,v 2.53 2010/11/11 15:38:43 roberto Exp $
33 ** Lua tables (hash)
44 ** See Copyright Notice in lua.h
55 */
@@ -38,8 +38,8 @@ · 32 unmodified lines
3838 /*
3939 ** max size of array part is 2^MAXBITS
4040 */
41−#if LUAI_BITSINT > 26
42−#define MAXBITS 26
41+#if LUAI_BITSINT >= 32
42+#define MAXBITS 30
4343 #else
4444 #define MAXBITS (LUAI_BITSINT-2)
4545 #endif
src/lua.h+1−1
@@ -18,7 +18,7 @@ · 17 unmodified lines
1818
1919 #define LUA_VERSION_MAJOR "5"
2020 #define LUA_VERSION_MINOR "2"
21−#define LUA_VERSION_RELEASE "0" " (work5)"
21+#define LUA_VERSION_RELEASE "0" " (alpha)"
2222
2323 #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
2424 #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
src/luaconf.h+13−115
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luaconf.h,v 1.148 2010/10/29 17:52:46 roberto Exp $
2+** $Id: luaconf.h,v 1.151 2010/11/12 15:48:30 roberto Exp $
33 ** Configuration file for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -229,7 +229,7 @@ · 223 unmodified lines
229229 ** You can define it to get all options, or change specific options
230230 ** to fit your specific needs.
231231 */
232−#if defined(LUA_COMPAT_ALL)
232+#if defined(LUA_COMPAT_ALL) /* { */
233233
234234 /*
235235 @@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
@@ -238,8 +238,8 @@ · 2 unmodified lines
238238 #define LUA_COMPAT_UNPACK
239239
240240 /*
241−@@ LUA_COMPAT_CPCALL controls the presence of macro 'lua_cpcall'.
242−** You can call your C function directly (with light C functions)
241+@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
242+** You can call your C function directly (with light C functions).
243243 */
244244 #define lua_cpcall(L,f,u) \
245245 (lua_pushcfunction(L, (f)), \
@@ -258,14 +258,6 @@ · 12 unmodified lines
258258 */
259259 #define LUA_COMPAT_MAXN
260260
261−/*
262−@@ LUA_COMPAT_DEBUGLIB controls compatibility with preloading
263−** the debug library.
264−** You should add 'require"debug"' everywhere you need the debug
265−** library.
266−*/
267−#define LUA_COMPAT_DEBUGLIB
268−
269261 /*
270262 @@ The following macros supply trivial compatibility for some
271263 ** changes in the API. The macros themselves document how to
@@ -275,19 +267,16 @@ · 3 unmodified lines
275267
276268 #define lua_objlen(L,i) lua_rawlen(L, (i))
277269
278−#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
270+#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
279271 #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
280272
281−/* compatibility with previous wrong spelling */
282−#define luaL_typerror luaL_typeerror
283−
284273 /*
285274 @@ LUA_COMPAT_MODULE controls compatibility with previous
286275 ** module functions 'module' (Lua) and 'luaL_register' (C).
287276 */
288277 #define LUA_COMPAT_MODULE
289278
290−#endif /* LUA_COMPAT_ALL */
279+#endif /* } */
291280
292281 /* }================================================================== */
293282
@@ -348,27 +337,13 @@ · 54 unmodified lines
348337
349338
350339
351−/*
352−** {==================================================================
353−** CHANGE (to smaller values) the following definitions if your system
354−** has a small C stack. (Or you may want to change them to larger
355−** values if your system has a large C stack and these limits are
356−** too rigid for you.) Some of these constants control the size of
357−** stack-allocated arrays used by the compiler or the interpreter, while
358−** others limit the maximum number of recursive calls that the compiler
359−** or the interpreter can perform. Values too large may cause a C stack
360−** overflow for some forms of deep constructs.
361−** ===================================================================
362−*/
363−
364340
365341 /*
366342 @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
343+** CHANGE it if it uses too much C-stack space.
367344 */
368345 #define LUAL_BUFFERSIZE BUFSIZ
369346
370−/* }================================================================== */
371−
372347
373348
374349
@@ -445,32 +420,21 @@ · 70 unmodified lines
445420 #define LUA_UNSIGNED unsigned LUA_INT32
446421
447422
448−/*
449−@@ lua_number2int is a macro to convert lua_Number to int.
450−@@ lua_number2integer is a macro to convert lua_Number to LUA_INTEGER.
451−@@ lua_number2uint is a macro to convert a lua_Number to a LUA_UNSIGNED.
452−@@ lua_uint2number is a macro to convert a LUA_UNSIGNED to a lua_Number.
453−*/
454−
455423 #if defined(LUA_CORE) /* { */
456424
457−#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && \
458− !defined(LUA_NOIEEE754TRICK) /* { */
425+#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
459426
460427 /* On a Microsoft compiler on a Pentium, use assembler to avoid clashes
461428 with a DirectX idiosyncrasy */
462429 #if defined(_MSC_VER) && defined(M_IX86) /* { */
463430
464−#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
465−#define lua_number2integer(i,n) lua_number2int(i, n)
466−#define lua_number2uint(i,n) \
467− {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
431+#define MS_ASMTRICK
468432
469433 #else /* }{ */
470−/* the next trick should work on any machine using IEEE754 with
471− a 32-bit integer type */
434+/* the next definition uses a trick that should work on any machine
435+ using IEEE754 with a 32-bit integer type */
472436
473−union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
437+#define LUA_IEEE754TRICK
474438
475439 /*
476440 @@ LUA_IEEEENDIAN is the endianness of doubles in your machine
@@ -485,77 +449,11 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; · 8 unmodified lines
485449 #define LUA_IEEEENDIAN 1
486450 #endif
487451
488−#if !defined(LUA_IEEEENDIAN) /* { */
489−#define LUAI_EXTRAIEEE \
490− static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
491−#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33)
492−#else
493−#define LUAI_EXTRAIEEE /* empty */
494−#endif /* } */
495−
496−#define lua_number2int32(i,n,t) \
497− { LUAI_EXTRAIEEE \
498− volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
499− (i) = (t)u.l_p[LUA_IEEEENDIAN]; }
500−
501−#define lua_number2int(i,n) lua_number2int32(i, n, int)
502−#define lua_number2integer(i,n) lua_number2int32(i, n, LUA_INTEGER)
503−#define lua_number2uint(i,n) lua_number2int32(i, n, LUA_UNSIGNED)
504−
505452 #endif /* } */
506453
507−
508454 #endif /* } */
509455
510−
511−/* the following definitions always work, but may be slow */
512−
513−#if !defined(lua_number2int)
514−#define lua_number2int(i,n) ((i)=(int)(n))
515−#endif
516−
517−#if !defined(lua_number2integer)
518−#define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n))
519−#endif
520−
521−#if !defined(lua_number2uint) && (defined(lapi_c) || defined(luaall_c)) /* { */
522−/* the following definition assures proper modulo behavior */
523−#if defined(LUA_NUMBER_DOUBLE)
524−#include <math.h>
525−#define lua_number2uint(i,n) \
526− ((i)=(LUA_UNSIGNED)((n) - floor((n)/4294967296.0)*4294967296.0))
527−#else
528−#define lua_number2uint(i,n) ((i)=(LUA_UNSIGNED)(n))
529−#endif
530−#endif /* } */
531−
532−#if !defined(lua_uint2number)
533−/* on several machines, coercion from unsigned to double is slow,
534− so it may be worth to avoid */
535−#define lua_uint2number(u) \
536− ((LUA_INT32)(u) < 0 ? (lua_Number)(u) : (lua_Number)(LUA_INT32)(u))
537−#endif
538−
539−#endif /* } */
540−
541−
542−/*
543−@@ luai_hashnum is a macro do hash a lua_Number value into an integer.
544−@* The hash must be deterministic and give reasonable values for
545−@* both small and large values (outside the range of integers).
546−@* It is used only in ltable.c.
547−*/
548−
549−#if defined(ltable_c) || defined(luaall_c)
550−
551−#include <float.h>
552−#include <math.h>
553−
554−#define luai_hashnum(i,n) { int e; \
555− n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
556− lua_number2int(i, n); i += e; }
557−
558−#endif /* ltable_c */
456+#endif /* } */
559457
560458 /* }================================================================== */
561459