瀏覽代碼

simpler tests for simpler API

Roberto Ierusalimschy 25 年之前
父節點
當前提交
a0de89d62a
共有 1 個文件被更改,包括 11 次插入28 次删除
  1. 11 28
      ltests.c

+ 11 - 28
ltests.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltests.c,v 1.36 2000/08/29 14:57:10 roberto Exp roberto $
+** $Id: ltests.c,v 1.37 2000/08/29 19:05:11 roberto Exp roberto $
 ** Internal Module for Debugging of the Lua Implementation
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -335,32 +335,24 @@ static void skip (const char **pc) {
   while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++;
   while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++;
 }
 }
 
 
-static int getnum (const char **pc, int *reg) {
+static int getnum (lua_State *L, const char **pc) {
   int res = 0;
   int res = 0;
   int sig = 1;
   int sig = 1;
-  int ref = 0;
   skip(pc);
   skip(pc);
-  if (**pc == 'r') {
-    ref = 1;
+  if (**pc == '.') {
+    res = (int)lua_tonumber(L, -1);
+    lua_settop(L, -1);
     (*pc)++;
     (*pc)++;
+    return res;
   }
   }
   else if (**pc == '-') {
   else if (**pc == '-') {
     sig = -1;
     sig = -1;
     (*pc)++;
     (*pc)++;
   }
   }
   while (isdigit(**pc)) res = res*10 + (*(*pc)++) - '0';
   while (isdigit(**pc)) res = res*10 + (*(*pc)++) - '0';
-  if (!ref)
-    return sig*res;
-  else
-    return reg[res];
+  return sig*res;
 }
 }
   
   
-static int getreg (const char **pc) {
-  skip(pc);
-  (*pc)++;  /* skip the `r' */
-  return getnum(pc, NULL);
-}
-
 static const char *getname (char *buff, const char **pc) {
 static const char *getname (char *buff, const char **pc) {
   int i = 0;
   int i = 0;
   skip(pc);
   skip(pc);
@@ -373,14 +365,12 @@ static const char *getname (char *buff, const char **pc) {
 
 
 #define EQ(s1)	(strcmp(s1, inst) == 0)
 #define EQ(s1)	(strcmp(s1, inst) == 0)
 
 
-#define getnum	((getnum)(&pc, reg))
-#define getreg	((getreg)(&pc))
+#define getnum	((getnum)(L, &pc))
 #define getname	((getname)(buff, &pc))
 #define getname	((getname)(buff, &pc))
 
 
 
 
 static int testC (lua_State *L) {
 static int testC (lua_State *L) {
   char buff[30];
   char buff[30];
-  int reg[10];
   const char *pc = luaL_check_string(L, 1);
   const char *pc = luaL_check_string(L, 1);
   for (;;) {
   for (;;) {
     const char *inst = getname;
     const char *inst = getname;
@@ -388,27 +378,20 @@ static int testC (lua_State *L) {
     else if EQ("return") {
     else if EQ("return") {
       return getnum;
       return getnum;
     }
     }
-    else if EQ("retall") {
-      return lua_gettop(L) - 1;
-    }
     else if EQ("gettop") {
     else if EQ("gettop") {
-      reg[getreg] = lua_gettop(L);
+      lua_pushnumber(L, lua_gettop(L));
     }
     }
     else if EQ("settop") {
     else if EQ("settop") {
       lua_settop(L, getnum);
       lua_settop(L, getnum);
     }
     }
-    else if EQ("setreg") {
-      int n = getreg;
-      reg[n] = lua_tonumber(L, getnum);
-    }
     else if EQ("pushnum") {
     else if EQ("pushnum") {
       lua_pushnumber(L, getnum);
       lua_pushnumber(L, getnum);
     }
     }
     else if EQ("pushobject") {
     else if EQ("pushobject") {
       lua_pushobject(L, getnum);
       lua_pushobject(L, getnum);
     }
     }
-    else if EQ("pushstring") {
-      lua_pushstring(L, getname);
+    else if EQ("next") {
+      lua_next(L);
     }
     }
     else if EQ("call") {
     else if EQ("call") {
       int narg = getnum;
       int narg = getnum;