aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-07 17:13:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-07 17:13:41 -0300
commitf04fe526cd9de3e5460b614b2ff06268ad51872d (patch)
tree9e9fd4fc0bae4858d74c04a22d8ce5748191d5a9
parent21947deddc5976536665cd2397d7d5c9e6bd7e48 (diff)
downloadlua-f04fe526cd9de3e5460b614b2ff06268ad51872d.tar.gz
lua-f04fe526cd9de3e5460b614b2ff06268ad51872d.tar.bz2
lua-f04fe526cd9de3e5460b614b2ff06268ad51872d.zip
new functions `lua_tointeger' and lua_pushinteger'
-rw-r--r--lapi.c29
-rw-r--r--lauxlib.c27
-rw-r--r--lauxlib.h27
-rw-r--r--lbaselib.c14
-rw-r--r--ldblib.c10
-rw-r--r--liolib.c24
-rw-r--r--lmathlib.c8
-rw-r--r--lstrlib.c34
-rw-r--r--ltablib.c6
-rw-r--r--ltests.c89
-rw-r--r--lua.h12
11 files changed, 160 insertions, 120 deletions
diff --git a/lapi.c b/lapi.c
index 33eed2eb..b40f984a 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.243 2003/08/25 20:00:50 roberto Exp roberto $ 2** $Id: lapi.c,v 1.244 2003/08/27 21:01:44 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -27,6 +27,12 @@
27#include "lvm.h" 27#include "lvm.h"
28 28
29 29
30/* function to convert a lua_Number to lua_Integer (with any rounding method) */
31#ifndef lua_number2integer
32#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
33#endif
34
35
30const char lua_ident[] = 36const char lua_ident[] =
31 "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" 37 "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
32 "$Authors: " LUA_AUTHORS " $\n" 38 "$Authors: " LUA_AUTHORS " $\n"
@@ -289,6 +295,19 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
289} 295}
290 296
291 297
298LUA_API lua_Integer lua_tointeger (lua_State *L, int idx) {
299 TObject n;
300 const TObject *o = luaA_index(L, idx);
301 if (tonumber(o, &n)) {
302 lua_Integer res;
303 lua_number2integer(res, nvalue(o));
304 return res;
305 }
306 else
307 return 0;
308}
309
310
292LUA_API int lua_toboolean (lua_State *L, int idx) { 311LUA_API int lua_toboolean (lua_State *L, int idx) {
293 const TObject *o = luaA_index(L, idx); 312 const TObject *o = luaA_index(L, idx);
294 return !l_isfalse(o); 313 return !l_isfalse(o);
@@ -382,6 +401,14 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
382} 401}
383 402
384 403
404LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
405 lua_lock(L);
406 setnvalue(L->top, cast(lua_Number, n));
407 api_incr_top(L);
408 lua_unlock(L);
409}
410
411
385LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { 412LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
386 lua_lock(L); 413 lua_lock(L);
387 luaC_checkGC(L); 414 luaC_checkGC(L);
diff --git a/lauxlib.c b/lauxlib.c
index b90bf458..d689b18d 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.103 2003/10/01 16:50:53 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.104 2003/10/02 20:31:17 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -197,6 +197,21 @@ LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
197} 197}
198 198
199 199
200LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) {
201 lua_Integer d = lua_tointeger(L, narg);
202 if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
203 tag_error(L, narg, LUA_TNUMBER);
204 return d;
205}
206
207
208LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg,
209 lua_Integer def) {
210 if (lua_isnoneornil(L, narg)) return def;
211 else return luaL_checkinteger(L, narg);
212}
213
214
200LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { 215LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
201 if (!lua_getmetatable(L, obj)) /* no metatable? */ 216 if (!lua_getmetatable(L, obj)) /* no metatable? */
202 return 0; 217 return 0;
@@ -257,7 +272,7 @@ LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
257*/ 272*/
258 273
259static int checkint (lua_State *L, int topop) { 274static int checkint (lua_State *L, int topop) {
260 int n = (int)lua_tonumber(L, -1); 275 int n = (int)lua_tointeger(L, -1);
261 if (n == 0 && !lua_isnumber(L, -1)) n = -1; 276 if (n == 0 && !lua_isnumber(L, -1)) n = -1;
262 lua_pop(L, topop); 277 lua_pop(L, topop);
263 return n; 278 return n;
@@ -286,13 +301,13 @@ void luaL_setn (lua_State *L, int t, int n) {
286 lua_rawget(L, t); 301 lua_rawget(L, t);
287 if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ 302 if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */
288 lua_pushliteral(L, "n"); /* use it */ 303 lua_pushliteral(L, "n"); /* use it */
289 lua_pushnumber(L, (lua_Number)n); 304 lua_pushinteger(L, n);
290 lua_rawset(L, t); 305 lua_rawset(L, t);
291 } 306 }
292 else { /* use `sizes' */ 307 else { /* use `sizes' */
293 getsizes(L); 308 getsizes(L);
294 lua_pushvalue(L, t); 309 lua_pushvalue(L, t);
295 lua_pushnumber(L, (lua_Number)n); 310 lua_pushinteger(L, n);
296 lua_rawset(L, -3); /* sizes[t] = n */ 311 lua_rawset(L, -3); /* sizes[t] = n */
297 lua_pop(L, 1); /* remove `sizes' */ 312 lua_pop(L, 1); /* remove `sizes' */
298 } 313 }
@@ -425,7 +440,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) {
425 return LUA_REFNIL; /* `nil' has a unique fixed reference */ 440 return LUA_REFNIL; /* `nil' has a unique fixed reference */
426 } 441 }
427 lua_rawgeti(L, t, FREELIST_REF); /* get first free element */ 442 lua_rawgeti(L, t, FREELIST_REF); /* get first free element */
428 ref = (int)lua_tonumber(L, -1); /* ref = t[FREELIST_REF] */ 443 ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */
429 lua_pop(L, 1); /* remove it from stack */ 444 lua_pop(L, 1); /* remove it from stack */
430 if (ref != 0) { /* any free element? */ 445 if (ref != 0) { /* any free element? */
431 lua_rawgeti(L, t, ref); /* remove it from list */ 446 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) {
448 t = abs_index(L, t); 463 t = abs_index(L, t);
449 lua_rawgeti(L, t, FREELIST_REF); 464 lua_rawgeti(L, t, FREELIST_REF);
450 lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */ 465 lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */
451 lua_pushnumber(L, (lua_Number)ref); 466 lua_pushinteger(L, ref);
452 lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */ 467 lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */
453 } 468 }
454} 469}
diff --git a/lauxlib.h b/lauxlib.h
index a04c55e7..dbda55ec 100644
--- a/lauxlib.h
+++ b/lauxlib.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.h,v 1.60 2003/04/03 13:35:34 roberto Exp roberto $ 2** $Id: lauxlib.h,v 1.61 2003/10/02 20:31:17 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -39,6 +39,10 @@ LUALIB_API const char *luaL_optlstring (lua_State *L, int numArg,
39LUALIB_API lua_Number luaL_checknumber (lua_State *L, int numArg); 39LUALIB_API lua_Number luaL_checknumber (lua_State *L, int numArg);
40LUALIB_API lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number def); 40LUALIB_API lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number def);
41 41
42LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int numArg);
43LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int nArg,
44 lua_Integer def);
45
42LUALIB_API void luaL_checkstack (lua_State *L, int sz, const char *msg); 46LUALIB_API void luaL_checkstack (lua_State *L, int sz, const char *msg);
43LUALIB_API void luaL_checktype (lua_State *L, int narg, int t); 47LUALIB_API void luaL_checktype (lua_State *L, int narg, int t);
44LUALIB_API void luaL_checkany (lua_State *L, int narg); 48LUALIB_API void luaL_checkany (lua_State *L, int narg);
@@ -76,10 +80,10 @@ LUALIB_API lua_State *(luaL_newstate) (void);
76 luaL_argerror(L, numarg,extramsg) 80 luaL_argerror(L, numarg,extramsg)
77#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 81#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
78#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 82#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
79#define luaL_checkint(L,n) ((int)luaL_checknumber(L, n)) 83#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, n))
80#define luaL_checklong(L,n) ((long)luaL_checknumber(L, n)) 84#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, n,d))
81#define luaL_optint(L,n,d) ((int)luaL_optnumber(L, n,(lua_Number)(d))) 85#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, n))
82#define luaL_optlong(L,n,d) ((long)luaL_optnumber(L, n,(lua_Number)(d))) 86#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, n,d))
83 87
84 88
85/* 89/*
@@ -129,19 +133,6 @@ LUALIB_API int lua_dobuffer (lua_State *L, const char *buff, size_t sz,
129 const char *n); 133 const char *n);
130 134
131 135
132#define luaL_check_lstr luaL_checklstring
133#define luaL_opt_lstr luaL_optlstring
134#define luaL_check_number luaL_checknumber
135#define luaL_opt_number luaL_optnumber
136#define luaL_arg_check luaL_argcheck
137#define luaL_check_string luaL_checkstring
138#define luaL_opt_string luaL_optstring
139#define luaL_check_int luaL_checkint
140#define luaL_check_long luaL_checklong
141#define luaL_opt_int luaL_optint
142#define luaL_opt_long luaL_optlong
143
144
145#endif 136#endif
146 137
147 138
diff --git a/lbaselib.c b/lbaselib.c
index 82cc71f8..cac980a0 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.132 2003/08/25 19:49:47 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.133 2003/08/27 21:02:08 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -187,8 +187,8 @@ static int luaB_rawset (lua_State *L) {
187 187
188 188
189static int luaB_gcinfo (lua_State *L) { 189static int luaB_gcinfo (lua_State *L) {
190 lua_pushnumber(L, (lua_Number)lua_getgccount(L)); 190 lua_pushinteger(L, lua_getgccount(L));
191 lua_pushnumber(L, (lua_Number)lua_getgcthreshold(L)); 191 lua_pushinteger(L, lua_getgcthreshold(L));
192 return 2; 192 return 2;
193} 193}
194 194
@@ -229,19 +229,19 @@ static int luaB_pairs (lua_State *L) {
229 229
230 230
231static int luaB_ipairs (lua_State *L) { 231static int luaB_ipairs (lua_State *L) {
232 lua_Number i = lua_tonumber(L, 2); 232 int i = (int)lua_tointeger(L, 2);
233 luaL_checktype(L, 1, LUA_TTABLE); 233 luaL_checktype(L, 1, LUA_TTABLE);
234 if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */ 234 if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */
235 lua_pushliteral(L, "ipairs"); 235 lua_pushliteral(L, "ipairs");
236 lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */ 236 lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */
237 lua_pushvalue(L, 1); /* state, */ 237 lua_pushvalue(L, 1); /* state, */
238 lua_pushnumber(L, 0); /* and initial value */ 238 lua_pushinteger(L, 0); /* and initial value */
239 return 3; 239 return 3;
240 } 240 }
241 else { /* `for' step */ 241 else { /* `for' step */
242 i++; /* next value */ 242 i++; /* next value */
243 lua_pushnumber(L, i); 243 lua_pushinteger(L, i);
244 lua_rawgeti(L, 1, (int)i); 244 lua_rawgeti(L, 1, i);
245 return (lua_isnil(L, -1)) ? 0 : 2; 245 return (lua_isnil(L, -1)) ? 0 : 2;
246 } 246 }
247} 247}
diff --git a/ldblib.c b/ldblib.c
index ad6a448a..ba7237c2 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.80 2003/04/03 13:35:34 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.81 2003/07/07 13:37:08 roberto Exp roberto $
3** Interface from Lua to its debug API 3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -27,7 +27,7 @@ static void settabss (lua_State *L, const char *i, const char *v) {
27 27
28static void settabsi (lua_State *L, const char *i, int v) { 28static void settabsi (lua_State *L, const char *i, int v) {
29 lua_pushstring(L, i); 29 lua_pushstring(L, i);
30 lua_pushnumber(L, (lua_Number)v); 30 lua_pushinteger(L, v);
31 lua_rawset(L, -3); 31 lua_rawset(L, -3);
32} 32}
33 33
@@ -50,7 +50,7 @@ static int getinfo (lua_State *L) {
50 lua_State *L1 = getthread(L, &arg); 50 lua_State *L1 = getthread(L, &arg);
51 const char *options = luaL_optstring(L, arg+2, "flnSu"); 51 const char *options = luaL_optstring(L, arg+2, "flnSu");
52 if (lua_isnumber(L, arg+1)) { 52 if (lua_isnumber(L, arg+1)) {
53 if (!lua_getstack(L1, (int)(lua_tonumber(L, arg+1)), &ar)) { 53 if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
54 lua_pushnil(L); /* level out of range */ 54 lua_pushnil(L); /* level out of range */
55 return 1; 55 return 1;
56 } 56 }
@@ -171,7 +171,7 @@ static void hookf (lua_State *L, lua_Debug *ar) {
171 if (lua_isfunction(L, -1)) { 171 if (lua_isfunction(L, -1)) {
172 lua_pushstring(L, hooknames[(int)ar->event]); 172 lua_pushstring(L, hooknames[(int)ar->event]);
173 if (ar->currentline >= 0) 173 if (ar->currentline >= 0)
174 lua_pushnumber(L, (lua_Number)ar->currentline); 174 lua_pushinteger(L, ar->currentline);
175 else lua_pushnil(L); 175 else lua_pushnil(L);
176 lua_assert(lua_getinfo(L, "lS", ar)); 176 lua_assert(lua_getinfo(L, "lS", ar));
177 lua_call(L, 2, 0); 177 lua_call(L, 2, 0);
@@ -251,7 +251,7 @@ static int gethook (lua_State *L) {
251 lua_xmove(L1, L, 1); 251 lua_xmove(L1, L, 1);
252 } 252 }
253 lua_pushstring(L, unmakemask(mask, buff)); 253 lua_pushstring(L, unmakemask(mask, buff));
254 lua_pushnumber(L, (lua_Number)lua_gethookcount(L1)); 254 lua_pushinteger(L, lua_gethookcount(L1));
255 return 3; 255 return 3;
256} 256}
257 257
diff --git a/liolib.c b/liolib.c
index 112a1fce..29c60f00 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.45 2003/07/09 12:08:43 roberto Exp roberto $ 2** $Id: liolib.c,v 2.46 2003/08/25 19:49:47 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -76,7 +76,7 @@ static int pushresult (lua_State *L, int i, const char *filename) {
76 lua_pushfstring(L, "%s: %s", filename, strerror(errno)); 76 lua_pushfstring(L, "%s: %s", filename, strerror(errno));
77 else 77 else
78 lua_pushfstring(L, "%s", strerror(errno)); 78 lua_pushfstring(L, "%s", strerror(errno));
79 lua_pushnumber(L, errno); 79 lua_pushinteger(L, errno);
80 return 3; 80 return 3;
81 } 81 }
82} 82}
@@ -346,7 +346,7 @@ static int g_read (lua_State *L, FILE *f, int first) {
346 success = 1; 346 success = 1;
347 for (n = first; nargs-- && success; n++) { 347 for (n = first; nargs-- && success; n++) {
348 if (lua_type(L, n) == LUA_TNUMBER) { 348 if (lua_type(L, n) == LUA_TNUMBER) {
349 size_t l = (size_t)lua_tonumber(L, n); 349 size_t l = (size_t)lua_tointeger(L, n);
350 success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); 350 success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
351 } 351 }
352 else { 352 else {
@@ -441,13 +441,13 @@ static int f_seek (lua_State *L) {
441 static const char *const modenames[] = {"set", "cur", "end", NULL}; 441 static const char *const modenames[] = {"set", "cur", "end", NULL};
442 FILE *f = tofile(L, 1); 442 FILE *f = tofile(L, 1);
443 int op = luaL_findstring(luaL_optstring(L, 2, "cur"), modenames); 443 int op = luaL_findstring(luaL_optstring(L, 2, "cur"), modenames);
444 long offset = luaL_optlong(L, 3, 0); 444 lua_Integer offset = luaL_optinteger(L, 3, 0);
445 luaL_argcheck(L, op != -1, 2, "invalid mode"); 445 luaL_argcheck(L, op != -1, 2, "invalid mode");
446 op = fseek(f, offset, mode[op]); 446 op = fseek(f, offset, mode[op]);
447 if (op) 447 if (op)
448 return pushresult(L, 0, NULL); /* error */ 448 return pushresult(L, 0, NULL); /* error */
449 else { 449 else {
450 lua_pushnumber(L, ftell(f)); 450 lua_pushinteger(L, ftell(f));
451 return 1; 451 return 1;
452 } 452 }
453} 453}
@@ -528,7 +528,7 @@ static void createmeta (lua_State *L) {
528*/ 528*/
529 529
530static int io_execute (lua_State *L) { 530static int io_execute (lua_State *L) {
531 lua_pushnumber(L, system(luaL_checkstring(L, 1))); 531 lua_pushinteger(L, system(luaL_checkstring(L, 1)));
532 return 1; 532 return 1;
533} 533}
534 534
@@ -582,7 +582,7 @@ static int io_clock (lua_State *L) {
582 582
583static void setfield (lua_State *L, const char *key, int value) { 583static void setfield (lua_State *L, const char *key, int value) {
584 lua_pushstring(L, key); 584 lua_pushstring(L, key);
585 lua_pushnumber(L, value); 585 lua_pushinteger(L, value);
586 lua_rawset(L, -3); 586 lua_rawset(L, -3);
587} 587}
588 588
@@ -607,9 +607,9 @@ static int getfield (lua_State *L, const char *key, int d) {
607 lua_pushstring(L, key); 607 lua_pushstring(L, key);
608 lua_gettable(L, -2); 608 lua_gettable(L, -2);
609 if (lua_isnumber(L, -1)) 609 if (lua_isnumber(L, -1))
610 res = (int)(lua_tonumber(L, -1)); 610 res = (int)lua_tointeger(L, -1);
611 else { 611 else {
612 if (d == -2) 612 if (d < 0)
613 return luaL_error(L, "field `%s' missing in date table", key); 613 return luaL_error(L, "field `%s' missing in date table", key);
614 res = d; 614 res = d;
615 } 615 }
@@ -665,9 +665,9 @@ static int io_time (lua_State *L) {
665 ts.tm_sec = getfield(L, "sec", 0); 665 ts.tm_sec = getfield(L, "sec", 0);
666 ts.tm_min = getfield(L, "min", 0); 666 ts.tm_min = getfield(L, "min", 0);
667 ts.tm_hour = getfield(L, "hour", 12); 667 ts.tm_hour = getfield(L, "hour", 12);
668 ts.tm_mday = getfield(L, "day", -2); 668 ts.tm_mday = getfield(L, "day", -1);
669 ts.tm_mon = getfield(L, "month", -2) - 1; 669 ts.tm_mon = getfield(L, "month", -1) - 1;
670 ts.tm_year = getfield(L, "year", -2) - 1900; 670 ts.tm_year = getfield(L, "year", -1) - 1900;
671 ts.tm_isdst = getboolfield(L, "isdst"); 671 ts.tm_isdst = getboolfield(L, "isdst");
672 t = mktime(&ts); 672 t = mktime(&ts);
673 if (t == (time_t)(-1)) 673 if (t == (time_t)(-1))
diff --git a/lmathlib.c b/lmathlib.c
index a4fa618c..6afbcab6 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmathlib.c,v 1.55 2003/03/11 12:24:34 roberto Exp roberto $ 2** $Id: lmathlib.c,v 1.56 2003/03/11 12:30:37 roberto Exp roberto $
3** Standard mathematical library 3** Standard mathematical library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -128,7 +128,7 @@ static int math_rad (lua_State *L) {
128static int math_frexp (lua_State *L) { 128static int math_frexp (lua_State *L) {
129 int e; 129 int e;
130 lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); 130 lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
131 lua_pushnumber(L, e); 131 lua_pushinteger(L, e);
132 return 2; 132 return 2;
133} 133}
134 134
@@ -179,14 +179,14 @@ static int math_random (lua_State *L) {
179 case 1: { /* only upper limit */ 179 case 1: { /* only upper limit */
180 int u = luaL_checkint(L, 1); 180 int u = luaL_checkint(L, 1);
181 luaL_argcheck(L, 1<=u, 1, "interval is empty"); 181 luaL_argcheck(L, 1<=u, 1, "interval is empty");
182 lua_pushnumber(L, (int)floor(r*u)+1); /* int between 1 and `u' */ 182 lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */
183 break; 183 break;
184 } 184 }
185 case 2: { /* lower and upper limits */ 185 case 2: { /* lower and upper limits */
186 int l = luaL_checkint(L, 1); 186 int l = luaL_checkint(L, 1);
187 int u = luaL_checkint(L, 2); 187 int u = luaL_checkint(L, 2);
188 luaL_argcheck(L, l<=u, 2, "interval is empty"); 188 luaL_argcheck(L, l<=u, 2, "interval is empty");
189 lua_pushnumber(L, (int)floor(r*(u-l+1))+l); /* int between `l' and `u' */ 189 lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */
190 break; 190 break;
191 } 191 }
192 default: return luaL_error(L, "wrong number of arguments"); 192 default: return luaL_error(L, "wrong number of arguments");
diff --git a/lstrlib.c b/lstrlib.c
index 7340e94c..e239e2fb 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.98 2003/04/03 13:35:34 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.99 2003/05/14 14:35:54 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -25,13 +25,13 @@
25#endif 25#endif
26 26
27 27
28typedef long sint32; /* a signed version for size_t */ 28typedef lua_Integer sint32; /* a signed version for size_t */
29 29
30 30
31static int str_len (lua_State *L) { 31static int str_len (lua_State *L) {
32 size_t l; 32 size_t l;
33 luaL_checklstring(L, 1, &l); 33 luaL_checklstring(L, 1, &l);
34 lua_pushnumber(L, (lua_Number)l); 34 lua_pushinteger(L, l);
35 return 1; 35 return 1;
36} 36}
37 37
@@ -45,8 +45,8 @@ static sint32 posrelat (sint32 pos, size_t len) {
45static int str_sub (lua_State *L) { 45static int str_sub (lua_State *L) {
46 size_t l; 46 size_t l;
47 const char *s = luaL_checklstring(L, 1, &l); 47 const char *s = luaL_checklstring(L, 1, &l);
48 sint32 start = posrelat(luaL_checklong(L, 2), l); 48 sint32 start = posrelat(luaL_checkinteger(L, 2), l);
49 sint32 end = posrelat(luaL_optlong(L, 3, -1), l); 49 sint32 end = posrelat(luaL_optinteger(L, 3, -1), l);
50 if (start < 1) start = 1; 50 if (start < 1) start = 1;
51 if (end > (sint32)l) end = (sint32)l; 51 if (end > (sint32)l) end = (sint32)l;
52 if (start <= end) 52 if (start <= end)
@@ -108,10 +108,10 @@ static int str_rep (lua_State *L) {
108static int str_byte (lua_State *L) { 108static int str_byte (lua_State *L) {
109 size_t l; 109 size_t l;
110 const char *s = luaL_checklstring(L, 1, &l); 110 const char *s = luaL_checklstring(L, 1, &l);
111 sint32 pos = posrelat(luaL_optlong(L, 2, 1), l); 111 sint32 pos = posrelat(luaL_optinteger(L, 2, 1), l);
112 if (pos <= 0 || (size_t)(pos) > l) /* index out of range? */ 112 if (pos <= 0 || (size_t)(pos) > l) /* index out of range? */
113 return 0; /* no answer */ 113 return 0; /* no answer */
114 lua_pushnumber(L, uchar(s[pos-1])); 114 lua_pushinteger(L, uchar(s[pos-1]));
115 return 1; 115 return 1;
116} 116}
117 117
@@ -463,7 +463,7 @@ static void push_onecapture (MatchState *ms, int i) {
463 int l = ms->capture[i].len; 463 int l = ms->capture[i].len;
464 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); 464 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
465 if (l == CAP_POSITION) 465 if (l == CAP_POSITION)
466 lua_pushnumber(ms->L, (lua_Number)(ms->capture[i].init - ms->src_init + 1)); 466 lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
467 else 467 else
468 lua_pushlstring(ms->L, ms->capture[i].init, l); 468 lua_pushlstring(ms->L, ms->capture[i].init, l);
469} 469}
@@ -488,7 +488,7 @@ static int str_find (lua_State *L) {
488 size_t l1, l2; 488 size_t l1, l2;
489 const char *s = luaL_checklstring(L, 1, &l1); 489 const char *s = luaL_checklstring(L, 1, &l1);
490 const char *p = luaL_checklstring(L, 2, &l2); 490 const char *p = luaL_checklstring(L, 2, &l2);
491 sint32 init = posrelat(luaL_optlong(L, 3, 1), l1) - 1; 491 sint32 init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
492 if (init < 0) init = 0; 492 if (init < 0) init = 0;
493 else if ((size_t)(init) > l1) init = (sint32)l1; 493 else if ((size_t)(init) > l1) init = (sint32)l1;
494 if (lua_toboolean(L, 4) || /* explicit request? */ 494 if (lua_toboolean(L, 4) || /* explicit request? */
@@ -496,8 +496,8 @@ static int str_find (lua_State *L) {
496 /* do a plain search */ 496 /* do a plain search */
497 const char *s2 = lmemfind(s+init, l1-init, p, l2); 497 const char *s2 = lmemfind(s+init, l1-init, p, l2);
498 if (s2) { 498 if (s2) {
499 lua_pushnumber(L, (lua_Number)(s2-s+1)); 499 lua_pushinteger(L, s2-s+1);
500 lua_pushnumber(L, (lua_Number)(s2-s+l2)); 500 lua_pushinteger(L, s2-s+l2);
501 return 2; 501 return 2;
502 } 502 }
503 } 503 }
@@ -512,8 +512,8 @@ static int str_find (lua_State *L) {
512 const char *res; 512 const char *res;
513 ms.level = 0; 513 ms.level = 0;
514 if ((res=match(&ms, s1, p)) != NULL) { 514 if ((res=match(&ms, s1, p)) != NULL) {
515 lua_pushnumber(L, (lua_Number)(s1-s+1)); /* start */ 515 lua_pushinteger(L, s1-s+1); /* start */
516 lua_pushnumber(L, (lua_Number)(res-s)); /* end */ 516 lua_pushinteger(L, res-s); /* end */
517 return push_captures(&ms, NULL, 0) + 2; 517 return push_captures(&ms, NULL, 0) + 2;
518 } 518 }
519 } while (s1++<ms.src_end && !anchor); 519 } while (s1++<ms.src_end && !anchor);
@@ -532,7 +532,7 @@ static int gfind_aux (lua_State *L) {
532 ms.L = L; 532 ms.L = L;
533 ms.src_init = s; 533 ms.src_init = s;
534 ms.src_end = s+ls; 534 ms.src_end = s+ls;
535 for (src = s + (size_t)lua_tonumber(L, lua_upvalueindex(3)); 535 for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));
536 src <= ms.src_end; 536 src <= ms.src_end;
537 src++) { 537 src++) {
538 const char *e; 538 const char *e;
@@ -540,7 +540,7 @@ static int gfind_aux (lua_State *L) {
540 if ((e = match(&ms, src, p)) != NULL) { 540 if ((e = match(&ms, src, p)) != NULL) {
541 int newstart = e-s; 541 int newstart = e-s;
542 if (e == src) newstart++; /* empty match? go at least one position */ 542 if (e == src) newstart++; /* empty match? go at least one position */
543 lua_pushnumber(L, (lua_Number)newstart); 543 lua_pushinteger(L, newstart);
544 lua_replace(L, lua_upvalueindex(3)); 544 lua_replace(L, lua_upvalueindex(3));
545 return push_captures(&ms, src, e); 545 return push_captures(&ms, src, e);
546 } 546 }
@@ -553,7 +553,7 @@ static int gfind (lua_State *L) {
553 luaL_checkstring(L, 1); 553 luaL_checkstring(L, 1);
554 luaL_checkstring(L, 2); 554 luaL_checkstring(L, 2);
555 lua_settop(L, 2); 555 lua_settop(L, 2);
556 lua_pushnumber(L, 0); 556 lua_pushinteger(L, 0);
557 lua_pushcclosure(L, gfind_aux, 3); 557 lua_pushcclosure(L, gfind_aux, 3);
558 return 1; 558 return 1;
559} 559}
@@ -627,7 +627,7 @@ static int str_gsub (lua_State *L) {
627 } 627 }
628 luaL_addlstring(&b, src, ms.src_end-src); 628 luaL_addlstring(&b, src, ms.src_end-src);
629 luaL_pushresult(&b); 629 luaL_pushresult(&b);
630 lua_pushnumber(L, (lua_Number)n); /* number of substitutions */ 630 lua_pushinteger(L, n); /* number of substitutions */
631 return 2; 631 return 2;
632} 632}
633 633
diff --git a/ltablib.c b/ltablib.c
index 39447e29..601e0df7 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltablib.c,v 1.20 2003/03/11 12:24:34 roberto Exp roberto $ 2** $Id: ltablib.c,v 1.21 2003/04/03 13:35:34 roberto Exp roberto $
3** Library for Table Manipulation 3** Library for Table Manipulation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -24,7 +24,7 @@ static int luaB_foreachi (lua_State *L) {
24 luaL_checktype(L, 2, LUA_TFUNCTION); 24 luaL_checktype(L, 2, LUA_TFUNCTION);
25 for (i=1; i<=n; i++) { 25 for (i=1; i<=n; i++) {
26 lua_pushvalue(L, 2); /* function */ 26 lua_pushvalue(L, 2); /* function */
27 lua_pushnumber(L, (lua_Number)i); /* 1st argument */ 27 lua_pushinteger(L, i); /* 1st argument */
28 lua_rawgeti(L, 1, i); /* 2nd argument */ 28 lua_rawgeti(L, 1, i); /* 2nd argument */
29 lua_call(L, 2, 1); 29 lua_call(L, 2, 1);
30 if (!lua_isnil(L, -1)) 30 if (!lua_isnil(L, -1))
@@ -54,7 +54,7 @@ static int luaB_foreach (lua_State *L) {
54 54
55 55
56static int luaB_getn (lua_State *L) { 56static int luaB_getn (lua_State *L) {
57 lua_pushnumber(L, (lua_Number)aux_getn(L, 1)); 57 lua_pushinteger(L, aux_getn(L, 1));
58 return 1; 58 return 1;
59} 59}
60 60
diff --git a/ltests.c b/ltests.c
index 2c0f5869..63e3cc5e 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.163 2003/07/29 19:26:34 roberto Exp roberto $ 2** $Id: ltests.c,v 1.164 2003/10/02 20:31:17 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -36,9 +36,6 @@
36#ifdef LUA_DEBUG 36#ifdef LUA_DEBUG
37 37
38 38
39#define lua_pushintegral(L,i) lua_pushnumber(L, cast(lua_Number, (i)))
40
41
42static lua_State *lua_state = NULL; 39static lua_State *lua_state = NULL;
43 40
44int islocked = 0; 41int islocked = 0;
@@ -49,7 +46,7 @@ int islocked = 0;
49 46
50static void setnameval (lua_State *L, const char *name, int val) { 47static void setnameval (lua_State *L, const char *name, int val) {
51 lua_pushstring(L, name); 48 lua_pushstring(L, name);
52 lua_pushintegral(L, val); 49 lua_pushinteger(L, val);
53 lua_settable(L, -3); 50 lua_settable(L, -3);
54} 51}
55 52
@@ -196,7 +193,7 @@ static int listcode (lua_State *L) {
196 setnameval(L, "numparams", p->numparams); 193 setnameval(L, "numparams", p->numparams);
197 for (pc=0; pc<p->sizecode; pc++) { 194 for (pc=0; pc<p->sizecode; pc++) {
198 char buff[100]; 195 char buff[100];
199 lua_pushintegral(L, pc+1); 196 lua_pushinteger(L, pc+1);
200 lua_pushstring(L, buildop(p, pc, buff)); 197 lua_pushstring(L, buildop(p, pc, buff));
201 lua_settable(L, -3); 198 lua_settable(L, -3);
202 } 199 }
@@ -212,7 +209,7 @@ static int listk (lua_State *L) {
212 p = clvalue(func_at(L, 1))->l.p; 209 p = clvalue(func_at(L, 1))->l.p;
213 lua_newtable(L); 210 lua_newtable(L);
214 for (i=0; i<p->sizek; i++) { 211 for (i=0; i<p->sizek; i++) {
215 lua_pushintegral(L, i+1); 212 lua_pushinteger(L, i+1);
216 luaA_pushobject(L, p->k+i); 213 luaA_pushobject(L, p->k+i);
217 lua_settable(L, -3); 214 lua_settable(L, -3);
218 } 215 }
@@ -257,9 +254,9 @@ static int setgcthreshold (lua_State *L) {
257 254
258static int mem_query (lua_State *L) { 255static int mem_query (lua_State *L) {
259 if (lua_isnone(L, 1)) { 256 if (lua_isnone(L, 1)) {
260 lua_pushintegral(L, memcontrol.total); 257 lua_pushinteger(L, memcontrol.total);
261 lua_pushintegral(L, memcontrol.numblocks); 258 lua_pushinteger(L, memcontrol.numblocks);
262 lua_pushintegral(L, memcontrol.maxmem); 259 lua_pushinteger(L, memcontrol.maxmem);
263 return 3; 260 return 3;
264 } 261 }
265 else { 262 else {
@@ -272,14 +269,14 @@ static int mem_query (lua_State *L) {
272static int hash_query (lua_State *L) { 269static int hash_query (lua_State *L) {
273 if (lua_isnone(L, 2)) { 270 if (lua_isnone(L, 2)) {
274 luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); 271 luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected");
275 lua_pushintegral(L, tsvalue(func_at(L, 1))->tsv.hash); 272 lua_pushinteger(L, tsvalue(func_at(L, 1))->tsv.hash);
276 } 273 }
277 else { 274 else {
278 TObject *o = func_at(L, 1); 275 TObject *o = func_at(L, 1);
279 Table *t; 276 Table *t;
280 luaL_checktype(L, 2, LUA_TTABLE); 277 luaL_checktype(L, 2, LUA_TTABLE);
281 t = hvalue(func_at(L, 2)); 278 t = hvalue(func_at(L, 2));
282 lua_pushintegral(L, luaH_mainposition(t, o) - t->node); 279 lua_pushinteger(L, luaH_mainposition(t, o) - t->node);
283 } 280 }
284 return 1; 281 return 1;
285} 282}
@@ -287,11 +284,11 @@ static int hash_query (lua_State *L) {
287 284
288static int stacklevel (lua_State *L) { 285static int stacklevel (lua_State *L) {
289 unsigned long a = 0; 286 unsigned long a = 0;
290 lua_pushintegral(L, (int)(L->top - L->stack)); 287 lua_pushinteger(L, (L->top - L->stack));
291 lua_pushintegral(L, (int)(L->stack_last - L->stack)); 288 lua_pushinteger(L, (L->stack_last - L->stack));
292 lua_pushintegral(L, (int)(L->ci - L->base_ci)); 289 lua_pushinteger(L, (L->ci - L->base_ci));
293 lua_pushintegral(L, (int)(L->end_ci - L->base_ci)); 290 lua_pushinteger(L, (L->end_ci - L->base_ci));
294 lua_pushintegral(L, (unsigned long)&a); 291 lua_pushinteger(L, (unsigned long)&a);
295 return 5; 292 return 5;
296} 293}
297 294
@@ -302,12 +299,12 @@ static int table_query (lua_State *L) {
302 luaL_checktype(L, 1, LUA_TTABLE); 299 luaL_checktype(L, 1, LUA_TTABLE);
303 t = hvalue(func_at(L, 1)); 300 t = hvalue(func_at(L, 1));
304 if (i == -1) { 301 if (i == -1) {
305 lua_pushintegral(L, t->sizearray); 302 lua_pushinteger(L, t->sizearray);
306 lua_pushintegral(L, sizenode(t)); 303 lua_pushinteger(L, sizenode(t));
307 lua_pushintegral(L, t->firstfree - t->node); 304 lua_pushinteger(L, t->firstfree - t->node);
308 } 305 }
309 else if (i < t->sizearray) { 306 else if (i < t->sizearray) {
310 lua_pushintegral(L, i); 307 lua_pushinteger(L, i);
311 luaA_pushobject(L, &t->array[i]); 308 luaA_pushobject(L, &t->array[i]);
312 lua_pushnil(L); 309 lua_pushnil(L);
313 } 310 }
@@ -321,7 +318,7 @@ static int table_query (lua_State *L) {
321 lua_pushliteral(L, "<undef>"); 318 lua_pushliteral(L, "<undef>");
322 luaA_pushobject(L, gval(gnode(t, i))); 319 luaA_pushobject(L, gval(gnode(t, i)));
323 if (t->node[i].next) 320 if (t->node[i].next)
324 lua_pushintegral(L, t->node[i].next - t->node); 321 lua_pushinteger(L, t->node[i].next - t->node);
325 else 322 else
326 lua_pushnil(L); 323 lua_pushnil(L);
327 } 324 }
@@ -333,8 +330,8 @@ static int string_query (lua_State *L) {
333 stringtable *tb = &G(L)->strt; 330 stringtable *tb = &G(L)->strt;
334 int s = luaL_optint(L, 2, 0) - 1; 331 int s = luaL_optint(L, 2, 0) - 1;
335 if (s==-1) { 332 if (s==-1) {
336 lua_pushintegral(L ,tb->nuse); 333 lua_pushinteger(L ,tb->nuse);
337 lua_pushintegral(L ,tb->size); 334 lua_pushinteger(L ,tb->size);
338 return 2; 335 return 2;
339 } 336 }
340 else if (s < tb->size) { 337 else if (s < tb->size) {
@@ -356,7 +353,7 @@ static int tref (lua_State *L) {
356 int lock = luaL_optint(L, 2, 1); 353 int lock = luaL_optint(L, 2, 1);
357 luaL_checkany(L, 1); 354 luaL_checkany(L, 1);
358 lua_pushvalue(L, 1); 355 lua_pushvalue(L, 1);
359 lua_pushintegral(L, lua_ref(L, lock)); 356 lua_pushinteger(L, lua_ref(L, lock));
360 assert(lua_gettop(L) == level+1); /* +1 for result */ 357 assert(lua_gettop(L) == level+1); /* +1 for result */
361 return 1; 358 return 1;
362} 359}
@@ -422,7 +419,7 @@ static int pushuserdata (lua_State *L) {
422 419
423 420
424static int udataval (lua_State *L) { 421static int udataval (lua_State *L) {
425 lua_pushintegral(L, cast(int, lua_touserdata(L, 1))); 422 lua_pushinteger(L, cast(long, lua_touserdata(L, 1)));
426 return 1; 423 return 1;
427} 424}
428 425
@@ -434,7 +431,7 @@ static int doonnewstack (lua_State *L) {
434 int status = luaL_loadbuffer(L1, s, l, s); 431 int status = luaL_loadbuffer(L1, s, l, s);
435 if (status == 0) 432 if (status == 0)
436 status = lua_pcall(L1, 0, 0, 0); 433 status = lua_pcall(L1, 0, 0, 0);
437 lua_pushintegral(L, status); 434 lua_pushinteger(L, status);
438 return 1; 435 return 1;
439} 436}
440 437
@@ -455,7 +452,7 @@ static int newstate (lua_State *L) {
455 lua_State *L1 = lua_open(); 452 lua_State *L1 = lua_open();
456 if (L1) { 453 if (L1) {
457 lua_userstateopen(L1); /* init lock */ 454 lua_userstateopen(L1); /* init lock */
458 lua_pushintegral(L, (unsigned long)L1); 455 lua_pushinteger(L, (unsigned long)L1);
459 } 456 }
460 else 457 else
461 lua_pushnil(L); 458 lua_pushnil(L);
@@ -498,7 +495,7 @@ static int doremote (lua_State *L) {
498 status = lua_pcall(L1, 0, LUA_MULTRET, 0); 495 status = lua_pcall(L1, 0, LUA_MULTRET, 0);
499 if (status != 0) { 496 if (status != 0) {
500 lua_pushnil(L); 497 lua_pushnil(L);
501 lua_pushintegral(L, status); 498 lua_pushinteger(L, status);
502 lua_pushstring(L, lua_tostring(L1, -1)); 499 lua_pushstring(L, lua_tostring(L1, -1));
503 return 3; 500 return 3;
504 } 501 }
@@ -513,14 +510,14 @@ static int doremote (lua_State *L) {
513 510
514 511
515static int log2_aux (lua_State *L) { 512static int log2_aux (lua_State *L) {
516 lua_pushintegral(L, luaO_log2(luaL_checkint(L, 1))); 513 lua_pushinteger(L, luaO_log2(luaL_checkint(L, 1)));
517 return 1; 514 return 1;
518} 515}
519 516
520static int int2fb_aux (lua_State *L) { 517static int int2fb_aux (lua_State *L) {
521 int b = luaO_int2fb(luaL_checkint(L, 1)); 518 int b = luaO_int2fb(luaL_checkint(L, 1));
522 lua_pushintegral(L, b); 519 lua_pushinteger(L, b);
523 lua_pushintegral(L, fb2int(b)); 520 lua_pushinteger(L, fb2int(b));
524 return 2; 521 return 2;
525} 522}
526 523
@@ -590,31 +587,31 @@ static int testC (lua_State *L) {
590 const char *inst = getname; 587 const char *inst = getname;
591 if EQ("") return 0; 588 if EQ("") return 0;
592 else if EQ("isnumber") { 589 else if EQ("isnumber") {
593 lua_pushintegral(L, lua_isnumber(L, getnum)); 590 lua_pushinteger(L, lua_isnumber(L, getnum));
594 } 591 }
595 else if EQ("isstring") { 592 else if EQ("isstring") {
596 lua_pushintegral(L, lua_isstring(L, getnum)); 593 lua_pushinteger(L, lua_isstring(L, getnum));
597 } 594 }
598 else if EQ("istable") { 595 else if EQ("istable") {
599 lua_pushintegral(L, lua_istable(L, getnum)); 596 lua_pushinteger(L, lua_istable(L, getnum));
600 } 597 }
601 else if EQ("iscfunction") { 598 else if EQ("iscfunction") {
602 lua_pushintegral(L, lua_iscfunction(L, getnum)); 599 lua_pushinteger(L, lua_iscfunction(L, getnum));
603 } 600 }
604 else if EQ("isfunction") { 601 else if EQ("isfunction") {
605 lua_pushintegral(L, lua_isfunction(L, getnum)); 602 lua_pushinteger(L, lua_isfunction(L, getnum));
606 } 603 }
607 else if EQ("isuserdata") { 604 else if EQ("isuserdata") {
608 lua_pushintegral(L, lua_isuserdata(L, getnum)); 605 lua_pushinteger(L, lua_isuserdata(L, getnum));
609 } 606 }
610 else if EQ("isudataval") { 607 else if EQ("isudataval") {
611 lua_pushintegral(L, lua_islightuserdata(L, getnum)); 608 lua_pushinteger(L, lua_islightuserdata(L, getnum));
612 } 609 }
613 else if EQ("isnil") { 610 else if EQ("isnil") {
614 lua_pushintegral(L, lua_isnil(L, getnum)); 611 lua_pushinteger(L, lua_isnil(L, getnum));
615 } 612 }
616 else if EQ("isnull") { 613 else if EQ("isnull") {
617 lua_pushintegral(L, lua_isnone(L, getnum)); 614 lua_pushinteger(L, lua_isnone(L, getnum));
618 } 615 }
619 else if EQ("tonumber") { 616 else if EQ("tonumber") {
620 lua_pushnumber(L, lua_tonumber(L, getnum)); 617 lua_pushnumber(L, lua_tonumber(L, getnum));
@@ -624,7 +621,7 @@ static int testC (lua_State *L) {
624 lua_pushstring(L, s); 621 lua_pushstring(L, s);
625 } 622 }
626 else if EQ("strlen") { 623 else if EQ("strlen") {
627 lua_pushintegral(L, lua_strlen(L, getnum)); 624 lua_pushinteger(L, lua_strlen(L, getnum));
628 } 625 }
629 else if EQ("tocfunction") { 626 else if EQ("tocfunction") {
630 lua_pushcfunction(L, lua_tocfunction(L, getnum)); 627 lua_pushcfunction(L, lua_tocfunction(L, getnum));
@@ -633,7 +630,7 @@ static int testC (lua_State *L) {
633 return getnum; 630 return getnum;
634 } 631 }
635 else if EQ("gettop") { 632 else if EQ("gettop") {
636 lua_pushintegral(L, lua_gettop(L)); 633 lua_pushinteger(L, lua_gettop(L));
637 } 634 }
638 else if EQ("settop") { 635 else if EQ("settop") {
639 lua_settop(L, getnum); 636 lua_settop(L, getnum);
@@ -642,7 +639,7 @@ static int testC (lua_State *L) {
642 lua_pop(L, getnum); 639 lua_pop(L, getnum);
643 } 640 }
644 else if EQ("pushnum") { 641 else if EQ("pushnum") {
645 lua_pushintegral(L, getnum); 642 lua_pushinteger(L, getnum);
646 } 643 }
647 else if EQ("pushnil") { 644 else if EQ("pushnil") {
648 lua_pushnil(L); 645 lua_pushnil(L);
@@ -651,7 +648,7 @@ static int testC (lua_State *L) {
651 lua_pushboolean(L, getnum); 648 lua_pushboolean(L, getnum);
652 } 649 }
653 else if EQ("tobool") { 650 else if EQ("tobool") {
654 lua_pushintegral(L, lua_toboolean(L, getnum)); 651 lua_pushinteger(L, lua_toboolean(L, getnum));
655 } 652 }
656 else if EQ("pushvalue") { 653 else if EQ("pushvalue") {
657 lua_pushvalue(L, getnum); 654 lua_pushvalue(L, getnum);
@@ -718,7 +715,7 @@ static int testC (lua_State *L) {
718 } 715 }
719 else if EQ("getn") { 716 else if EQ("getn") {
720 int i = getnum; 717 int i = getnum;
721 lua_pushintegral(L, luaL_getn(L, i)); 718 lua_pushinteger(L, luaL_getn(L, i));
722 } 719 }
723 else if EQ("setn") { 720 else if EQ("setn") {
724 int i = getnum; 721 int i = getnum;
diff --git a/lua.h b/lua.h
index abea10af..b0b80f43 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.178 2003/07/07 13:30:57 roberto Exp roberto $ 2** $Id: lua.h,v 1.179 2003/10/02 20:31:17 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil 4** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
5** http://www.lua.org mailto:info@lua.org 5** http://www.lua.org mailto:info@lua.org
@@ -98,6 +98,14 @@ typedef LUA_NUMBER lua_Number;
98#endif 98#endif
99 99
100 100
101/* type for integer functions */
102#ifndef LUA_INTEGER
103typedef long lua_Integer;
104#else
105typedef LUA_INTEGER lua_Integer;
106#endif
107
108
101/* mark for all API functions */ 109/* mark for all API functions */
102#ifndef LUA_API 110#ifndef LUA_API
103#define LUA_API extern 111#define LUA_API extern
@@ -144,6 +152,7 @@ LUA_API int lua_rawequal (lua_State *L, int idx1, int idx2);
144LUA_API int lua_lessthan (lua_State *L, int idx1, int idx2); 152LUA_API int lua_lessthan (lua_State *L, int idx1, int idx2);
145 153
146LUA_API lua_Number lua_tonumber (lua_State *L, int idx); 154LUA_API lua_Number lua_tonumber (lua_State *L, int idx);
155LUA_API lua_Integer lua_tointeger (lua_State *L, int idx);
147LUA_API int lua_toboolean (lua_State *L, int idx); 156LUA_API int lua_toboolean (lua_State *L, int idx);
148LUA_API const char *lua_tostring (lua_State *L, int idx); 157LUA_API const char *lua_tostring (lua_State *L, int idx);
149LUA_API size_t lua_strlen (lua_State *L, int idx); 158LUA_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);
158*/ 167*/
159LUA_API void lua_pushnil (lua_State *L); 168LUA_API void lua_pushnil (lua_State *L);
160LUA_API void lua_pushnumber (lua_State *L, lua_Number n); 169LUA_API void lua_pushnumber (lua_State *L, lua_Number n);
170LUA_API void lua_pushinteger (lua_State *L, lua_Integer n);
161LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t l); 171LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t l);
162LUA_API void lua_pushstring (lua_State *L, const char *s); 172LUA_API void lua_pushstring (lua_State *L, const char *s);
163LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt, 173LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,