commit f04fe526cd9de3e5460b614b2ff06268ad51872d
parent 21947deddc5976536665cd2397d7d5c9e6bd7e48
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 7 Oct 2003 17:13:19 -0300
new functions `lua_tointeger' and lua_pushinteger'
Diffstat:
11 files changed, 160 insertions(+), 120 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 1.243 2003/08/25 20:00:50 roberto Exp roberto $
+** $Id: lapi.c,v 1.244 2003/08/27 21:01:44 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -27,6 +27,12 @@
#include "lvm.h"
+/* function to convert a lua_Number to lua_Integer (with any rounding method) */
+#ifndef lua_number2integer
+#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
+#endif
+
+
const char lua_ident[] =
"$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
"$Authors: " LUA_AUTHORS " $\n"
@@ -289,6 +295,19 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
}
+LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
+ TObject n;
+ const TObject *o = luaA_index(L, idx);
+ if (tonumber(o, &n)) {
+ lua_Integer res;
+ lua_number2integer(res, nvalue(o));
+ return res;
+ }
+ else
+ return 0;
+}
+
+
LUA_API int lua_toboolean (lua_State *L, int idx) {
const TObject *o = luaA_index(L, idx);
return !l_isfalse(o);
@@ -382,6 +401,14 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
}
+LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
+ lua_lock(L);
+ setnvalue(L->top, cast(lua_Number, n));
+ api_incr_top(L);
+ lua_unlock(L);
+}
+
+
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
lua_lock(L);
luaC_checkGC(L);
diff --git a/lauxlib.c b/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.103 2003/10/01 16:50:53 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.104 2003/10/02 20:31:17 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -197,6 +197,21 @@ LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
}
+LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {
+ lua_Integer d = lua_tointeger(L, narg);
+ if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
+ tag_error(L, narg, LUA_TNUMBER);
+ return d;
+}
+
+
+LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
+ lua_Integer def) {
+ if (lua_isnoneornil(L, narg)) return def;
+ else return luaL_checkinteger(L, narg);
+}
+
+
LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
if (!lua_getmetatable(L, obj)) /* no metatable? */
return 0;
@@ -257,7 +272,7 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
*/
static int checkint (lua_State *L, int topop) {
- int n = (int)lua_tonumber(L, -1);
+ int n = (int)lua_tointeger(L, -1);
if (n == 0 && !lua_isnumber(L, -1)) n = -1;
lua_pop(L, topop);
return n;
@@ -286,13 +301,13 @@ void luaL_setn (lua_State *L, int t, int n) {
lua_rawget(L, t);
if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */
lua_pushliteral(L, "n"); /* use it */
- lua_pushnumber(L, (lua_Number)n);
+ lua_pushinteger(L, n);
lua_rawset(L, t);
}
else { /* use `sizes' */
getsizes(L);
lua_pushvalue(L, t);
- lua_pushnumber(L, (lua_Number)n);
+ lua_pushinteger(L, n);
lua_rawset(L, -3); /* sizes[t] = n */
lua_pop(L, 1); /* remove `sizes' */
}
@@ -425,7 +440,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) {
return LUA_REFNIL; /* `nil' has a unique fixed reference */
}
lua_rawgeti(L, t, FREELIST_REF); /* get first free element */
- ref = (int)lua_tonumber(L, -1); /* ref = t[FREELIST_REF] */
+ ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */
lua_pop(L, 1); /* remove it from stack */
if (ref != 0) { /* any free element? */
lua_rawgeti(L, t, ref); /* remove it from list */
@@ -448,7 +463,7 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
t = abs_index(L, t);
lua_rawgeti(L, t, FREELIST_REF);
lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */
- lua_pushnumber(L, (lua_Number)ref);
+ lua_pushinteger(L, ref);
lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */
}
}
diff --git a/lauxlib.h b/lauxlib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.h,v 1.60 2003/04/03 13:35:34 roberto Exp roberto $
+** $Id: lauxlib.h,v 1.61 2003/10/02 20:31:17 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -39,6 +39,10 @@ LUALIB_API const char *luaL_optlstring (lua_State *L, int numArg,
LUALIB_API lua_Number luaL_checknumber (lua_State *L, int numArg);
LUALIB_API lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number def);
+LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int numArg);
+LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int nArg,
+ lua_Integer def);
+
LUALIB_API void luaL_checkstack (lua_State *L, int sz, const char *msg);
LUALIB_API void luaL_checktype (lua_State *L, int narg, int t);
LUALIB_API void luaL_checkany (lua_State *L, int narg);
@@ -76,10 +80,10 @@ LUALIB_API lua_State *(luaL_newstate) (void);
luaL_argerror(L, numarg,extramsg)
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
-#define luaL_checkint(L,n) ((int)luaL_checknumber(L, n))
-#define luaL_checklong(L,n) ((long)luaL_checknumber(L, n))
-#define luaL_optint(L,n,d) ((int)luaL_optnumber(L, n,(lua_Number)(d)))
-#define luaL_optlong(L,n,d) ((long)luaL_optnumber(L, n,(lua_Number)(d)))
+#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, n))
+#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, n,d))
+#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, n))
+#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, n,d))
/*
@@ -129,19 +133,6 @@ LUALIB_API int lua_dobuffer (lua_State *L, const char *buff, size_t sz,
const char *n);
-#define luaL_check_lstr luaL_checklstring
-#define luaL_opt_lstr luaL_optlstring
-#define luaL_check_number luaL_checknumber
-#define luaL_opt_number luaL_optnumber
-#define luaL_arg_check luaL_argcheck
-#define luaL_check_string luaL_checkstring
-#define luaL_opt_string luaL_optstring
-#define luaL_check_int luaL_checkint
-#define luaL_check_long luaL_checklong
-#define luaL_opt_int luaL_optint
-#define luaL_opt_long luaL_optlong
-
-
#endif
diff --git a/lbaselib.c b/lbaselib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbaselib.c,v 1.132 2003/08/25 19:49:47 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.133 2003/08/27 21:02:08 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@@ -187,8 +187,8 @@ static int luaB_rawset (lua_State *L) {
static int luaB_gcinfo (lua_State *L) {
- lua_pushnumber(L, (lua_Number)lua_getgccount(L));
- lua_pushnumber(L, (lua_Number)lua_getgcthreshold(L));
+ lua_pushinteger(L, lua_getgccount(L));
+ lua_pushinteger(L, lua_getgcthreshold(L));
return 2;
}
@@ -229,19 +229,19 @@ static int luaB_pairs (lua_State *L) {
static int luaB_ipairs (lua_State *L) {
- lua_Number i = lua_tonumber(L, 2);
+ int i = (int)lua_tointeger(L, 2);
luaL_checktype(L, 1, LUA_TTABLE);
if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */
lua_pushliteral(L, "ipairs");
lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */
lua_pushvalue(L, 1); /* state, */
- lua_pushnumber(L, 0); /* and initial value */
+ lua_pushinteger(L, 0); /* and initial value */
return 3;
}
else { /* `for' step */
i++; /* next value */
- lua_pushnumber(L, i);
- lua_rawgeti(L, 1, (int)i);
+ lua_pushinteger(L, i);
+ lua_rawgeti(L, 1, i);
return (lua_isnil(L, -1)) ? 0 : 2;
}
}
diff --git a/ldblib.c b/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.80 2003/04/03 13:35:34 roberto Exp roberto $
+** $Id: ldblib.c,v 1.81 2003/07/07 13:37:08 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -27,7 +27,7 @@ static void settabss (lua_State *L, const char *i, const char *v) {
static void settabsi (lua_State *L, const char *i, int v) {
lua_pushstring(L, i);
- lua_pushnumber(L, (lua_Number)v);
+ lua_pushinteger(L, v);
lua_rawset(L, -3);
}
@@ -50,7 +50,7 @@ static int getinfo (lua_State *L) {
lua_State *L1 = getthread(L, &arg);
const char *options = luaL_optstring(L, arg+2, "flnSu");
if (lua_isnumber(L, arg+1)) {
- if (!lua_getstack(L1, (int)(lua_tonumber(L, arg+1)), &ar)) {
+ if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
lua_pushnil(L); /* level out of range */
return 1;
}
@@ -171,7 +171,7 @@ static void hookf (lua_State *L, lua_Debug *ar) {
if (lua_isfunction(L, -1)) {
lua_pushstring(L, hooknames[(int)ar->event]);
if (ar->currentline >= 0)
- lua_pushnumber(L, (lua_Number)ar->currentline);
+ lua_pushinteger(L, ar->currentline);
else lua_pushnil(L);
lua_assert(lua_getinfo(L, "lS", ar));
lua_call(L, 2, 0);
@@ -251,7 +251,7 @@ static int gethook (lua_State *L) {
lua_xmove(L1, L, 1);
}
lua_pushstring(L, unmakemask(mask, buff));
- lua_pushnumber(L, (lua_Number)lua_gethookcount(L1));
+ lua_pushinteger(L, lua_gethookcount(L1));
return 3;
}
diff --git a/liolib.c b/liolib.c
@@ -1,5 +1,5 @@
/*
-** $Id: liolib.c,v 2.45 2003/07/09 12:08:43 roberto Exp roberto $
+** $Id: liolib.c,v 2.46 2003/08/25 19:49:47 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@@ -76,7 +76,7 @@ static int pushresult (lua_State *L, int i, const char *filename) {
lua_pushfstring(L, "%s: %s", filename, strerror(errno));
else
lua_pushfstring(L, "%s", strerror(errno));
- lua_pushnumber(L, errno);
+ lua_pushinteger(L, errno);
return 3;
}
}
@@ -346,7 +346,7 @@ static int g_read (lua_State *L, FILE *f, int first) {
success = 1;
for (n = first; nargs-- && success; n++) {
if (lua_type(L, n) == LUA_TNUMBER) {
- size_t l = (size_t)lua_tonumber(L, n);
+ size_t l = (size_t)lua_tointeger(L, n);
success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
}
else {
@@ -441,13 +441,13 @@ static int f_seek (lua_State *L) {
static const char *const modenames[] = {"set", "cur", "end", NULL};
FILE *f = tofile(L, 1);
int op = luaL_findstring(luaL_optstring(L, 2, "cur"), modenames);
- long offset = luaL_optlong(L, 3, 0);
+ lua_Integer offset = luaL_optinteger(L, 3, 0);
luaL_argcheck(L, op != -1, 2, "invalid mode");
op = fseek(f, offset, mode[op]);
if (op)
return pushresult(L, 0, NULL); /* error */
else {
- lua_pushnumber(L, ftell(f));
+ lua_pushinteger(L, ftell(f));
return 1;
}
}
@@ -528,7 +528,7 @@ static void createmeta (lua_State *L) {
*/
static int io_execute (lua_State *L) {
- lua_pushnumber(L, system(luaL_checkstring(L, 1)));
+ lua_pushinteger(L, system(luaL_checkstring(L, 1)));
return 1;
}
@@ -582,7 +582,7 @@ static int io_clock (lua_State *L) {
static void setfield (lua_State *L, const char *key, int value) {
lua_pushstring(L, key);
- lua_pushnumber(L, value);
+ lua_pushinteger(L, value);
lua_rawset(L, -3);
}
@@ -607,9 +607,9 @@ static int getfield (lua_State *L, const char *key, int d) {
lua_pushstring(L, key);
lua_gettable(L, -2);
if (lua_isnumber(L, -1))
- res = (int)(lua_tonumber(L, -1));
+ res = (int)lua_tointeger(L, -1);
else {
- if (d == -2)
+ if (d < 0)
return luaL_error(L, "field `%s' missing in date table", key);
res = d;
}
@@ -665,9 +665,9 @@ static int io_time (lua_State *L) {
ts.tm_sec = getfield(L, "sec", 0);
ts.tm_min = getfield(L, "min", 0);
ts.tm_hour = getfield(L, "hour", 12);
- ts.tm_mday = getfield(L, "day", -2);
- ts.tm_mon = getfield(L, "month", -2) - 1;
- ts.tm_year = getfield(L, "year", -2) - 1900;
+ ts.tm_mday = getfield(L, "day", -1);
+ ts.tm_mon = getfield(L, "month", -1) - 1;
+ ts.tm_year = getfield(L, "year", -1) - 1900;
ts.tm_isdst = getboolfield(L, "isdst");
t = mktime(&ts);
if (t == (time_t)(-1))
diff --git a/lmathlib.c b/lmathlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmathlib.c,v 1.55 2003/03/11 12:24:34 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.56 2003/03/11 12:30:37 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -128,7 +128,7 @@ 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, e);
+ lua_pushinteger(L, e);
return 2;
}
@@ -179,14 +179,14 @@ static int math_random (lua_State *L) {
case 1: { /* only upper limit */
int u = luaL_checkint(L, 1);
luaL_argcheck(L, 1<=u, 1, "interval is empty");
- lua_pushnumber(L, (int)floor(r*u)+1); /* int between 1 and `u' */
+ lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */
break;
}
case 2: { /* lower and upper limits */
int l = luaL_checkint(L, 1);
int u = luaL_checkint(L, 2);
luaL_argcheck(L, l<=u, 2, "interval is empty");
- lua_pushnumber(L, (int)floor(r*(u-l+1))+l); /* int between `l' and `u' */
+ lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */
break;
}
default: return luaL_error(L, "wrong number of arguments");
diff --git a/lstrlib.c b/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.98 2003/04/03 13:35:34 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.99 2003/05/14 14:35:54 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -25,13 +25,13 @@
#endif
-typedef long sint32; /* a signed version for size_t */
+typedef lua_Integer sint32; /* a signed version for size_t */
static int str_len (lua_State *L) {
size_t l;
luaL_checklstring(L, 1, &l);
- lua_pushnumber(L, (lua_Number)l);
+ lua_pushinteger(L, l);
return 1;
}
@@ -45,8 +45,8 @@ static sint32 posrelat (sint32 pos, size_t len) {
static int str_sub (lua_State *L) {
size_t l;
const char *s = luaL_checklstring(L, 1, &l);
- sint32 start = posrelat(luaL_checklong(L, 2), l);
- sint32 end = posrelat(luaL_optlong(L, 3, -1), l);
+ sint32 start = posrelat(luaL_checkinteger(L, 2), l);
+ sint32 end = posrelat(luaL_optinteger(L, 3, -1), l);
if (start < 1) start = 1;
if (end > (sint32)l) end = (sint32)l;
if (start <= end)
@@ -108,10 +108,10 @@ static int str_rep (lua_State *L) {
static int str_byte (lua_State *L) {
size_t l;
const char *s = luaL_checklstring(L, 1, &l);
- sint32 pos = posrelat(luaL_optlong(L, 2, 1), l);
+ sint32 pos = posrelat(luaL_optinteger(L, 2, 1), l);
if (pos <= 0 || (size_t)(pos) > l) /* index out of range? */
return 0; /* no answer */
- lua_pushnumber(L, uchar(s[pos-1]));
+ lua_pushinteger(L, uchar(s[pos-1]));
return 1;
}
@@ -463,7 +463,7 @@ static void push_onecapture (MatchState *ms, int i) {
int l = ms->capture[i].len;
if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
if (l == CAP_POSITION)
- lua_pushnumber(ms->L, (lua_Number)(ms->capture[i].init - ms->src_init + 1));
+ lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
else
lua_pushlstring(ms->L, ms->capture[i].init, l);
}
@@ -488,7 +488,7 @@ static int str_find (lua_State *L) {
size_t l1, l2;
const char *s = luaL_checklstring(L, 1, &l1);
const char *p = luaL_checklstring(L, 2, &l2);
- sint32 init = posrelat(luaL_optlong(L, 3, 1), l1) - 1;
+ sint32 init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
if (init < 0) init = 0;
else if ((size_t)(init) > l1) init = (sint32)l1;
if (lua_toboolean(L, 4) || /* explicit request? */
@@ -496,8 +496,8 @@ static int str_find (lua_State *L) {
/* do a plain search */
const char *s2 = lmemfind(s+init, l1-init, p, l2);
if (s2) {
- lua_pushnumber(L, (lua_Number)(s2-s+1));
- lua_pushnumber(L, (lua_Number)(s2-s+l2));
+ lua_pushinteger(L, s2-s+1);
+ lua_pushinteger(L, s2-s+l2);
return 2;
}
}
@@ -512,8 +512,8 @@ static int str_find (lua_State *L) {
const char *res;
ms.level = 0;
if ((res=match(&ms, s1, p)) != NULL) {
- lua_pushnumber(L, (lua_Number)(s1-s+1)); /* start */
- lua_pushnumber(L, (lua_Number)(res-s)); /* end */
+ lua_pushinteger(L, s1-s+1); /* start */
+ lua_pushinteger(L, res-s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
} while (s1++<ms.src_end && !anchor);
@@ -532,7 +532,7 @@ static int gfind_aux (lua_State *L) {
ms.L = L;
ms.src_init = s;
ms.src_end = s+ls;
- for (src = s + (size_t)lua_tonumber(L, lua_upvalueindex(3));
+ for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));
src <= ms.src_end;
src++) {
const char *e;
@@ -540,7 +540,7 @@ static int gfind_aux (lua_State *L) {
if ((e = match(&ms, src, p)) != NULL) {
int newstart = e-s;
if (e == src) newstart++; /* empty match? go at least one position */
- lua_pushnumber(L, (lua_Number)newstart);
+ lua_pushinteger(L, newstart);
lua_replace(L, lua_upvalueindex(3));
return push_captures(&ms, src, e);
}
@@ -553,7 +553,7 @@ static int gfind (lua_State *L) {
luaL_checkstring(L, 1);
luaL_checkstring(L, 2);
lua_settop(L, 2);
- lua_pushnumber(L, 0);
+ lua_pushinteger(L, 0);
lua_pushcclosure(L, gfind_aux, 3);
return 1;
}
@@ -627,7 +627,7 @@ static int str_gsub (lua_State *L) {
}
luaL_addlstring(&b, src, ms.src_end-src);
luaL_pushresult(&b);
- lua_pushnumber(L, (lua_Number)n); /* number of substitutions */
+ lua_pushinteger(L, n); /* number of substitutions */
return 2;
}
diff --git a/ltablib.c b/ltablib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltablib.c,v 1.20 2003/03/11 12:24:34 roberto Exp roberto $
+** $Id: ltablib.c,v 1.21 2003/04/03 13:35:34 roberto Exp roberto $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/
@@ -24,7 +24,7 @@ static int luaB_foreachi (lua_State *L) {
luaL_checktype(L, 2, LUA_TFUNCTION);
for (i=1; i<=n; i++) {
lua_pushvalue(L, 2); /* function */
- lua_pushnumber(L, (lua_Number)i); /* 1st argument */
+ lua_pushinteger(L, i); /* 1st argument */
lua_rawgeti(L, 1, i); /* 2nd argument */
lua_call(L, 2, 1);
if (!lua_isnil(L, -1))
@@ -54,7 +54,7 @@ static int luaB_foreach (lua_State *L) {
static int luaB_getn (lua_State *L) {
- lua_pushnumber(L, (lua_Number)aux_getn(L, 1));
+ lua_pushinteger(L, aux_getn(L, 1));
return 1;
}
diff --git a/ltests.c b/ltests.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltests.c,v 1.163 2003/07/29 19:26:34 roberto Exp roberto $
+** $Id: ltests.c,v 1.164 2003/10/02 20:31:17 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@@ -36,9 +36,6 @@
#ifdef LUA_DEBUG
-#define lua_pushintegral(L,i) lua_pushnumber(L, cast(lua_Number, (i)))
-
-
static lua_State *lua_state = NULL;
int islocked = 0;
@@ -49,7 +46,7 @@ int islocked = 0;
static void setnameval (lua_State *L, const char *name, int val) {
lua_pushstring(L, name);
- lua_pushintegral(L, val);
+ lua_pushinteger(L, val);
lua_settable(L, -3);
}
@@ -196,7 +193,7 @@ static int listcode (lua_State *L) {
setnameval(L, "numparams", p->numparams);
for (pc=0; pc<p->sizecode; pc++) {
char buff[100];
- lua_pushintegral(L, pc+1);
+ lua_pushinteger(L, pc+1);
lua_pushstring(L, buildop(p, pc, buff));
lua_settable(L, -3);
}
@@ -212,7 +209,7 @@ static int listk (lua_State *L) {
p = clvalue(func_at(L, 1))->l.p;
lua_newtable(L);
for (i=0; i<p->sizek; i++) {
- lua_pushintegral(L, i+1);
+ lua_pushinteger(L, i+1);
luaA_pushobject(L, p->k+i);
lua_settable(L, -3);
}
@@ -257,9 +254,9 @@ static int setgcthreshold (lua_State *L) {
static int mem_query (lua_State *L) {
if (lua_isnone(L, 1)) {
- lua_pushintegral(L, memcontrol.total);
- lua_pushintegral(L, memcontrol.numblocks);
- lua_pushintegral(L, memcontrol.maxmem);
+ lua_pushinteger(L, memcontrol.total);
+ lua_pushinteger(L, memcontrol.numblocks);
+ lua_pushinteger(L, memcontrol.maxmem);
return 3;
}
else {
@@ -272,14 +269,14 @@ static int mem_query (lua_State *L) {
static int hash_query (lua_State *L) {
if (lua_isnone(L, 2)) {
luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected");
- lua_pushintegral(L, tsvalue(func_at(L, 1))->tsv.hash);
+ lua_pushinteger(L, tsvalue(func_at(L, 1))->tsv.hash);
}
else {
TObject *o = func_at(L, 1);
Table *t;
luaL_checktype(L, 2, LUA_TTABLE);
t = hvalue(func_at(L, 2));
- lua_pushintegral(L, luaH_mainposition(t, o) - t->node);
+ lua_pushinteger(L, luaH_mainposition(t, o) - t->node);
}
return 1;
}
@@ -287,11 +284,11 @@ static int hash_query (lua_State *L) {
static int stacklevel (lua_State *L) {
unsigned long a = 0;
- lua_pushintegral(L, (int)(L->top - L->stack));
- lua_pushintegral(L, (int)(L->stack_last - L->stack));
- lua_pushintegral(L, (int)(L->ci - L->base_ci));
- lua_pushintegral(L, (int)(L->end_ci - L->base_ci));
- lua_pushintegral(L, (unsigned long)&a);
+ lua_pushinteger(L, (L->top - L->stack));
+ lua_pushinteger(L, (L->stack_last - L->stack));
+ lua_pushinteger(L, (L->ci - L->base_ci));
+ lua_pushinteger(L, (L->end_ci - L->base_ci));
+ lua_pushinteger(L, (unsigned long)&a);
return 5;
}
@@ -302,12 +299,12 @@ static int table_query (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE);
t = hvalue(func_at(L, 1));
if (i == -1) {
- lua_pushintegral(L, t->sizearray);
- lua_pushintegral(L, sizenode(t));
- lua_pushintegral(L, t->firstfree - t->node);
+ lua_pushinteger(L, t->sizearray);
+ lua_pushinteger(L, sizenode(t));
+ lua_pushinteger(L, t->firstfree - t->node);
}
else if (i < t->sizearray) {
- lua_pushintegral(L, i);
+ lua_pushinteger(L, i);
luaA_pushobject(L, &t->array[i]);
lua_pushnil(L);
}
@@ -321,7 +318,7 @@ static int table_query (lua_State *L) {
lua_pushliteral(L, "<undef>");
luaA_pushobject(L, gval(gnode(t, i)));
if (t->node[i].next)
- lua_pushintegral(L, t->node[i].next - t->node);
+ lua_pushinteger(L, t->node[i].next - t->node);
else
lua_pushnil(L);
}
@@ -333,8 +330,8 @@ static int string_query (lua_State *L) {
stringtable *tb = &G(L)->strt;
int s = luaL_optint(L, 2, 0) - 1;
if (s==-1) {
- lua_pushintegral(L ,tb->nuse);
- lua_pushintegral(L ,tb->size);
+ lua_pushinteger(L ,tb->nuse);
+ lua_pushinteger(L ,tb->size);
return 2;
}
else if (s < tb->size) {
@@ -356,7 +353,7 @@ static int tref (lua_State *L) {
int lock = luaL_optint(L, 2, 1);
luaL_checkany(L, 1);
lua_pushvalue(L, 1);
- lua_pushintegral(L, lua_ref(L, lock));
+ lua_pushinteger(L, lua_ref(L, lock));
assert(lua_gettop(L) == level+1); /* +1 for result */
return 1;
}
@@ -422,7 +419,7 @@ static int pushuserdata (lua_State *L) {
static int udataval (lua_State *L) {
- lua_pushintegral(L, cast(int, lua_touserdata(L, 1)));
+ lua_pushinteger(L, cast(long, lua_touserdata(L, 1)));
return 1;
}
@@ -434,7 +431,7 @@ static int doonnewstack (lua_State *L) {
int status = luaL_loadbuffer(L1, s, l, s);
if (status == 0)
status = lua_pcall(L1, 0, 0, 0);
- lua_pushintegral(L, status);
+ lua_pushinteger(L, status);
return 1;
}
@@ -455,7 +452,7 @@ static int newstate (lua_State *L) {
lua_State *L1 = lua_open();
if (L1) {
lua_userstateopen(L1); /* init lock */
- lua_pushintegral(L, (unsigned long)L1);
+ lua_pushinteger(L, (unsigned long)L1);
}
else
lua_pushnil(L);
@@ -498,7 +495,7 @@ static int doremote (lua_State *L) {
status = lua_pcall(L1, 0, LUA_MULTRET, 0);
if (status != 0) {
lua_pushnil(L);
- lua_pushintegral(L, status);
+ lua_pushinteger(L, status);
lua_pushstring(L, lua_tostring(L1, -1));
return 3;
}
@@ -513,14 +510,14 @@ static int doremote (lua_State *L) {
static int log2_aux (lua_State *L) {
- lua_pushintegral(L, luaO_log2(luaL_checkint(L, 1)));
+ lua_pushinteger(L, luaO_log2(luaL_checkint(L, 1)));
return 1;
}
static int int2fb_aux (lua_State *L) {
int b = luaO_int2fb(luaL_checkint(L, 1));
- lua_pushintegral(L, b);
- lua_pushintegral(L, fb2int(b));
+ lua_pushinteger(L, b);
+ lua_pushinteger(L, fb2int(b));
return 2;
}
@@ -590,31 +587,31 @@ static int testC (lua_State *L) {
const char *inst = getname;
if EQ("") return 0;
else if EQ("isnumber") {
- lua_pushintegral(L, lua_isnumber(L, getnum));
+ lua_pushinteger(L, lua_isnumber(L, getnum));
}
else if EQ("isstring") {
- lua_pushintegral(L, lua_isstring(L, getnum));
+ lua_pushinteger(L, lua_isstring(L, getnum));
}
else if EQ("istable") {
- lua_pushintegral(L, lua_istable(L, getnum));
+ lua_pushinteger(L, lua_istable(L, getnum));
}
else if EQ("iscfunction") {
- lua_pushintegral(L, lua_iscfunction(L, getnum));
+ lua_pushinteger(L, lua_iscfunction(L, getnum));
}
else if EQ("isfunction") {
- lua_pushintegral(L, lua_isfunction(L, getnum));
+ lua_pushinteger(L, lua_isfunction(L, getnum));
}
else if EQ("isuserdata") {
- lua_pushintegral(L, lua_isuserdata(L, getnum));
+ lua_pushinteger(L, lua_isuserdata(L, getnum));
}
else if EQ("isudataval") {
- lua_pushintegral(L, lua_islightuserdata(L, getnum));
+ lua_pushinteger(L, lua_islightuserdata(L, getnum));
}
else if EQ("isnil") {
- lua_pushintegral(L, lua_isnil(L, getnum));
+ lua_pushinteger(L, lua_isnil(L, getnum));
}
else if EQ("isnull") {
- lua_pushintegral(L, lua_isnone(L, getnum));
+ lua_pushinteger(L, lua_isnone(L, getnum));
}
else if EQ("tonumber") {
lua_pushnumber(L, lua_tonumber(L, getnum));
@@ -624,7 +621,7 @@ static int testC (lua_State *L) {
lua_pushstring(L, s);
}
else if EQ("strlen") {
- lua_pushintegral(L, lua_strlen(L, getnum));
+ lua_pushinteger(L, lua_strlen(L, getnum));
}
else if EQ("tocfunction") {
lua_pushcfunction(L, lua_tocfunction(L, getnum));
@@ -633,7 +630,7 @@ static int testC (lua_State *L) {
return getnum;
}
else if EQ("gettop") {
- lua_pushintegral(L, lua_gettop(L));
+ lua_pushinteger(L, lua_gettop(L));
}
else if EQ("settop") {
lua_settop(L, getnum);
@@ -642,7 +639,7 @@ static int testC (lua_State *L) {
lua_pop(L, getnum);
}
else if EQ("pushnum") {
- lua_pushintegral(L, getnum);
+ lua_pushinteger(L, getnum);
}
else if EQ("pushnil") {
lua_pushnil(L);
@@ -651,7 +648,7 @@ static int testC (lua_State *L) {
lua_pushboolean(L, getnum);
}
else if EQ("tobool") {
- lua_pushintegral(L, lua_toboolean(L, getnum));
+ lua_pushinteger(L, lua_toboolean(L, getnum));
}
else if EQ("pushvalue") {
lua_pushvalue(L, getnum);
@@ -718,7 +715,7 @@ static int testC (lua_State *L) {
}
else if EQ("getn") {
int i = getnum;
- lua_pushintegral(L, luaL_getn(L, i));
+ lua_pushinteger(L, luaL_getn(L, i));
}
else if EQ("setn") {
int i = getnum;
diff --git a/lua.h b/lua.h
@@ -1,5 +1,5 @@
/*
-** $Id: lua.h,v 1.178 2003/07/07 13:30:57 roberto Exp roberto $
+** $Id: lua.h,v 1.179 2003/10/02 20:31:17 roberto Exp roberto $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org
@@ -98,6 +98,14 @@ typedef LUA_NUMBER lua_Number;
#endif
+/* type for integer functions */
+#ifndef LUA_INTEGER
+typedef long lua_Integer;
+#else
+typedef LUA_INTEGER lua_Integer;
+#endif
+
+
/* mark for all API functions */
#ifndef LUA_API
#define LUA_API extern
@@ -144,6 +152,7 @@ LUA_API int lua_rawequal (lua_State *L, int idx1, int idx2);
LUA_API int lua_lessthan (lua_State *L, int idx1, int idx2);
LUA_API lua_Number lua_tonumber (lua_State *L, int idx);
+LUA_API lua_Integer lua_tointeger (lua_State *L, int idx);
LUA_API int lua_toboolean (lua_State *L, int idx);
LUA_API const char *lua_tostring (lua_State *L, int idx);
LUA_API size_t lua_strlen (lua_State *L, int idx);
@@ -158,6 +167,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx);
*/
LUA_API void lua_pushnil (lua_State *L);
LUA_API void lua_pushnumber (lua_State *L, lua_Number n);
+LUA_API void lua_pushinteger (lua_State *L, lua_Integer n);
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t l);
LUA_API void lua_pushstring (lua_State *L, const char *s);
LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,