aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ltests.c39
1 files changed, 11 insertions, 28 deletions
diff --git a/ltests.c b/ltests.c
index a8aafcb9..45b1f1c0 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.36 2000/08/29 14:57:10 roberto Exp roberto $ 2** $Id: ltests.c,v 1.37 2000/08/29 19:05:11 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*/
@@ -335,32 +335,24 @@ static void skip (const char **pc) {
335 while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++; 335 while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++;
336} 336}
337 337
338static int getnum (const char **pc, int *reg) { 338static int getnum (lua_State *L, const char **pc) {
339 int res = 0; 339 int res = 0;
340 int sig = 1; 340 int sig = 1;
341 int ref = 0;
342 skip(pc); 341 skip(pc);
343 if (**pc == 'r') { 342 if (**pc == '.') {
344 ref = 1; 343 res = (int)lua_tonumber(L, -1);
344 lua_settop(L, -1);
345 (*pc)++; 345 (*pc)++;
346 return res;
346 } 347 }
347 else if (**pc == '-') { 348 else if (**pc == '-') {
348 sig = -1; 349 sig = -1;
349 (*pc)++; 350 (*pc)++;
350 } 351 }
351 while (isdigit(**pc)) res = res*10 + (*(*pc)++) - '0'; 352 while (isdigit(**pc)) res = res*10 + (*(*pc)++) - '0';
352 if (!ref) 353 return sig*res;
353 return sig*res;
354 else
355 return reg[res];
356} 354}
357 355
358static int getreg (const char **pc) {
359 skip(pc);
360 (*pc)++; /* skip the `r' */
361 return getnum(pc, NULL);
362}
363
364static const char *getname (char *buff, const char **pc) { 356static const char *getname (char *buff, const char **pc) {
365 int i = 0; 357 int i = 0;
366 skip(pc); 358 skip(pc);
@@ -373,14 +365,12 @@ static const char *getname (char *buff, const char **pc) {
373 365
374#define EQ(s1) (strcmp(s1, inst) == 0) 366#define EQ(s1) (strcmp(s1, inst) == 0)
375 367
376#define getnum ((getnum)(&pc, reg)) 368#define getnum ((getnum)(L, &pc))
377#define getreg ((getreg)(&pc))
378#define getname ((getname)(buff, &pc)) 369#define getname ((getname)(buff, &pc))
379 370
380 371
381static int testC (lua_State *L) { 372static int testC (lua_State *L) {
382 char buff[30]; 373 char buff[30];
383 int reg[10];
384 const char *pc = luaL_check_string(L, 1); 374 const char *pc = luaL_check_string(L, 1);
385 for (;;) { 375 for (;;) {
386 const char *inst = getname; 376 const char *inst = getname;
@@ -388,27 +378,20 @@ static int testC (lua_State *L) {
388 else if EQ("return") { 378 else if EQ("return") {
389 return getnum; 379 return getnum;
390 } 380 }
391 else if EQ("retall") {
392 return lua_gettop(L) - 1;
393 }
394 else if EQ("gettop") { 381 else if EQ("gettop") {
395 reg[getreg] = lua_gettop(L); 382 lua_pushnumber(L, lua_gettop(L));
396 } 383 }
397 else if EQ("settop") { 384 else if EQ("settop") {
398 lua_settop(L, getnum); 385 lua_settop(L, getnum);
399 } 386 }
400 else if EQ("setreg") {
401 int n = getreg;
402 reg[n] = lua_tonumber(L, getnum);
403 }
404 else if EQ("pushnum") { 387 else if EQ("pushnum") {
405 lua_pushnumber(L, getnum); 388 lua_pushnumber(L, getnum);
406 } 389 }
407 else if EQ("pushobject") { 390 else if EQ("pushobject") {
408 lua_pushobject(L, getnum); 391 lua_pushobject(L, getnum);
409 } 392 }
410 else if EQ("pushstring") { 393 else if EQ("next") {
411 lua_pushstring(L, getname); 394 lua_next(L);
412 } 395 }
413 else if EQ("call") { 396 else if EQ("call") {
414 int narg = getnum; 397 int narg = getnum;