diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-06-02 14:06:42 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-06-02 14:06:42 -0300 |
| commit | 989ad7232af7d3c12848129e1f1ff01943535d0e (patch) | |
| tree | a6dc7d7b27e492c255582789bb38d8f74b5f6a94 | |
| parent | 190c3be739b0dd9134070555c6c11b8d2f2a7629 (diff) | |
| download | lua-989ad7232af7d3c12848129e1f1ff01943535d0e.tar.gz lua-989ad7232af7d3c12848129e1f1ff01943535d0e.tar.bz2 lua-989ad7232af7d3c12848129e1f1ff01943535d0e.zip | |
changed to test macros for single-state use
| -rw-r--r-- | ltests.c | 270 |
1 files changed, 136 insertions, 134 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.20 2000/05/22 18:44:46 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.21 2000/05/26 19:17:57 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 | */ |
| @@ -10,7 +10,6 @@ | |||
| 10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 11 | #include <string.h> | 11 | #include <string.h> |
| 12 | 12 | ||
| 13 | #define LUA_REENTRANT | ||
| 14 | 13 | ||
| 15 | #include "lapi.h" | 14 | #include "lapi.h" |
| 16 | #include "lauxlib.h" | 15 | #include "lauxlib.h" |
| @@ -35,11 +34,11 @@ void luaB_opentests (lua_State *L); | |||
| 35 | 34 | ||
| 36 | 35 | ||
| 37 | 36 | ||
| 38 | static void setnameval (lua_State *L, lua_Object t, const char *name, int val) { | 37 | static void setnameval (lua_Object t, const char *name, int val) { |
| 39 | lua_pushobject(L, t); | 38 | lua_pushobject(t); |
| 40 | lua_pushstring(L, name); | 39 | lua_pushstring(name); |
| 41 | lua_pushnumber(L, val); | 40 | lua_pushnumber(val); |
| 42 | lua_settable(L); | 41 | lua_settable(); |
| 43 | } | 42 | } |
| 44 | 43 | ||
| 45 | 44 | ||
| @@ -62,7 +61,7 @@ static const char *const instrname[OP_SETLINE+1] = { | |||
| 62 | }; | 61 | }; |
| 63 | 62 | ||
| 64 | 63 | ||
| 65 | static int pushop (lua_State *L, Instruction i) { | 64 | static int pushop (Instruction i) { |
| 66 | char buff[100]; | 65 | char buff[100]; |
| 67 | OpCode o = GET_OPCODE(i); | 66 | OpCode o = GET_OPCODE(i); |
| 68 | const char *name = instrname[o]; | 67 | const char *name = instrname[o]; |
| @@ -80,98 +79,99 @@ static int pushop (lua_State *L, Instruction i) { | |||
| 80 | sprintf(buff, "%-12s%4d %4d", name, GETARG_A(i), GETARG_B(i)); | 79 | sprintf(buff, "%-12s%4d %4d", name, GETARG_A(i), GETARG_B(i)); |
| 81 | break; | 80 | break; |
| 82 | } | 81 | } |
| 83 | lua_pushstring(L, buff); | 82 | lua_pushstring(buff); |
| 84 | return (o != OP_END); | 83 | return (o != OP_END); |
| 85 | } | 84 | } |
| 86 | 85 | ||
| 87 | 86 | ||
| 88 | static void listcode (lua_State *L) { | 87 | static void listcode (void) { |
| 89 | lua_Object o = luaL_nonnullarg(L, 1); | 88 | lua_Object o = luaL_nonnullarg(1); |
| 90 | lua_Object t = lua_createtable(L); | 89 | lua_Object t = lua_createtable(); |
| 91 | Instruction *pc; | 90 | Instruction *pc; |
| 92 | Proto *p; | 91 | Proto *p; |
| 93 | int res; | 92 | int res; |
| 94 | luaL_arg_check(L, ttype(o) == TAG_LCLOSURE, 1, "Lua function expected"); | 93 | luaL_arg_check(ttype(o) == TAG_LCLOSURE, 1, "Lua function expected"); |
| 95 | p = clvalue(o)->f.l; | 94 | p = clvalue(o)->f.l; |
| 96 | setnameval(L, t, "maxstack", p->maxstacksize); | 95 | setnameval(t, "maxstack", p->maxstacksize); |
| 97 | setnameval(L, t, "numparams", p->numparams); | 96 | setnameval(t, "numparams", p->numparams); |
| 98 | pc = p->code; | 97 | pc = p->code; |
| 99 | do { | 98 | do { |
| 100 | lua_pushobject(L, t); | 99 | lua_pushobject(t); |
| 101 | lua_pushnumber(L, pc - p->code + 1); | 100 | lua_pushnumber(pc - p->code + 1); |
| 102 | res = pushop(L, *pc++); | 101 | res = pushop(*pc++); |
| 103 | lua_settable(L); | 102 | lua_settable(); |
| 104 | } while (res); | 103 | } while (res); |
| 105 | lua_pushobject(L, t); | 104 | lua_pushobject(t); |
| 106 | } | 105 | } |
| 107 | 106 | ||
| 108 | /* }====================================================== */ | 107 | /* }====================================================== */ |
| 109 | 108 | ||
| 110 | 109 | ||
| 111 | 110 | ||
| 112 | static void get_limits (lua_State *L) { | 111 | static void get_limits (void) { |
| 113 | lua_Object t = lua_createtable(L); | 112 | lua_Object t = lua_createtable(); |
| 114 | setnameval(L, t, "SIZE_OP", SIZE_OP); | 113 | setnameval(t, "SIZE_OP", SIZE_OP); |
| 115 | setnameval(L, t, "SIZE_U", SIZE_U); | 114 | setnameval(t, "SIZE_U", SIZE_U); |
| 116 | setnameval(L, t, "SIZE_A", SIZE_A); | 115 | setnameval(t, "SIZE_A", SIZE_A); |
| 117 | setnameval(L, t, "SIZE_B", SIZE_B); | 116 | setnameval(t, "SIZE_B", SIZE_B); |
| 118 | setnameval(L, t, "MAXARG_U", MAXARG_U); | 117 | setnameval(t, "MAXARG_U", MAXARG_U); |
| 119 | setnameval(L, t, "MAXARG_S", MAXARG_S); | 118 | setnameval(t, "MAXARG_S", MAXARG_S); |
| 120 | setnameval(L, t, "MAXARG_A", MAXARG_A); | 119 | setnameval(t, "MAXARG_A", MAXARG_A); |
| 121 | setnameval(L, t, "MAXARG_B", MAXARG_B); | 120 | setnameval(t, "MAXARG_B", MAXARG_B); |
| 122 | setnameval(L, t, "MAXSTACK", MAXSTACK); | 121 | setnameval(t, "MAXSTACK", MAXSTACK); |
| 123 | setnameval(L, t, "MAXLOCALS", MAXLOCALS); | 122 | setnameval(t, "MAXLOCALS", MAXLOCALS); |
| 124 | setnameval(L, t, "MAXUPVALUES", MAXUPVALUES); | 123 | setnameval(t, "MAXUPVALUES", MAXUPVALUES); |
| 125 | setnameval(L, t, "MAXVARSLH", MAXVARSLH); | 124 | setnameval(t, "MAXVARSLH", MAXVARSLH); |
| 126 | setnameval(L, t, "MAXPARAMS", MAXPARAMS); | 125 | setnameval(t, "MAXPARAMS", MAXPARAMS); |
| 127 | setnameval(L, t, "LFPF", LFIELDS_PER_FLUSH); | 126 | setnameval(t, "LFPF", LFIELDS_PER_FLUSH); |
| 128 | setnameval(L, t, "RFPF", RFIELDS_PER_FLUSH); | 127 | setnameval(t, "RFPF", RFIELDS_PER_FLUSH); |
| 129 | lua_pushobject(L, t); | 128 | lua_pushobject(t); |
| 130 | } | 129 | } |
| 131 | 130 | ||
| 132 | 131 | ||
| 133 | static void mem_query (lua_State *L) { | 132 | static void mem_query (void) { |
| 134 | lua_pushnumber(L, memdebug_total); | 133 | lua_pushnumber(memdebug_total); |
| 135 | lua_pushnumber(L, memdebug_numblocks); | 134 | lua_pushnumber(memdebug_numblocks); |
| 136 | lua_pushnumber(L, memdebug_maxmem); | 135 | lua_pushnumber(memdebug_maxmem); |
| 137 | } | 136 | } |
| 138 | 137 | ||
| 139 | 138 | ||
| 140 | static void hash_query (lua_State *L) { | 139 | static void hash_query (void) { |
| 141 | lua_Object o = luaL_nonnullarg(L, 1); | 140 | lua_Object o = luaL_nonnullarg(1); |
| 142 | if (lua_getparam(L, 2) == LUA_NOOBJECT) { | 141 | if (lua_getparam(2) == LUA_NOOBJECT) { |
| 143 | luaL_arg_check(L, ttype(o) == TAG_STRING, 1, "string expected"); | 142 | luaL_arg_check(ttype(o) == TAG_STRING, 1, "string expected"); |
| 144 | lua_pushnumber(L, tsvalue(o)->u.s.hash); | 143 | lua_pushnumber(tsvalue(o)->u.s.hash); |
| 145 | } | 144 | } |
| 146 | else { | 145 | else { |
| 147 | const Hash *t = avalue(luaL_tablearg(L, 2)); | 146 | const Hash *t = avalue(luaL_tablearg(2)); |
| 148 | lua_pushnumber(L, luaH_mainposition(t, o) - t->node); | 147 | lua_pushnumber(luaH_mainposition(t, o) - t->node); |
| 149 | } | 148 | } |
| 150 | } | 149 | } |
| 151 | 150 | ||
| 152 | 151 | ||
| 153 | static void table_query (lua_State *L) { | 152 | static void table_query (void) { |
| 154 | const Hash *t = avalue(luaL_tablearg(L, 1)); | 153 | const Hash *t = avalue(luaL_tablearg(1)); |
| 155 | int i = luaL_opt_int(L, 2, -1); | 154 | int i = luaL_opt_int(2, -1); |
| 156 | if (i == -1) { | 155 | if (i == -1) { |
| 157 | lua_pushnumber(L, t->size); | 156 | lua_pushnumber(t->size); |
| 158 | lua_pushnumber(L, t->firstfree - t->node); | 157 | lua_pushnumber(t->firstfree - t->node); |
| 159 | } | 158 | } |
| 160 | else if (i < t->size) { | 159 | else if (i < t->size) { |
| 161 | luaA_pushobject(L, &t->node[i].key); | 160 | luaA_pushobject(lua_state, &t->node[i].key); |
| 162 | luaA_pushobject(L, &t->node[i].val); | 161 | luaA_pushobject(lua_state, &t->node[i].val); |
| 163 | if (t->node[i].next) | 162 | if (t->node[i].next) |
| 164 | lua_pushnumber(L, t->node[i].next - t->node); | 163 | lua_pushnumber(t->node[i].next - t->node); |
| 165 | } | 164 | } |
| 166 | } | 165 | } |
| 167 | 166 | ||
| 168 | 167 | ||
| 169 | static void string_query (lua_State *L) { | 168 | static void string_query (void) { |
| 170 | stringtable *tb = (*luaL_check_string(L, 1) == 's') ? &L->strt : &L->udt; | 169 | lua_State *L = lua_state; |
| 171 | int s = luaL_opt_int(L, 2, 0) - 1; | 170 | stringtable *tb = (*luaL_check_string(1) == 's') ? &L->strt : &L->udt; |
| 171 | int s = luaL_opt_int(2, 0) - 1; | ||
| 172 | if (s==-1) { | 172 | if (s==-1) { |
| 173 | lua_pushnumber(L, tb->nuse); | 173 | lua_pushnumber(tb->nuse); |
| 174 | lua_pushnumber(L, tb->size); | 174 | lua_pushnumber(tb->size); |
| 175 | } | 175 | } |
| 176 | else if (s < tb->size) { | 176 | else if (s < tb->size) { |
| 177 | TString *ts; | 177 | TString *ts; |
| @@ -203,9 +203,9 @@ static int getnum (const char **pc) { | |||
| 203 | return res; | 203 | return res; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | static int getreg (lua_State *L, const char **pc) { | 206 | static int getreg (const char **pc) { |
| 207 | skip(pc); | 207 | skip(pc); |
| 208 | if (*(*pc)++ != 'r') lua_error(L, "`testC' expecting a register"); | 208 | if (*(*pc)++ != 'r') lua_error("`testC' expecting a register"); |
| 209 | return getnum(pc); | 209 | return getnum(pc); |
| 210 | } | 210 | } |
| 211 | 211 | ||
| @@ -223,149 +223,149 @@ static const char *getname (const char **pc) { | |||
| 223 | #define EQ(s1) (strcmp(s1, inst) == 0) | 223 | #define EQ(s1) (strcmp(s1, inst) == 0) |
| 224 | 224 | ||
| 225 | 225 | ||
| 226 | static void testC (lua_State *L) { | 226 | static void testC (void) { |
| 227 | lua_Object reg[10]; | 227 | lua_Object reg[10]; |
| 228 | const char *pc = luaL_check_string(L, 1); | 228 | const char *pc = luaL_check_string(1); |
| 229 | for (;;) { | 229 | for (;;) { |
| 230 | const char *inst = getname(&pc); | 230 | const char *inst = getname(&pc); |
| 231 | if EQ("") return; | 231 | if EQ("") return; |
| 232 | else if EQ("pushnum") { | 232 | else if EQ("pushnum") { |
| 233 | lua_pushnumber(L, getnum(&pc)); | 233 | lua_pushnumber(getnum(&pc)); |
| 234 | } | 234 | } |
| 235 | else if EQ("createtable") { | 235 | else if EQ("createtable") { |
| 236 | reg[getreg(L, &pc)] = lua_createtable(L); | 236 | reg[getreg(&pc)] = lua_createtable(); |
| 237 | } | 237 | } |
| 238 | else if EQ("closure") { | 238 | else if EQ("closure") { |
| 239 | lua_CFunction f = lua_getcfunction(L, lua_getglobal(L, getname(&pc))); | 239 | lua_CFunction f = lua_getcfunction(lua_getglobal(getname(&pc))); |
| 240 | lua_pushcclosure(L, f, getnum(&pc)); | 240 | lua_pushcclosure(f, getnum(&pc)); |
| 241 | } | 241 | } |
| 242 | else if EQ("pop") { | 242 | else if EQ("pop") { |
| 243 | reg[getreg(L, &pc)] = lua_pop(L); | 243 | reg[getreg(&pc)] = lua_pop(); |
| 244 | } | 244 | } |
| 245 | else if EQ("getglobal") { | 245 | else if EQ("getglobal") { |
| 246 | int n = getreg(L, &pc); | 246 | int n = getreg(&pc); |
| 247 | reg[n] = lua_getglobal(L, getname(&pc)); | 247 | reg[n] = lua_getglobal(getname(&pc)); |
| 248 | } | 248 | } |
| 249 | else if EQ("ref") { | 249 | else if EQ("ref") { |
| 250 | lua_pushnumber(L, lua_ref(L, 0)); | 250 | lua_pushnumber(lua_ref(0)); |
| 251 | reg[getreg(L, &pc)] = lua_pop(L); | 251 | reg[getreg(&pc)] = lua_pop(); |
| 252 | } | 252 | } |
| 253 | else if EQ("reflock") { | 253 | else if EQ("reflock") { |
| 254 | lua_pushnumber(L, lua_ref(L, 1)); | 254 | lua_pushnumber(lua_ref(1)); |
| 255 | reg[getreg(L, &pc)] = lua_pop(L); | 255 | reg[getreg(&pc)] = lua_pop(); |
| 256 | } | 256 | } |
| 257 | else if EQ("getref") { | 257 | else if EQ("getref") { |
| 258 | int n = getreg(L, &pc); | 258 | int n = getreg(&pc); |
| 259 | reg[n] = lua_getref(L, (int)lua_getnumber(L, reg[getreg(L, &pc)])); | 259 | reg[n] = lua_getref((int)lua_getnumber(reg[getreg(&pc)])); |
| 260 | } | 260 | } |
| 261 | else if EQ("unref") { | 261 | else if EQ("unref") { |
| 262 | lua_unref(L, (int)lua_getnumber(L, reg[getreg(L, &pc)])); | 262 | lua_unref((int)lua_getnumber(reg[getreg(&pc)])); |
| 263 | } | 263 | } |
| 264 | else if EQ("getparam") { | 264 | else if EQ("getparam") { |
| 265 | int n = getreg(L, &pc); | 265 | int n = getreg(&pc); |
| 266 | reg[n] = lua_getparam(L, getnum(&pc)+1); /* skips the command itself */ | 266 | reg[n] = lua_getparam(getnum(&pc)+1); /* skips the command itself */ |
| 267 | } | 267 | } |
| 268 | else if EQ("getresult") { | 268 | else if EQ("getresult") { |
| 269 | int n = getreg(L, &pc); | 269 | int n = getreg(&pc); |
| 270 | reg[n] = lua_getparam(L, getnum(&pc)); | 270 | reg[n] = lua_getparam(getnum(&pc)); |
| 271 | } | 271 | } |
| 272 | else if EQ("setglobal") { | 272 | else if EQ("setglobal") { |
| 273 | lua_setglobal(L, getname(&pc)); | 273 | lua_setglobal(getname(&pc)); |
| 274 | } | 274 | } |
| 275 | else if EQ("pushglobals") { | 275 | else if EQ("pushglobals") { |
| 276 | lua_pushglobaltable(L); | 276 | lua_pushglobaltable(); |
| 277 | } | 277 | } |
| 278 | else if EQ("pushstring") { | 278 | else if EQ("pushstring") { |
| 279 | lua_pushstring(L, getname(&pc)); | 279 | lua_pushstring(getname(&pc)); |
| 280 | } | 280 | } |
| 281 | else if EQ("pushreg") { | 281 | else if EQ("pushreg") { |
| 282 | lua_pushobject(L, reg[getreg(L, &pc)]); | 282 | lua_pushobject(reg[getreg(&pc)]); |
| 283 | } | 283 | } |
| 284 | else if EQ("call") { | 284 | else if EQ("call") { |
| 285 | if (lua_call(L, getname(&pc))) lua_error(L, NULL); | 285 | if (lua_call(getname(&pc))) lua_error(NULL); |
| 286 | } | 286 | } |
| 287 | else if EQ("gettable") { | 287 | else if EQ("gettable") { |
| 288 | reg[getreg(L, &pc)] = lua_gettable(L); | 288 | reg[getreg(&pc)] = lua_gettable(); |
| 289 | } | 289 | } |
| 290 | else if EQ("rawget") { | 290 | else if EQ("rawget") { |
| 291 | reg[getreg(L, &pc)] = lua_rawget(L); | 291 | reg[getreg(&pc)] = lua_rawget(); |
| 292 | } | 292 | } |
| 293 | else if EQ("settable") { | 293 | else if EQ("settable") { |
| 294 | lua_settable(L); | 294 | lua_settable(); |
| 295 | } | 295 | } |
| 296 | else if EQ("rawset") { | 296 | else if EQ("rawset") { |
| 297 | lua_rawset(L); | 297 | lua_rawset(); |
| 298 | } | 298 | } |
| 299 | else if EQ("tag") { | 299 | else if EQ("tag") { |
| 300 | lua_pushnumber(L, lua_tag(L, reg[getreg(L, &pc)])); | 300 | lua_pushnumber(lua_tag(reg[getreg(&pc)])); |
| 301 | } | 301 | } |
| 302 | else if EQ("type") { | 302 | else if EQ("type") { |
| 303 | lua_pushstring(L, lua_type(L, reg[getreg(L, &pc)])); | 303 | lua_pushstring(lua_type(reg[getreg(&pc)])); |
| 304 | } | 304 | } |
| 305 | else if EQ("next") { | 305 | else if EQ("next") { |
| 306 | int n = getreg(L, &pc); | 306 | int n = getreg(&pc); |
| 307 | n = lua_next(L, reg[n], (int)lua_getnumber(L, reg[getreg(L, &pc)])); | 307 | n = lua_next(reg[n], (int)lua_getnumber(reg[getreg(&pc)])); |
| 308 | lua_pushnumber(L, n); | 308 | lua_pushnumber(n); |
| 309 | } | 309 | } |
| 310 | else if EQ("equal") { | 310 | else if EQ("equal") { |
| 311 | int n1 = getreg(L, &pc); | 311 | int n1 = getreg(&pc); |
| 312 | int n2 = getreg(L, &pc); | 312 | int n2 = getreg(&pc); |
| 313 | lua_pushnumber(L, lua_equal(L, reg[n1], reg[n2])); | 313 | lua_pushnumber(lua_equal(reg[n1], reg[n2])); |
| 314 | } | 314 | } |
| 315 | else if EQ("pushusertag") { | 315 | else if EQ("pushusertag") { |
| 316 | int val = getreg(L, &pc); | 316 | int val = getreg(&pc); |
| 317 | int tag = getreg(L, &pc); | 317 | int tag = getreg(&pc); |
| 318 | lua_pushusertag(L, (void *)(int)lua_getnumber(L, reg[val]), | 318 | lua_pushusertag((void *)(int)lua_getnumber(reg[val]), |
| 319 | (int)lua_getnumber(L, reg[tag])); | 319 | (int)lua_getnumber(reg[tag])); |
| 320 | } | 320 | } |
| 321 | else if EQ("udataval") { | 321 | else if EQ("udataval") { |
| 322 | int n = getreg(L, &pc); | 322 | int n = getreg(&pc); |
| 323 | lua_pushnumber(L, (int)lua_getuserdata(L, reg[getreg(L, &pc)])); | 323 | lua_pushnumber((int)lua_getuserdata(reg[getreg(&pc)])); |
| 324 | reg[n] = lua_pop(L); | 324 | reg[n] = lua_pop(); |
| 325 | } | 325 | } |
| 326 | else if EQ("settagmethod") { | 326 | else if EQ("settagmethod") { |
| 327 | int n = getreg(L, &pc); | 327 | int n = getreg(&pc); |
| 328 | lua_settagmethod(L, (int)lua_getnumber(L, reg[n]), getname(&pc)); | 328 | lua_settagmethod((int)lua_getnumber(reg[n]), getname(&pc)); |
| 329 | } | 329 | } |
| 330 | else if EQ("beginblock") { | 330 | else if EQ("beginblock") { |
| 331 | lua_beginblock(L); | 331 | lua_beginblock(); |
| 332 | } | 332 | } |
| 333 | else if EQ("endblock") { | 333 | else if EQ("endblock") { |
| 334 | lua_endblock(L); | 334 | lua_endblock(); |
| 335 | } | 335 | } |
| 336 | else if EQ("newstate") { | 336 | else if EQ("newstate") { |
| 337 | int stacksize = getnum(&pc); | 337 | int stacksize = getnum(&pc); |
| 338 | lua_State *L1 = lua_newstate("stack", stacksize, | 338 | lua_State *L1 = lua_newstate("stack", stacksize, |
| 339 | "builtin", getnum(&pc), NULL); | 339 | "builtin", getnum(&pc), NULL); |
| 340 | lua_pushuserdata(L, L1); | 340 | lua_pushuserdata(L1); |
| 341 | } | 341 | } |
| 342 | else if EQ("closestate") { | 342 | else if EQ("closestate") { |
| 343 | lua_close((lua_State *)lua_getuserdata(L, reg[getreg(L, &pc)])); | 343 | (lua_close)((lua_State *)lua_getuserdata(reg[getreg(&pc)])); |
| 344 | } | 344 | } |
| 345 | else if EQ("doremote") { | 345 | else if EQ("doremote") { |
| 346 | lua_Object ol1 = reg[getreg(L, &pc)]; | 346 | lua_Object ol1 = reg[getreg(&pc)]; |
| 347 | lua_Object str = reg[getreg(L, &pc)]; | 347 | lua_Object str = reg[getreg(&pc)]; |
| 348 | lua_State *L1; | 348 | lua_State *L1; |
| 349 | lua_Object temp; | 349 | lua_Object temp; |
| 350 | int i; | 350 | int i; |
| 351 | if (!lua_isuserdata(L, ol1) || !lua_isstring(L, str)) | 351 | if (!lua_isuserdata(ol1) || !lua_isstring(str)) |
| 352 | lua_error(L, "bad arguments for `doremote'"); | 352 | lua_error("bad arguments for `doremote'"); |
| 353 | L1 = (lua_State *)lua_getuserdata(L, ol1); | 353 | L1 = (lua_State *)lua_getuserdata(ol1); |
| 354 | lua_dostring(L1, lua_getstring(L, str)); | 354 | (lua_dostring)(L1, lua_getstring(str)); |
| 355 | i = 1; | 355 | i = 1; |
| 356 | while ((temp = lua_getresult(L1, i++)) != LUA_NOOBJECT) | 356 | while ((temp = (lua_getresult)(L1, i++)) != LUA_NOOBJECT) |
| 357 | lua_pushstring(L, lua_getstring(L1, temp)); | 357 | lua_pushstring((lua_getstring)(L1, temp)); |
| 358 | } | 358 | } |
| 359 | #if LUA_DEPRECATETFUNCS | 359 | #if LUA_DEPRECATETFUNCS |
| 360 | else if EQ("rawsetglobal") { | 360 | else if EQ("rawsetglobal") { |
| 361 | lua_rawsetglobal(L, getname(&pc)); | 361 | lua_rawsetglobal(getname(&pc)); |
| 362 | } | 362 | } |
| 363 | else if EQ("rawgetglobal") { | 363 | else if EQ("rawgetglobal") { |
| 364 | int n = getreg(L, &pc); | 364 | int n = getreg(&pc); |
| 365 | reg[n] = lua_rawgetglobal(L, getname(&pc)); | 365 | reg[n] = lua_rawgetglobal(getname(&pc)); |
| 366 | } | 366 | } |
| 367 | #endif | 367 | #endif |
| 368 | else luaL_verror(L, "unknown command in `testC': %.20s", inst); | 368 | else luaL_verror(lua_state, "unknown command in `testC': %.20s", inst); |
| 369 | } | 369 | } |
| 370 | } | 370 | } |
| 371 | 371 | ||
| @@ -374,18 +374,20 @@ static void testC (lua_State *L) { | |||
| 374 | 374 | ||
| 375 | 375 | ||
| 376 | static const struct luaL_reg tests_funcs[] = { | 376 | static const struct luaL_reg tests_funcs[] = { |
| 377 | {"hash", hash_query}, | 377 | {"hash", (lua_CFunction)hash_query}, |
| 378 | {"limits", get_limits}, | 378 | {"limits", (lua_CFunction)get_limits}, |
| 379 | {"listcode", listcode}, | 379 | {"listcode", (lua_CFunction)listcode}, |
| 380 | {"querystr", string_query}, | 380 | {"querystr", (lua_CFunction)string_query}, |
| 381 | {"querytab", table_query}, | 381 | {"querytab", (lua_CFunction)table_query}, |
| 382 | {"testC", testC}, | 382 | {"testC", (lua_CFunction)testC}, |
| 383 | {"totalmem", mem_query} | 383 | {"totalmem", (lua_CFunction)mem_query} |
| 384 | }; | 384 | }; |
| 385 | 385 | ||
| 386 | 386 | ||
| 387 | void luaB_opentests (lua_State *L) { | 387 | void luaB_opentests (lua_State *L) { |
| 388 | luaL_openl(L, tests_funcs); | 388 | if (lua_state != NULL) return; /* do not open tests for auxiliar states */ |
| 389 | lua_state = L; | ||
| 390 | luaL_openl(tests_funcs); | ||
| 389 | } | 391 | } |
| 390 | 392 | ||
| 391 | #endif | 393 | #endif |
