summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2010-11-16 12:00:00 +0000
committerrepogen <>2010-11-16 12:00:00 +0000
commitccd28dfe034d5dfd130e5378a147e3e9fe7f6807 (patch)
treef1c922e8064f556c1034511afbbb3376640c4d27
parentd4bba06f4b8264eee00b25ee08e982d348486aaf (diff)
downloadlua-github-5.2.0-alpha-rc1.tar.gz
Lua 5.2.0-alpha-rc15.2.0-alpha-rc1
-rw-r--r--README2
-rw-r--r--doc/contents.html14
-rw-r--r--doc/manual.html100
-rw-r--r--doc/readme.html15
-rw-r--r--src/Makefile4
-rw-r--r--src/lapi.c6
-rw-r--r--src/lauxlib.c16
-rw-r--r--src/lauxlib.h4
-rw-r--r--src/lbitlib.c4
-rw-r--r--src/ldblib.c13
-rw-r--r--src/linit.c5
-rw-r--r--src/liolib.c44
-rw-r--r--src/llimits.h92
-rw-r--r--src/lmathlib.c66
-rw-r--r--src/loadlib.c18
-rw-r--r--src/lstrlib.c33
-rw-r--r--src/ltable.c6
-rw-r--r--src/lua.h2
-rw-r--r--src/luaconf.h128
19 files changed, 286 insertions, 286 deletions
diff --git a/README b/README
index 37c89345..bc7accfe 100644
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
-This is Lua 5.2 (work5), released on 30 Oct 2010.
+This is Lua 5.2 (alpha), released on 16 Nov 2010.
For installation instructions, license details, and
further information about Lua, see doc/readme.html.
diff --git a/doc/contents.html b/doc/contents.html
index 35b51d02..199af668 100644
--- a/doc/contents.html
+++ b/doc/contents.html
@@ -22,8 +22,8 @@ Lua 5.2 Reference Manual
<P>
<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
-<EM>This is a work version of Lua 5.2.
-Everything may change in the final version.</EM>
+<EM>This is an alpha version of Lua 5.2.
+Some details may change in the final version.</EM>
<P>
The reference manual is the official definition of the Lua language.
@@ -52,7 +52,7 @@ Freely available under the terms of the
<LI><A HREF="manual.html#2.1">2.1 &ndash; Values and Types</A>
<LI><A HREF="manual.html#2.2">2.2 &ndash; Environments and the Global Environment</A>
<LI><A HREF="manual.html#2.3">2.3 &ndash; Error Handling</A>
-<LI><A HREF="manual.html#2.4">2.4 &ndash; Metatables</A>
+<LI><A HREF="manual.html#2.4">2.4 &ndash; Metatables and Metamethods</A>
<LI><A HREF="manual.html#2.5">2.5 &ndash; Garbage Collection</A>
<UL>
<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
<A HREF="manual.html#luaL_newlib">luaL_newlib</A><BR>
<A HREF="manual.html#luaL_newmetatable">luaL_newmetatable</A><BR>
<A HREF="manual.html#luaL_newstate">luaL_newstate</A><BR>
-<A HREF="manual.html#luaL_setfuncs">luaL_setfuncs</A><BR>
<A HREF="manual.html#luaL_openlibs">luaL_openlibs</A><BR>
<A HREF="manual.html#luaL_optint">luaL_optint</A><BR>
<A HREF="manual.html#luaL_optinteger">luaL_optinteger</A><BR>
@@ -497,11 +496,12 @@ Freely available under the terms of the
<A HREF="manual.html#luaL_pushresult">luaL_pushresult</A><BR>
<A HREF="manual.html#luaL_ref">luaL_ref</A><BR>
<A HREF="manual.html#luaL_requiref">luaL_requiref</A><BR>
+<A HREF="manual.html#luaL_setfuncs">luaL_setfuncs</A><BR>
+<A HREF="manual.html#luaL_setmetatable">luaL_setmetatable</A><BR>
<A HREF="manual.html#luaL_testudata">luaL_testudata</A><BR>
<A HREF="manual.html#luaL_tolstring">luaL_tolstring</A><BR>
<A HREF="manual.html#luaL_traceback">luaL_traceback</A><BR>
<A HREF="manual.html#luaL_typename">luaL_typename</A><BR>
-<A HREF="manual.html#luaL_typeerror">luaL_typeerror</A><BR>
<A HREF="manual.html#luaL_unref">luaL_unref</A><BR>
<A HREF="manual.html#luaL_where">luaL_where</A><BR>
@@ -512,10 +512,10 @@ Freely available under the terms of the
<HR>
<SMALL>
Last update:
-Sat Oct 30 21:34:44 BRST 2010
+Tue Nov 16 09:56:07 BRST 2010
</SMALL>
<!--
-Last change: revised for Lua 5.2.0 (work5)
+Last change: revised for Lua 5.2.0 (alpha)
-->
</BODY>
diff --git a/doc/manual.html b/doc/manual.html
index c97b88c1..db1af8c8 100644
--- a/doc/manual.html
+++ b/doc/manual.html
@@ -17,8 +17,8 @@ Lua 5.2 Reference Manual
</h1>
<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
-<EM>This is a work version of Lua 5.2.
-Everything may change in the final version.</EM>
+<EM>This is an alpha version of Lua 5.2.
+Some details may change in the final version.</EM>
<P>
by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes
@@ -38,7 +38,7 @@ Freely available under the terms of the
<!-- ====================================================================== -->
<p>
-<!-- $Id: manual.of,v 1.61 2010/10/29 12:51:39 roberto Exp $ -->
+<!-- $Id: manual.of,v 1.62 2010/11/16 11:38:25 roberto Exp $ -->
@@ -287,7 +287,7 @@ you can use the <a href="#pdf-pcall"><code>pcall</code></a> function.
-<h2>2.4 &ndash; <a name="2.4">Metatables</a></h2>
+<h2>2.4 &ndash; <a name="2.4">Metatables and Metamethods</a></h2>
<p>
Every value in Lua can have a <em>metatable</em>.
@@ -305,7 +305,7 @@ Lua calls this function to perform the addition.
<p>
We call the keys in a metatable <em>events</em>
and the values <em>metamethods</em>.
-In the previous example, the event is <code>"add"</code>
+In the previous example, the event is <code>"__add"</code>
and the metamethod is the function that performs the addition.
@@ -383,7 +383,7 @@ and the access to objects with no metatables does not fail
<p>
For the unary <code>-</code> and <code>#</code> operators,
-the metamethod is called repeating the first argument as a second argument.
+the metamethod is called with a dummy second argument.
This extra argument is only to simplify Lua's internals;
it may be removed in future versions and therefore it is not present
in the following code.
@@ -2731,13 +2731,12 @@ It is used in the auxiliary library by <a href="#luaL_newstate"><code>luaL_newst
return realloc(ptr, nsize);
}
</pre><p>
-This code assumes
+Note that ANSI&nbsp;C ensures
that <code>free(NULL)</code> has no effect and that
<code>realloc(NULL, size)</code> is equivalent to <code>malloc(size)</code>.
-ANSI&nbsp;C ensures both behaviors.
-It also assumes that <code>realloc</code> does not fail when shrinking a block.
-(ANSI&nbsp;C does not ensure this behavior,
-but it seems a safe assumption.)
+This code assumes that <code>realloc</code> does not fail when shrinking a block.
+ANSI&nbsp;C does not ensure this behavior,
+but it seems a safe assumption.
@@ -5989,6 +5988,19 @@ These values are popped from the stack after the registration.
+<hr><h3><a name="luaL_setmetatable"><code>luaL_setmetatable</code></a></h3><p>
+<span class="apii">[-0, +0, <em>-</em>]</span>
+<pre>void luaL_setmetatable (lua_State *L, const char *tname);</pre>
+
+<p>
+Sets the metatable of the object at the top of the stack
+as the metatable associated with name <code>tname</code>
+in the registry (see <a href="#luaL_newmetatable"><code>luaL_newmetatable</code></a>).
+
+
+
+
+
<hr><h3><a name="luaL_openlibs"><code>luaL_openlibs</code></a></h3><p>
<span class="apii">[-0, +0, <em>e</em>]</span>
<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.
-<hr><h3><a name="luaL_typeerror"><code>luaL_typeerror</code></a></h3><p>
-<span class="apii">[-0, +0, <em>v</em>]</span>
-<pre>int luaL_typeerror (lua_State *L, int narg, const char *tname);</pre>
-
-<p>
-Generates an error with a message like the following:
-
-<pre>
- <em>location</em>: bad argument <em>narg</em> to '<em>func</em>' (<em>tname</em> expected, got <em>rt</em>)
-</pre><p>
-where <code><em>location</em></code> is produced by <a href="#luaL_where"><code>luaL_where</code></a>,
-<code><em>func</em></code> is the name of the current function,
-and <code><em>rt</em></code> is the type name of the actual argument.
-
-
-
-
-
<hr><h3><a name="luaL_unref"><code>luaL_unref</code></a></h3><p>
<span class="apii">[-0, +0, <em>-</em>]</span>
<pre>void luaL_unref (lua_State *L, int t, int ref);</pre>
@@ -7020,8 +7014,6 @@ In case of error, propagates the error.
<p>
Suspends the execution of the calling coroutine.
-The coroutine cannot be running a C&nbsp;function,
-a metamethod, or an iterator.
Any arguments to <code>yield</code> are passed as extra results to <code>resume</code>.
@@ -8586,20 +8578,13 @@ instead of returning an error code.
<p>
-<hr><h3><a name="pdf-io.lines"><code>io.lines ([filename] [, keepNL])</code></a></h3>
+<hr><h3><a name="pdf-io.lines"><code>io.lines ([filename] &middot;&middot;&middot;)</code></a></h3>
<p>
Opens the given file name in read mode
-and returns an iterator function that,
-each time it is called,
-returns a new line from the file.
-Therefore, the construction
-
-<pre>
- for line in io.lines(filename) do <em>body</em> end
-</pre><p>
-will iterate over all lines of the file.
+and returns an iterator function that
+works like <code>file:lines(&middot;&middot;&middot;)</code> over the oppened file.
When the iterator function detects the end of file,
it returns <b>nil</b> (to finish the loop) and automatically closes the file.
@@ -8611,11 +8596,6 @@ that is, it iterates over the lines of the default input file.
In this case it does not close the file when the loop ends.
-<p>
-By default, <code>lines</code> removes the newline at the end of each line.
-If <code>keepNL</code> is <b>true</b>, it will keep the newlines.
-
-
<p>
@@ -8750,29 +8730,26 @@ Saves any written data to <code>file</code>.
<p>
-<hr><h3><a name="pdf-file:lines"><code>file:lines ([keepNL])</code></a></h3>
+<hr><h3><a name="pdf-file:lines"><code>file:lines (&middot;&middot;&middot;)</code></a></h3>
<p>
Returns an iterator function that,
each time it is called,
-returns a new line from the file.
+reads the file according to the given formats.
+When no format is given,
+uses "*l" as a default.
Therefore, the construction
<pre>
- for line in file:lines() do <em>body</em> end
+ for c in file:lines(1) do <em>body</em> end
</pre><p>
-will iterate over all lines of the file,
+will iterate over all characters of the file,
starting at the current position.
(Unlike <a href="#pdf-io.lines"><code>io.lines</code></a>, this function does not close the file
when the loop ends.)
-<p>
-By default, <code>lines</code> removes the newline at the end of each line.
-If <code>keepNL</code> is <b>true</b>, it will keep the newlines.
-
-
<p>
@@ -9674,11 +9651,6 @@ and it is easy to set up a module with regular Lua code.
</li>
<li>
-The debug library is not loaded by default.
-You must explicitly require it.
-</li>
-
-<li>
Functions <code>setfenv</code> and <code>getfenv</code> are deprecated.
To set the environment of a Lua function,
use the variable <code>_ENV</code> or the new function <a href="#pdf-loadin"><code>loadin</code></a>.
@@ -9767,8 +9739,8 @@ even if it is set later.
</li>
<li>
-<code>luaL_typerror</code> was renamed <a href="#luaL_typeerror"><code>luaL_typeerror</code></a>,
-to have a correct spelling.
+<code>luaL_typerror</code> was deprecated.
+Write your own version if you need it.
</li>
<li>
@@ -9873,10 +9845,10 @@ Here is the complete syntax of Lua in extended BNF.
<HR>
<SMALL>
Last update:
-Sat Oct 30 21:36:20 BRST 2010
+Tue Nov 16 09:52:41 BRST 2010
</SMALL>
<!--
-Last change: revised for Lua 5.2.0 (work5)
+Last change: revised for Lua 5.2.0 (alpha)
-->
</body></html>
diff --git a/doc/readme.html b/doc/readme.html
index 55919999..9b0f9260 100644
--- a/doc/readme.html
+++ b/doc/readme.html
@@ -27,13 +27,13 @@ tt, kbd, code {
<HR>
<H1>
<A HREF="http://www.lua.org/"><IMG SRC="logo.gif" ALT="Lua" BORDER=0></A>
-Welcome to Lua 5.2 (work5)
+Welcome to Lua 5.2 (alpha)
</H1>
<P>
<IMG SRC="alert.png" ALIGN="absbottom" ALT="[!]">
-<EM>This is a work version of Lua 5.2.
-Everything may change in the final version.</EM>
+<EM>This is an alpha version of Lua 5.2.
+Some details may change in the final version.</EM>
<P>
<A HREF="#about">about</A>
@@ -323,12 +323,13 @@ Here are the other changes introduced in Lua 5.2:
<LI> new <CODE>lua_compare</CODE>, <CODE>lua_arith</CODE>, and <CODE>lua_len</CODE>
<LI> new <CODE>lua_version</CODE> and <CODE>luaL_version</CODE>
<LI> <CODE>lua_pushstring</CODE> and <CODE>pushlstring</CODE> return string
-<LI> new <CODE>luaL_testudata</CODE>
+<LI> new <CODE>luaL_testudata</CODE> and <CODE>luaL_setmetatable</CODE>
<LI> new <CODE>luaL_tolstring</CODE>
<LI> new <CODE>lua_copy</CODE>
<LI> new <CODE>lua_absindex</CODE>
<LI> new <CODE>lua_upvalueid</CODE> and <CODE>lua_upvaluejoin</CODE>
<LI> <CODE>nparams</CODE> and <CODE>isvarag</CODE> available in debug API
+<LI> new <CODE>lua_Unsigned</CODE>
</UL>
<H3>Implementation</H3>
@@ -337,7 +338,7 @@ Here are the other changes introduced in Lua 5.2:
<LI> internal (immutable) version of ctypes
<LI> simpler implementation for string buffers
<LI> udata with finalizers are kept in a separated list for the GC
-<LI> <CODE>CallInfo</CODE>stack now is a linked list
+<LI> <CODE>CallInfo</CODE> stack now is a linked list
<LI> parser uses much less C-stack space (no more auto arrays)
<LI> new hash for floats
<LI> handling of non-string error messages in the standalone interpreter
@@ -390,10 +391,10 @@ THE SOFTWARE.
<HR>
<SMALL>
Last update:
-Sat Oct 30 21:36:38 BRST 2010
+Thu Nov 11 15:16:22 BRST 2010
</SMALL>
<!--
-Last change: revised for Lua 5.2.0 (work5)
+Last change: revised for Lua 5.2.0 (alpha)
-->
</BODY>
diff --git a/src/Makefile b/src/Makefile
index 61ad180e..b8cee9c6 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -7,7 +7,7 @@
PLAT= none
CC= gcc
-CFLAGS= -O2 -Wall $(MYCFLAGS)
+CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(MYCFLAGS)
LIBS= -lm $(MYLIBS)
AR= ar rcu
@@ -97,7 +97,7 @@ freebsd:
generic: $(ALL)
linux:
- $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline -lncurses"
+ $(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -ldl -lreadline"
macosx:
$(MAKE) $(ALL) MYCFLAGS="-DLUA_USE_MACOSX" MYLIBS="-lreadline"
diff --git a/src/lapi.c b/src/lapi.c
index 094d623b..074979c3 100644
--- a/src/lapi.c
+++ b/src/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 2.139 2010/10/25 20:31:11 roberto Exp $
+** $Id: lapi.c,v 2.140 2010/11/03 15:16:17 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -353,7 +353,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *isnum) {
if (tonumber(o, &n)) {
lua_Unsigned res;
lua_Number num = nvalue(o);
- lua_number2uint(res, num);
+ lua_number2unsigned(res, num);
if (isnum) *isnum = 1;
return res;
}
@@ -472,7 +472,7 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) {
lua_Number n;
lua_lock(L);
- n = lua_uint2number(u);
+ n = lua_unsigned2number(u);
setnvalue(L->top, n);
api_incr_top(L);
lua_unlock(L);
diff --git a/src/lauxlib.c b/src/lauxlib.c
index 807c5522..cdd5a53f 100644
--- a/src/lauxlib.c
+++ b/src/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.224 2010/10/29 12:52:21 roberto Exp $
+** $Id: lauxlib.c,v 1.227 2010/11/10 18:05:36 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -168,7 +168,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
}
-LUALIB_API int luaL_typeerror (lua_State *L, int narg, const char *tname) {
+static int typeerror (lua_State *L, int narg, const char *tname) {
const char *msg = lua_pushfstring(L, "%s expected, got %s",
tname, luaL_typename(L, narg));
return luaL_argerror(L, narg, msg);
@@ -176,7 +176,7 @@ LUALIB_API int luaL_typeerror (lua_State *L, int narg, const char *tname) {
static void tag_error (lua_State *L, int narg, int tag) {
- luaL_typeerror(L, narg, lua_typename(L, tag));
+ typeerror(L, narg, lua_typename(L, tag));
}
@@ -224,6 +224,12 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
}
+LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {
+ luaL_getmetatable(L, tname);
+ lua_setmetatable(L, -2);
+}
+
+
LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
void *p = lua_touserdata(L, ud);
if (p != NULL) { /* value is a userdata? */
@@ -241,7 +247,7 @@ LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
void *p = luaL_testudata(L, ud, tname);
- if (p == NULL) luaL_typeerror(L, ud, tname);
+ if (p == NULL) typeerror(L, ud, tname);
return p;
}
@@ -377,7 +383,7 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
if (newsize - B->n < sz) /* not bit enough? */
newsize = B->n + sz;
if (newsize < B->n || newsize - B->n < sz)
- luaL_error(L, "string too large");
+ luaL_error(L, "buffer too large");
newbuff = (char *)lua_newuserdata(L, newsize); /* create larger buffer */
memcpy(newbuff, B->b, B->n); /* move content to new buffer */
if (buffonstack(B))
diff --git a/src/lauxlib.h b/src/lauxlib.h
index 504fdf58..f4e31bc8 100644
--- a/src/lauxlib.h
+++ b/src/lauxlib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.h,v 1.109 2010/10/25 20:31:11 roberto Exp $
+** $Id: lauxlib.h,v 1.111 2010/11/10 18:05:36 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -32,7 +32,6 @@ LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver);
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
-LUALIB_API int (luaL_typeerror) (lua_State *L, int narg, const char *tname);
LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
size_t *l);
@@ -53,6 +52,7 @@ LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
+LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
diff --git a/src/lbitlib.c b/src/lbitlib.c
index e93575e6..b37344f3 100644
--- a/src/lbitlib.c
+++ b/src/lbitlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbitlib.c,v 1.10 2010/10/28 15:17:29 roberto Exp $
+** $Id: lbitlib.c,v 1.11 2010/11/08 16:31:22 roberto Exp $
** Standard library for bitwise operations
** See Copyright Notice in lua.h
*/
@@ -108,7 +108,7 @@ static int b_rshift (lua_State *L) {
static int b_arshift (lua_State *L) {
b_uint r = getuintarg(L, 1);
int i = luaL_checkint(L, 2);
- if (i < 0 || !(r & (1 << (NBITS - 1))))
+ if (i < 0 || !(r & ((b_uint)1 << (NBITS - 1))))
return b_shift(L, r, -i);
else { /* arithmetic shift for 'negative' number */
if (i >= NBITS) r = ALLONES;
diff --git a/src/ldblib.c b/src/ldblib.c
index 9ae6f86b..04213159 100644
--- a/src/ldblib.c
+++ b/src/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.124 2010/07/25 15:18:19 roberto Exp $
+** $Id: ldblib.c,v 1.125 2010/11/10 18:06:10 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -44,15 +44,22 @@ static int db_setmetatable (lua_State *L) {
}
+static void checkudata (lua_State *L, int narg) {
+ if (lua_type(L, narg) == LUA_TLIGHTUSERDATA)
+ luaL_argerror(L, narg, "full userdata expected, got light userdata");
+ luaL_checktype(L, narg, LUA_TUSERDATA);
+}
+
+
static int db_getuservalue (lua_State *L) {
- luaL_checktype(L, 1, LUA_TUSERDATA);
+ checkudata(L, 1);
lua_getuservalue(L, 1);
return 1;
}
static int db_setuservalue (lua_State *L) {
- luaL_checktype(L, 1, LUA_TUSERDATA);
+ checkudata(L, 1);
if (!lua_isnoneornil(L, 2))
luaL_checktype(L, 2, LUA_TTABLE);
lua_settop(L, 2);
diff --git a/src/linit.c b/src/linit.c
index ecde4915..fa944671 100644
--- a/src/linit.c
+++ b/src/linit.c
@@ -1,5 +1,5 @@
/*
-** $Id: linit.c,v 1.29 2010/10/25 14:32:36 roberto Exp $
+** $Id: linit.c,v 1.30 2010/11/12 15:48:30 roberto Exp $
** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h
*/
@@ -36,9 +36,7 @@ static const luaL_Reg loadedlibs[] = {
{LUA_STRLIBNAME, luaopen_string},
{LUA_BITLIBNAME, luaopen_bit32},
{LUA_MATHLIBNAME, luaopen_math},
-#if defined(LUA_COMPAT_DEBUGLIB)
{LUA_DBLIBNAME, luaopen_debug},
-#endif
{NULL, NULL}
};
@@ -47,7 +45,6 @@ static const luaL_Reg loadedlibs[] = {
** these libs are preloaded and must be required before used
*/
static const luaL_Reg preloadedlibs[] = {
- {LUA_DBLIBNAME, luaopen_debug},
{NULL, NULL}
};
diff --git a/src/liolib.c b/src/liolib.c
index 6574e8b6..658601ad 100644
--- a/src/liolib.c
+++ b/src/liolib.c
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 2.92 2010/10/25 19:01:37 roberto Exp $
+** $Id: liolib.c,v 2.95 2010/11/10 18:05:36 roberto Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -19,6 +19,9 @@
#include "lualib.h"
+#define MAX_SIZE_T (~(size_t)0)
+
+
/*
** lua_popen spawns a new process connected to the current one through
** the file streams.
@@ -111,8 +114,7 @@ static FILE *tofile (lua_State *L) {
static FILE **newprefile (lua_State *L) {
FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
*pf = NULL; /* file handle is currently `closed' */
- luaL_getmetatable(L, LUA_FILEHANDLE);
- lua_setmetatable(L, -2);
+ luaL_setmetatable(L, LUA_FILEHANDLE);
return pf;
}
@@ -371,22 +373,32 @@ static int read_line (lua_State *L, FILE *f, int chop) {
}
-static int read_chars (lua_State *L, FILE *f, size_t n) {
- size_t tbr = n; /* number of chars to be read */
- size_t rlen; /* how much to read in each cycle */
- size_t nr; /* number of chars actually read in each cycle */
+static void read_all (lua_State *L, FILE *f) {
+ size_t rlen = LUAL_BUFFERSIZE; /* how much to read in each cycle */
luaL_Buffer b;
luaL_buffinit(L, &b);
- rlen = LUAL_BUFFERSIZE; /* try to read that much each time */
- do {
- char *p = luaL_prepbuffer(&b);
- if (rlen > tbr) rlen = tbr; /* cannot read more than asked */
- nr = fread(p, sizeof(char), rlen, f);
+ for (;;) {
+ char *p = luaL_prepbuffsize(&b, rlen);
+ size_t nr = fread(p, sizeof(char), rlen, f);
luaL_addsize(&b, nr);
- tbr -= nr; /* still have to read 'tbr' chars */
- } while (tbr > 0 && nr == rlen); /* until end of count or eof */
+ if (nr < rlen) break; /* eof? */
+ else if (rlen <= (MAX_SIZE_T / 4)) /* avoid buffers too large */
+ rlen *= 2; /* double buffer size at each iteration */
+ }
+ luaL_pushresult(&b); /* close buffer */
+}
+
+
+static int read_chars (lua_State *L, FILE *f, size_t n) {
+ size_t nr; /* number of chars actually read */
+ char *p;
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */
+ nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */
+ luaL_addsize(&b, nr);
luaL_pushresult(&b); /* close buffer */
- return (tbr < n); /* true iff read something */
+ return (nr > 0); /* true iff read something */
}
@@ -421,7 +433,7 @@ static int g_read (lua_State *L, FILE *f, int first) {
success = read_line(L, f, 0);
break;
case 'a': /* file */
- read_chars(L, f, ~((size_t)0)); /* read MAX_SIZE_T chars */
+ read_all(L, f); /* read entire file */
success = 1; /* always success */
break;
default:
diff --git a/src/llimits.h b/src/llimits.h
index 4b75a84e..f8ede143 100644
--- a/src/llimits.h
+++ b/src/llimits.h
@@ -1,5 +1,5 @@
/*
-** $Id: llimits.h,v 1.82 2010/05/31 16:08:55 roberto Exp $
+** $Id: llimits.h,v 1.84 2010/11/08 16:33:20 roberto Exp $
** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h
*/
@@ -168,6 +168,96 @@ typedef lu_int32 Instruction;
#define luai_userstateyield(L,n) ((void)L)
#endif
+/*
+** lua_number2int is a macro to convert lua_Number to int.
+** lua_number2integer is a macro to convert lua_Number to lua_Integer.
+** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned.
+** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number.
+*/
+
+#if defined(MS_ASMTRICK) /* { */
+/* trick with Microsoft assembler for X86 */
+
+#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
+#define lua_number2integer(i,n) lua_number2int(i, n)
+#define lua_number2unsigned(i,n) \
+ {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
+
+
+#elif defined(LUA_IEEE754TRICK) /* }{ */
+/* the next trick should work on any machine using IEEE754 with
+ a 32-bit integer type */
+
+union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
+
+#if !defined(LUA_IEEEENDIAN) /* { */
+#define LUAI_EXTRAIEEE \
+ static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
+#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33)
+#else
+#define LUAI_EXTRAIEEE /* empty */
+#endif /* } */
+
+#define lua_number2int32(i,n,t) \
+ { LUAI_EXTRAIEEE \
+ volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
+ (i) = (t)u.l_p[LUA_IEEEENDIAN]; }
+
+#define lua_number2int(i,n) lua_number2int32(i, n, int)
+#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
+#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
+
+#endif /* } */
+
+
+/* the following definitions always work, but may be slow */
+
+#if !defined(lua_number2int)
+#define lua_number2int(i,n) ((i)=(int)(n))
+#endif
+
+#if !defined(lua_number2integer)
+#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
+#endif
+
+#if !defined(lua_number2unsigned) /* { */
+/* the following definition assures proper modulo behavior */
+#if defined(LUA_NUMBER_DOUBLE)
+#include <math.h>
+#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
+#define lua_number2unsigned(i,n) \
+ ((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
+#else
+#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n))
+#endif
+#endif /* } */
+
+
+#if !defined(lua_unsigned2number)
+/* on several machines, coercion from unsigned to double is slow,
+ so it may be worth to avoid */
+#define lua_unsigned2number(u) \
+ (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
+#endif
+
+
+/*
+** luai_hashnum is a macro do hash a lua_Number value into an integer.
+** The hash must be deterministic and give reasonable values for
+** both small and large values (outside the range of integers).
+** It is used only in ltable.c.
+*/
+
+#if !defined(luai_hashnum) /* { */
+
+#include <float.h>
+#include <math.h>
+
+#define luai_hashnum(i,n) { int e; \
+ n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
+ lua_number2int(i, n); i += e; }
+
+#endif /* } */
diff --git a/src/lmathlib.c b/src/lmathlib.c
index 13aebe9e..8494d80d 100644
--- a/src/lmathlib.c
+++ b/src/lmathlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmathlib.c,v 1.76 2010/10/25 20:31:11 roberto Exp $
+** $Id: lmathlib.c,v 1.78 2010/11/12 15:47:34 roberto Exp $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -22,92 +22,101 @@
#define RADIANS_PER_DEGREE (PI/180.0)
+/* macro 'l_tg' allows the addition of an 'l' or 'f' to all math operations */
+#if !defined(l_tg)
+#define l_tg(x) (x)
+#endif
+
+
static int math_abs (lua_State *L) {
- lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(fabs)(luaL_checknumber(L, 1)));
return 1;
}
static int math_sin (lua_State *L) {
- lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(sin)(luaL_checknumber(L, 1)));
return 1;
}
static int math_sinh (lua_State *L) {
- lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(sinh)(luaL_checknumber(L, 1)));
return 1;
}
static int math_cos (lua_State *L) {
- lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(cos)(luaL_checknumber(L, 1)));
return 1;
}
static int math_cosh (lua_State *L) {
- lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(cosh)(luaL_checknumber(L, 1)));
return 1;
}
static int math_tan (lua_State *L) {
- lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(tan)(luaL_checknumber(L, 1)));
return 1;
}
static int math_tanh (lua_State *L) {
- lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(tanh)(luaL_checknumber(L, 1)));
return 1;
}
static int math_asin (lua_State *L) {
- lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(asin)(luaL_checknumber(L, 1)));
return 1;
}
static int math_acos (lua_State *L) {
- lua_pushnumber(L, acos(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(acos)(luaL_checknumber(L, 1)));
return 1;
}
static int math_atan (lua_State *L) {
- lua_pushnumber(L, atan(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(atan)(luaL_checknumber(L, 1)));
return 1;
}
static int math_atan2 (lua_State *L) {
- lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
+ lua_pushnumber(L, l_tg(atan2)(luaL_checknumber(L, 1),
+ luaL_checknumber(L, 2)));
return 1;
}
static int math_ceil (lua_State *L) {
- lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(ceil)(luaL_checknumber(L, 1)));
return 1;
}
static int math_floor (lua_State *L) {
- lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(floor)(luaL_checknumber(L, 1)));
return 1;
}
static int math_fmod (lua_State *L) {
- lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
+ lua_pushnumber(L, l_tg(fmod)(luaL_checknumber(L, 1),
+ luaL_checknumber(L, 2)));
return 1;
}
static int math_modf (lua_State *L) {
- double ip;
- double fp = modf(luaL_checknumber(L, 1), &ip);
+ lua_Number ip;
+ lua_Number fp = l_tg(modf)(luaL_checknumber(L, 1), &ip);
lua_pushnumber(L, ip);
lua_pushnumber(L, fp);
return 2;
}
static int math_sqrt (lua_State *L) {
- lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(sqrt)(luaL_checknumber(L, 1)));
return 1;
}
static int math_pow (lua_State *L) {
- lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
+ lua_pushnumber(L, l_tg(pow)(luaL_checknumber(L, 1),
+ luaL_checknumber(L, 2)));
return 1;
}
@@ -115,11 +124,11 @@ static int math_log (lua_State *L) {
lua_Number x = luaL_checknumber(L, 1);
lua_Number res;
if (lua_isnoneornil(L, 2))
- res = log(x);
+ res = l_tg(log)(x);
else {
lua_Number base = luaL_checknumber(L, 2);
- if (base == 10.0) res = log10(x);
- else res = log(x)/log(base);
+ if (base == 10.0) res = l_tg(log10)(x);
+ else res = l_tg(log)(x)/l_tg(log)(base);
}
lua_pushnumber(L, res);
return 1;
@@ -130,12 +139,12 @@ static int math_log10 (lua_State *L) {
luaL_error(L, "function " LUA_QL("log10")
" is deprecated; use log(x, 10) instead");
#endif
- lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(log10)(luaL_checknumber(L, 1)));
return 1;
}
static int math_exp (lua_State *L) {
- lua_pushnumber(L, exp(luaL_checknumber(L, 1)));
+ lua_pushnumber(L, l_tg(exp)(luaL_checknumber(L, 1)));
return 1;
}
@@ -151,13 +160,14 @@ static int math_rad (lua_State *L) {
static int math_frexp (lua_State *L) {
int e;
- lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
+ lua_pushnumber(L, l_tg(frexp)(luaL_checknumber(L, 1), &e));
lua_pushinteger(L, e);
return 2;
}
static int math_ldexp (lua_State *L) {
- lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
+ lua_pushnumber(L, l_tg(ldexp)(luaL_checknumber(L, 1),
+ luaL_checkint(L, 2)));
return 1;
}
@@ -203,14 +213,14 @@ static int math_random (lua_State *L) {
case 1: { /* only upper limit */
lua_Number u = luaL_checknumber(L, 1);
luaL_argcheck(L, 1.0 <= u, 1, "interval is empty");
- lua_pushnumber(L, floor(r*u) + 1.0); /* int between 1 and `u' */
+ lua_pushnumber(L, l_tg(floor)(r*u) + 1.0); /* int in [1, u] */
break;
}
case 2: { /* lower and upper limits */
lua_Number l = luaL_checknumber(L, 1);
lua_Number u = luaL_checknumber(L, 2);
luaL_argcheck(L, l <= u, 2, "interval is empty");
- lua_pushnumber(L, floor(r*(u-l+1)) + l); /* int between `l' and `u' */
+ lua_pushnumber(L, l_tg(floor)(r*(u-l+1)) + l); /* int in [l, u] */
break;
}
default: return luaL_error(L, "wrong number of arguments");
diff --git a/src/loadlib.c b/src/loadlib.c
index 42cfb869..3e5eaecf 100644
--- a/src/loadlib.c
+++ b/src/loadlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loadlib.c,v 1.92 2010/10/29 14:35:09 roberto Exp $
+** $Id: loadlib.c,v 1.94 2010/11/10 20:00:04 roberto Exp $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
@@ -239,8 +239,7 @@ static void **ll_register (lua_State *L, const char *path) {
lua_pop(L, 1); /* remove result from gettable */
plib = (void **)lua_newuserdata(L, sizeof(const void *));
*plib = NULL;
- luaL_getmetatable(L, "_LOADLIB");
- lua_setmetatable(L, -2);
+ luaL_setmetatable(L, "_LOADLIB");
lua_pushfstring(L, "%s%s", LIBPREFIX, path);
lua_pushvalue(L, -2);
lua_settable(L, LUA_REGISTRYINDEX);
@@ -435,21 +434,14 @@ static int loader_preload (lua_State *L) {
}
-static const int sentinel_ = 0;
-#define sentinel ((void *)&sentinel_)
-
-
static int ll_require (lua_State *L) {
const char *name = luaL_checkstring(L, 1);
int i;
lua_settop(L, 1); /* _LOADED table will be at index 2 */
lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
lua_getfield(L, 2, name);
- if (lua_toboolean(L, -1)) { /* is it there? */
- if (lua_touserdata(L, -1) == sentinel) /* check loops */
- luaL_error(L, "loop or previous error loading module " LUA_QS, name);
+ if (lua_toboolean(L, -1)) /* is it there? */
return 1; /* package is already loaded */
- }
/* else must load it; iterate over available loaders */
lua_getfield(L, lua_upvalueindex(1), "loaders");
if (!lua_istable(L, -1))
@@ -469,14 +461,12 @@ static int ll_require (lua_State *L) {
else
lua_pop(L, 1);
}
- lua_pushlightuserdata(L, sentinel);
- lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
lua_pushstring(L, name); /* pass name as argument to module */
lua_call(L, 1, 1); /* run loaded module */
if (!lua_isnil(L, -1)) /* non-nil return? */
lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
lua_getfield(L, 2, name);
- if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
+ if (lua_isnil(L, -1)) { /* module did not set a value? */
lua_pushboolean(L, 1); /* use true as result */
lua_pushvalue(L, -1); /* extra copy to be returned */
lua_setfield(L, 2, name); /* _LOADED[name] = true */
diff --git a/src/lstrlib.c b/src/lstrlib.c
index f2132005..1cd37def 100644
--- a/src/lstrlib.c
+++ b/src/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.156 2010/10/29 17:52:46 roberto Exp $
+** $Id: lstrlib.c,v 1.157 2010/11/08 17:38:37 roberto Exp $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -722,6 +722,7 @@ static int str_gsub (lua_State *L) {
** 'string.format'; LUA_INTFRM_T is the integer type corresponding to
** the previous length
*/
+#if !defined(LUA_INTFRMLEN) /* { */
#if defined(LUA_USELONGLONG)
#define LUA_INTFRMLEN "ll"
@@ -733,6 +734,20 @@ static int str_gsub (lua_State *L) {
#define LUA_INTFRM_T long
#endif
+#endif /* } */
+
+
+/*
+** LUA_FLTFRMLEN is the length modifier for float conversions in
+** 'string.format'; LUA_FLTFRM_T is the float type corresponding to
+** the previous length
+*/
+#if !defined(LUA_FLTFRMLEN)
+
+#define LUA_FLTFRMLEN ""
+#define LUA_FLTFRM_T double
+
+#endif
/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
@@ -793,14 +808,15 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
/*
-** add length modifier into integer formats
+** add length modifier into formats
*/
-static void addintlen (char *form) {
+static void addlenmod (char *form, const char *lenmod) {
size_t l = strlen(form);
+ size_t lm = strlen(lenmod);
char spec = form[l - 1];
- strcpy(form + l - 1, LUA_INTFRMLEN);
- form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
- form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
+ strcpy(form + l - 1, lenmod);
+ form[l + lm - 1] = spec;
+ form[l + lm] = '\0';
}
@@ -834,13 +850,14 @@ static int str_format (lua_State *L) {
lua_Number n = luaL_checknumber(L, arg);
LUA_INTFRM_T r = (n < 0) ? (LUA_INTFRM_T)n :
(LUA_INTFRM_T)(unsigned LUA_INTFRM_T)n;
- addintlen(form);
+ addlenmod(form, LUA_INTFRMLEN);
nb = sprintf(buff, form, r);
break;
}
case 'e': case 'E': case 'f':
case 'g': case 'G': {
- nb = sprintf(buff, form, (double)luaL_checknumber(L, arg));
+ addlenmod(form, LUA_FLTFRMLEN);
+ nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'q': {
diff --git a/src/ltable.c b/src/ltable.c
index f93b96cc..7ff0f897 100644
--- a/src/ltable.c
+++ b/src/ltable.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.c,v 2.52 2010/06/25 12:18:10 roberto Exp $
+** $Id: ltable.c,v 2.53 2010/11/11 15:38:43 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -38,8 +38,8 @@
/*
** max size of array part is 2^MAXBITS
*/
-#if LUAI_BITSINT > 26
-#define MAXBITS 26
+#if LUAI_BITSINT >= 32
+#define MAXBITS 30
#else
#define MAXBITS (LUAI_BITSINT-2)
#endif
diff --git a/src/lua.h b/src/lua.h
index 9de92287..0e1f97a4 100644
--- a/src/lua.h
+++ b/src/lua.h
@@ -18,7 +18,7 @@
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "2"
-#define LUA_VERSION_RELEASE "0" " (work5)"
+#define LUA_VERSION_RELEASE "0" " (alpha)"
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
diff --git a/src/luaconf.h b/src/luaconf.h
index 2345e00c..1222dc9c 100644
--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -1,5 +1,5 @@
/*
-** $Id: luaconf.h,v 1.148 2010/10/29 17:52:46 roberto Exp $
+** $Id: luaconf.h,v 1.151 2010/11/12 15:48:30 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@@ -229,7 +229,7 @@
** You can define it to get all options, or change specific options
** to fit your specific needs.
*/
-#if defined(LUA_COMPAT_ALL)
+#if defined(LUA_COMPAT_ALL) /* { */
/*
@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
@@ -238,8 +238,8 @@
#define LUA_COMPAT_UNPACK
/*
-@@ LUA_COMPAT_CPCALL controls the presence of macro 'lua_cpcall'.
-** You can call your C function directly (with light C functions)
+@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
+** You can call your C function directly (with light C functions).
*/
#define lua_cpcall(L,f,u) \
(lua_pushcfunction(L, (f)), \
@@ -259,14 +259,6 @@
#define LUA_COMPAT_MAXN
/*
-@@ LUA_COMPAT_DEBUGLIB controls compatibility with preloading
-** the debug library.
-** You should add 'require"debug"' everywhere you need the debug
-** library.
-*/
-#define LUA_COMPAT_DEBUGLIB
-
-/*
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
@@ -275,19 +267,16 @@
#define lua_objlen(L,i) lua_rawlen(L, (i))
-#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
+#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
-/* compatibility with previous wrong spelling */
-#define luaL_typerror luaL_typeerror
-
/*
@@ LUA_COMPAT_MODULE controls compatibility with previous
** module functions 'module' (Lua) and 'luaL_register' (C).
*/
#define LUA_COMPAT_MODULE
-#endif /* LUA_COMPAT_ALL */
+#endif /* } */
/* }================================================================== */
@@ -348,27 +337,13 @@
-/*
-** {==================================================================
-** CHANGE (to smaller values) the following definitions if your system
-** has a small C stack. (Or you may want to change them to larger
-** values if your system has a large C stack and these limits are
-** too rigid for you.) Some of these constants control the size of
-** stack-allocated arrays used by the compiler or the interpreter, while
-** others limit the maximum number of recursive calls that the compiler
-** or the interpreter can perform. Values too large may cause a C stack
-** overflow for some forms of deep constructs.
-** ===================================================================
-*/
-
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
+** CHANGE it if it uses too much C-stack space.
*/
#define LUAL_BUFFERSIZE BUFSIZ
-/* }================================================================== */
-
@@ -445,32 +420,21 @@
#define LUA_UNSIGNED unsigned LUA_INT32
-/*
-@@ lua_number2int is a macro to convert lua_Number to int.
-@@ lua_number2integer is a macro to convert lua_Number to LUA_INTEGER.
-@@ lua_number2uint is a macro to convert a lua_Number to a LUA_UNSIGNED.
-@@ lua_uint2number is a macro to convert a LUA_UNSIGNED to a lua_Number.
-*/
-
#if defined(LUA_CORE) /* { */
-#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && \
- !defined(LUA_NOIEEE754TRICK) /* { */
+#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
/* On a Microsoft compiler on a Pentium, use assembler to avoid clashes
with a DirectX idiosyncrasy */
#if defined(_MSC_VER) && defined(M_IX86) /* { */
-#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
-#define lua_number2integer(i,n) lua_number2int(i, n)
-#define lua_number2uint(i,n) \
- {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
+#define MS_ASMTRICK
#else /* }{ */
-/* the next trick should work on any machine using IEEE754 with
- a 32-bit integer type */
+/* the next definition uses a trick that should work on any machine
+ using IEEE754 with a 32-bit integer type */
-union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
+#define LUA_IEEE754TRICK
/*
@@ 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]; };
#define LUA_IEEEENDIAN 1
#endif
-#if !defined(LUA_IEEEENDIAN) /* { */
-#define LUAI_EXTRAIEEE \
- static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
-#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33)
-#else
-#define LUAI_EXTRAIEEE /* empty */
-#endif /* } */
-
-#define lua_number2int32(i,n,t) \
- { LUAI_EXTRAIEEE \
- volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
- (i) = (t)u.l_p[LUA_IEEEENDIAN]; }
-
-#define lua_number2int(i,n) lua_number2int32(i, n, int)
-#define lua_number2integer(i,n) lua_number2int32(i, n, LUA_INTEGER)
-#define lua_number2uint(i,n) lua_number2int32(i, n, LUA_UNSIGNED)
-
#endif /* } */
-
#endif /* } */
-
-/* the following definitions always work, but may be slow */
-
-#if !defined(lua_number2int)
-#define lua_number2int(i,n) ((i)=(int)(n))
-#endif
-
-#if !defined(lua_number2integer)
-#define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n))
-#endif
-
-#if !defined(lua_number2uint) && (defined(lapi_c) || defined(luaall_c)) /* { */
-/* the following definition assures proper modulo behavior */
-#if defined(LUA_NUMBER_DOUBLE)
-#include <math.h>
-#define lua_number2uint(i,n) \
- ((i)=(LUA_UNSIGNED)((n) - floor((n)/4294967296.0)*4294967296.0))
-#else
-#define lua_number2uint(i,n) ((i)=(LUA_UNSIGNED)(n))
-#endif
-#endif /* } */
-
-#if !defined(lua_uint2number)
-/* on several machines, coercion from unsigned to double is slow,
- so it may be worth to avoid */
-#define lua_uint2number(u) \
- ((LUA_INT32)(u) < 0 ? (lua_Number)(u) : (lua_Number)(LUA_INT32)(u))
-#endif
-
-#endif /* } */
-
-
-/*
-@@ luai_hashnum is a macro do hash a lua_Number value into an integer.
-@* The hash must be deterministic and give reasonable values for
-@* both small and large values (outside the range of integers).
-@* It is used only in ltable.c.
-*/
-
-#if defined(ltable_c) || defined(luaall_c)
-
-#include <float.h>
-#include <math.h>
-
-#define luai_hashnum(i,n) { int e; \
- n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
- lua_number2int(i, n); i += e; }
-
-#endif /* ltable_c */
+#endif /* } */
/* }================================================================== */