aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c89
1 files changed, 43 insertions, 46 deletions
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;