diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 413 |
1 files changed, 213 insertions, 200 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.33 2000/08/09 19:16:57 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.34 2000/08/15 20:14:27 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_SINGLESTATE | ||
14 | 13 | ||
15 | #include "lua.h" | 14 | #include "lua.h" |
16 | 15 | ||
@@ -38,11 +37,11 @@ void luaB_opentests (lua_State *L); | |||
38 | 37 | ||
39 | 38 | ||
40 | 39 | ||
41 | static void setnameval (lua_Object t, const char *name, int val) { | 40 | static void setnameval (lua_State *L, const char *name, int val) { |
42 | lua_pushobject(t); | 41 | lua_pushobject(L, -1); |
43 | lua_pushstring(name); | 42 | lua_pushstring(L, name); |
44 | lua_pushnumber(val); | 43 | lua_pushnumber(L, val); |
45 | lua_settable(); | 44 | lua_settable(L); |
46 | } | 45 | } |
47 | 46 | ||
48 | 47 | ||
@@ -65,7 +64,7 @@ static const char *const instrname[NUM_OPCODES] = { | |||
65 | }; | 64 | }; |
66 | 65 | ||
67 | 66 | ||
68 | static int pushop (Proto *p, int pc) { | 67 | static int pushop (lua_State *L, Proto *p, int pc) { |
69 | char buff[100]; | 68 | char buff[100]; |
70 | Instruction i = p->code[pc]; | 69 | Instruction i = p->code[pc]; |
71 | OpCode o = GET_OPCODE(i); | 70 | OpCode o = GET_OPCODE(i); |
@@ -85,146 +84,161 @@ static int pushop (Proto *p, int pc) { | |||
85 | sprintf(buff+8, "%-12s%4d %4d", name, GETARG_A(i), GETARG_B(i)); | 84 | sprintf(buff+8, "%-12s%4d %4d", name, GETARG_A(i), GETARG_B(i)); |
86 | break; | 85 | break; |
87 | } | 86 | } |
88 | lua_pushstring(buff); | 87 | lua_pushstring(L, buff); |
89 | return (o != OP_END); | 88 | return (o != OP_END); |
90 | } | 89 | } |
91 | 90 | ||
92 | 91 | ||
93 | static void listcode (void) { | 92 | static int listcode (lua_State *L) { |
94 | lua_Object o = luaL_nonnullarg(1); | ||
95 | lua_Object t = lua_createtable(); | ||
96 | int pc; | 93 | int pc; |
97 | Proto *p; | 94 | Proto *p; |
98 | int res; | 95 | int res; |
99 | luaL_arg_check(ttype(o) == TAG_LCLOSURE, 1, "Lua function expected"); | 96 | luaL_arg_check(L, lua_tag(L, 1) == TAG_LCLOSURE, 1, "Lua function expected"); |
100 | p = clvalue(o)->f.l; | 97 | p = clvalue(luaA_index(L, 1))->f.l; |
101 | setnameval(t, "maxstack", p->maxstacksize); | 98 | lua_newtable(L); |
102 | setnameval(t, "numparams", p->numparams); | 99 | setnameval(L, "maxstack", p->maxstacksize); |
100 | setnameval(L, "numparams", p->numparams); | ||
103 | pc = 0; | 101 | pc = 0; |
104 | do { | 102 | do { |
105 | lua_pushobject(t); | 103 | lua_pushobject(L, -1); |
106 | lua_pushnumber(pc+1); | 104 | lua_pushnumber(L, pc+1); |
107 | res = pushop(p, pc++); | 105 | res = pushop(L, p, pc++); |
108 | lua_settable(); | 106 | lua_settable(L); |
109 | } while (res); | 107 | } while (res); |
110 | lua_pushobject(t); | 108 | return 1; |
111 | } | 109 | } |
112 | 110 | ||
113 | 111 | ||
114 | static void liststrings (void) { | 112 | static int liststrings (lua_State *L) { |
115 | lua_Object o = luaL_nonnullarg(1); | ||
116 | lua_Object t = lua_createtable(); | ||
117 | Proto *p; | 113 | Proto *p; |
118 | int i; | 114 | int i; |
119 | luaL_arg_check(ttype(o) == TAG_LCLOSURE, 1, "Lua function expected"); | 115 | luaL_arg_check(L, lua_tag(L, 1) == TAG_LCLOSURE, 1, "Lua function expected"); |
120 | p = clvalue(o)->f.l; | 116 | p = clvalue(luaA_index(L, 1))->f.l; |
117 | lua_newtable(L); | ||
121 | for (i=0; i<p->nkstr; i++) { | 118 | for (i=0; i<p->nkstr; i++) { |
122 | lua_pushobject(t); | 119 | lua_pushobject(L, -1); |
123 | lua_pushnumber(i+1); | 120 | lua_pushnumber(L, i+1); |
124 | lua_pushstring(p->kstr[i]->str); | 121 | lua_pushstring(L, p->kstr[i]->str); |
125 | lua_settable(); | 122 | lua_settable(L); |
126 | } | 123 | } |
127 | lua_pushobject(t); | 124 | return 1; |
128 | } | 125 | } |
129 | 126 | ||
130 | 127 | ||
131 | static void listlocals (void) { | 128 | static int listlocals (lua_State *L) { |
132 | lua_Object o = luaL_nonnullarg(1); | ||
133 | Proto *p; | 129 | Proto *p; |
134 | int pc = luaL_check_int(2) - 1; | 130 | int pc = luaL_check_int(L, 2) - 1; |
135 | int i = 1; | 131 | int i = 0; |
136 | const char *name; | 132 | const char *name; |
137 | luaL_arg_check(ttype(o) == TAG_LCLOSURE, 1, "Lua function expected"); | 133 | luaL_arg_check(L, lua_tag(L, 1) == TAG_LCLOSURE, 1, "Lua function expected"); |
138 | p = clvalue(o)->f.l; | 134 | p = clvalue(luaA_index(L, 1))->f.l; |
139 | while ((name = luaF_getlocalname(p, i++, pc)) != NULL) | 135 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) |
140 | lua_pushstring(name); | 136 | lua_pushstring(L, name); |
137 | return i-1; | ||
141 | } | 138 | } |
142 | 139 | ||
143 | /* }====================================================== */ | 140 | /* }====================================================== */ |
144 | 141 | ||
145 | 142 | ||
146 | 143 | ||
147 | static void get_limits (void) { | 144 | static int get_limits (lua_State *L) { |
148 | lua_Object t = lua_createtable(); | 145 | lua_newtable(L); |
149 | setnameval(t, "BITS_INT", BITS_INT); | 146 | setnameval(L, "BITS_INT", BITS_INT); |
150 | setnameval(t, "LFPF", LFIELDS_PER_FLUSH); | 147 | setnameval(L, "LFPF", LFIELDS_PER_FLUSH); |
151 | setnameval(t, "MAXARG_A", MAXARG_A); | 148 | setnameval(L, "MAXARG_A", MAXARG_A); |
152 | setnameval(t, "MAXARG_B", MAXARG_B); | 149 | setnameval(L, "MAXARG_B", MAXARG_B); |
153 | setnameval(t, "MAXARG_S", MAXARG_S); | 150 | setnameval(L, "MAXARG_S", MAXARG_S); |
154 | setnameval(t, "MAXARG_U", MAXARG_U); | 151 | setnameval(L, "MAXARG_U", MAXARG_U); |
155 | setnameval(t, "MAXLOCALS", MAXLOCALS); | 152 | setnameval(L, "MAXLOCALS", MAXLOCALS); |
156 | setnameval(t, "MAXPARAMS", MAXPARAMS); | 153 | setnameval(L, "MAXPARAMS", MAXPARAMS); |
157 | setnameval(t, "MAXSTACK", MAXSTACK); | 154 | setnameval(L, "MAXSTACK", MAXSTACK); |
158 | setnameval(t, "MAXUPVALUES", MAXUPVALUES); | 155 | setnameval(L, "MAXUPVALUES", MAXUPVALUES); |
159 | setnameval(t, "MAXVARSLH", MAXVARSLH); | 156 | setnameval(L, "MAXVARSLH", MAXVARSLH); |
160 | setnameval(t, "RFPF", RFIELDS_PER_FLUSH); | 157 | setnameval(L, "RFPF", RFIELDS_PER_FLUSH); |
161 | setnameval(t, "SIZE_A", SIZE_A); | 158 | setnameval(L, "SIZE_A", SIZE_A); |
162 | setnameval(t, "SIZE_B", SIZE_B); | 159 | setnameval(L, "SIZE_B", SIZE_B); |
163 | setnameval(t, "SIZE_OP", SIZE_OP); | 160 | setnameval(L, "SIZE_OP", SIZE_OP); |
164 | setnameval(t, "SIZE_U", SIZE_U); | 161 | setnameval(L, "SIZE_U", SIZE_U); |
165 | lua_pushobject(t); | 162 | return 1; |
166 | } | 163 | } |
167 | 164 | ||
168 | 165 | ||
169 | static void mem_query (void) { | 166 | static int mem_query (lua_State *L) { |
170 | lua_Object arg = lua_getparam(1); | 167 | if (lua_isnull(L, 1)) { |
171 | if (arg == LUA_NOOBJECT) { | 168 | lua_pushnumber(L, memdebug_total); |
172 | lua_pushnumber(memdebug_total); | 169 | lua_pushnumber(L, memdebug_numblocks); |
173 | lua_pushnumber(memdebug_numblocks); | 170 | lua_pushnumber(L, memdebug_maxmem); |
174 | lua_pushnumber(memdebug_maxmem); | 171 | return 3; |
172 | } | ||
173 | else { | ||
174 | memdebug_memlimit = luaL_check_int(L, 1); | ||
175 | return 0; | ||
175 | } | 176 | } |
176 | else | ||
177 | memdebug_memlimit = luaL_check_int(1); | ||
178 | } | 177 | } |
179 | 178 | ||
180 | 179 | ||
181 | static void hash_query (void) { | 180 | static int hash_query (lua_State *L) { |
182 | lua_Object o = luaL_nonnullarg(1); | 181 | if (lua_isnull(L, 2)) { |
183 | if (lua_getparam(2) == LUA_NOOBJECT) { | 182 | luaL_arg_check(L, lua_tag(L, 1) == TAG_STRING, 1, "string expected"); |
184 | luaL_arg_check(ttype(o) == TAG_STRING, 1, "string expected"); | 183 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->u.s.hash); |
185 | lua_pushnumber(tsvalue(o)->u.s.hash); | ||
186 | } | 184 | } |
187 | else { | 185 | else { |
188 | const Hash *t = hvalue(luaL_tablearg(2)); | 186 | Hash *t; |
189 | lua_pushnumber(luaH_mainposition(t, o) - t->node); | 187 | luaL_checktype(L, 2, "table"); |
188 | t = hvalue(luaA_index(L, 2)); | ||
189 | lua_pushnumber(L, luaH_mainposition(t, luaA_index(L, 1)) - t->node); | ||
190 | } | 190 | } |
191 | return 1; | ||
191 | } | 192 | } |
192 | 193 | ||
193 | 194 | ||
194 | static void table_query (void) { | 195 | static int table_query (lua_State *L) { |
195 | const Hash *t = hvalue(luaL_tablearg(1)); | 196 | const Hash *t; |
196 | int i = luaL_opt_int(2, -1); | 197 | int i = luaL_opt_int(L, 2, -1); |
198 | luaL_checktype(L, 1, "table"); | ||
199 | t = hvalue(luaA_index(L, 1)); | ||
197 | if (i == -1) { | 200 | if (i == -1) { |
198 | lua_pushnumber(t->size); | 201 | lua_pushnumber(L, t->size); |
199 | lua_pushnumber(t->firstfree - t->node); | 202 | lua_pushnumber(L, t->firstfree - t->node); |
203 | return 2; | ||
200 | } | 204 | } |
201 | else if (i < t->size) { | 205 | else if (i < t->size) { |
202 | luaA_pushobject(lua_state, &t->node[i].key); | 206 | luaA_pushobject(L, &t->node[i].key); |
203 | luaA_pushobject(lua_state, &t->node[i].val); | 207 | luaA_pushobject(L, &t->node[i].val); |
204 | if (t->node[i].next) | 208 | if (t->node[i].next) { |
205 | lua_pushnumber(t->node[i].next - t->node); | 209 | lua_pushnumber(L, t->node[i].next - t->node); |
210 | return 3; | ||
211 | } | ||
212 | else | ||
213 | return 2; | ||
206 | } | 214 | } |
215 | return 0; | ||
207 | } | 216 | } |
208 | 217 | ||
209 | 218 | ||
210 | static void string_query (void) { | 219 | static int string_query (lua_State *L) { |
211 | lua_State *L = lua_state; | 220 | stringtable *tb = (*luaL_check_string(L, 1) == 's') ? &L->strt : &L->udt; |
212 | stringtable *tb = (*luaL_check_string(1) == 's') ? &L->strt : &L->udt; | 221 | int s = luaL_opt_int(L, 2, 0) - 1; |
213 | int s = luaL_opt_int(2, 0) - 1; | ||
214 | if (s==-1) { | 222 | if (s==-1) { |
215 | lua_pushnumber(tb->nuse); | 223 | lua_pushnumber(L ,tb->nuse); |
216 | lua_pushnumber(tb->size); | 224 | lua_pushnumber(L ,tb->size); |
225 | return 2; | ||
217 | } | 226 | } |
218 | else if (s < tb->size) { | 227 | else if (s < tb->size) { |
219 | TString *ts; | 228 | TString *ts; |
229 | int n = 0; | ||
220 | for (ts = tb->hash[s]; ts; ts = ts->nexthash) { | 230 | for (ts = tb->hash[s]; ts; ts = ts->nexthash) { |
221 | ttype(L->top) = TAG_STRING; | 231 | ttype(L->top) = TAG_STRING; |
222 | tsvalue(L->top) = ts; | 232 | tsvalue(L->top) = ts; |
223 | incr_top; | 233 | incr_top; |
234 | n++; | ||
224 | } | 235 | } |
236 | return n; | ||
225 | } | 237 | } |
238 | return 0; | ||
226 | } | 239 | } |
227 | 240 | ||
241 | |||
228 | /* | 242 | /* |
229 | ** {====================================================== | 243 | ** {====================================================== |
230 | ** function to test the API with C. It interprets a kind of "assembler" | 244 | ** function to test the API with C. It interprets a kind of "assembler" |
@@ -238,21 +252,33 @@ static void skip (const char **pc) { | |||
238 | while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++; | 252 | while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++; |
239 | } | 253 | } |
240 | 254 | ||
241 | static int getnum (const char **pc) { | 255 | static int getnum (const char **pc, int *reg) { |
242 | int res = 0; | 256 | int res = 0; |
257 | int sig = 1; | ||
258 | int ref = 0; | ||
243 | skip(pc); | 259 | skip(pc); |
260 | if (**pc == 'r') { | ||
261 | ref = 1; | ||
262 | (*pc)++; | ||
263 | } | ||
264 | else if (**pc == '-') { | ||
265 | sig = -1; | ||
266 | (*pc)++; | ||
267 | } | ||
244 | while (isdigit(**pc)) res = res*10 + (*(*pc)++) - '0'; | 268 | while (isdigit(**pc)) res = res*10 + (*(*pc)++) - '0'; |
245 | return res; | 269 | if (!ref) |
270 | return sig*res; | ||
271 | else | ||
272 | return reg[res]; | ||
246 | } | 273 | } |
247 | 274 | ||
248 | static int getreg (const char **pc) { | 275 | static int getreg (const char **pc) { |
249 | skip(pc); | 276 | skip(pc); |
250 | if (*(*pc)++ != 'r') lua_error("`testC' expecting a register"); | 277 | (*pc)++; /* skip the `r' */ |
251 | return getnum(pc); | 278 | return getnum(pc, NULL); |
252 | } | 279 | } |
253 | 280 | ||
254 | static const char *getname (const char **pc) { | 281 | static const char *getname (char *buff, const char **pc) { |
255 | static char buff[30]; | ||
256 | int i = 0; | 282 | int i = 0; |
257 | skip(pc); | 283 | skip(pc); |
258 | while (**pc != '\0' && !strchr(delimits, **pc)) | 284 | while (**pc != '\0' && !strchr(delimits, **pc)) |
@@ -264,159 +290,148 @@ static const char *getname (const char **pc) { | |||
264 | 290 | ||
265 | #define EQ(s1) (strcmp(s1, inst) == 0) | 291 | #define EQ(s1) (strcmp(s1, inst) == 0) |
266 | 292 | ||
293 | #define getnum ((getnum)(&pc, reg)) | ||
294 | #define getreg ((getreg)(&pc)) | ||
295 | #define getname ((getname)(buff, &pc)) | ||
296 | |||
267 | 297 | ||
268 | static void testC (void) { | 298 | static int testC (lua_State *L) { |
269 | lua_Object reg[10]; | 299 | char buff[30]; |
270 | const char *pc = luaL_check_string(1); | 300 | int reg[10]; |
301 | const char *pc = luaL_check_string(L, 1); | ||
271 | for (;;) { | 302 | for (;;) { |
272 | const char *inst = getname(&pc); | 303 | const char *inst = getname; |
273 | if EQ("") return; | 304 | if EQ("") return 0; |
305 | else if EQ("return") { | ||
306 | return getnum; | ||
307 | } | ||
308 | else if EQ("retall") { | ||
309 | return lua_gettop(L) - 1; | ||
310 | } | ||
311 | else if EQ("gettop") { | ||
312 | reg[getreg] = lua_gettop(L); | ||
313 | } | ||
314 | else if EQ("settop") { | ||
315 | lua_settop(L, getnum); | ||
316 | } | ||
317 | else if EQ("setreg") { | ||
318 | int n = getreg; | ||
319 | reg[n] = lua_tonumber(L, getnum); | ||
320 | } | ||
274 | else if EQ("pushnum") { | 321 | else if EQ("pushnum") { |
275 | lua_pushnumber(getnum(&pc)); | 322 | lua_pushnumber(L, getnum); |
276 | } | 323 | } |
277 | else if EQ("createtable") { | 324 | else if EQ("newtable") { |
278 | reg[getreg(&pc)] = lua_createtable(); | 325 | lua_newtable(L); |
279 | } | 326 | } |
280 | else if EQ("closure") { | 327 | else if EQ("closure") { |
281 | lua_CFunction f = lua_getcfunction(lua_getglobal(getname(&pc))); | 328 | lua_CFunction f; |
282 | lua_pushcclosure(f, getnum(&pc)); | 329 | lua_getglobal(L, getname); |
330 | f = lua_tocfunction(L, -1); | ||
331 | lua_settop(L, -1); | ||
332 | lua_pushcclosure(L, f, getnum); | ||
283 | } | 333 | } |
284 | else if EQ("pop") { | 334 | else if EQ("pushobject") { |
285 | reg[getreg(&pc)] = lua_pop(); | 335 | lua_pushobject(L, getnum); |
286 | } | 336 | } |
287 | else if EQ("getglobal") { | 337 | else if EQ("getglobal") { |
288 | int n = getreg(&pc); | 338 | lua_getglobal(L, getname); |
289 | reg[n] = lua_getglobal(getname(&pc)); | ||
290 | } | 339 | } |
291 | else if EQ("ref") { | 340 | else if EQ("ref") { |
292 | lua_pushnumber(lua_ref(0)); | 341 | reg[getreg] = lua_ref(L, 0); |
293 | reg[getreg(&pc)] = lua_pop(); | ||
294 | } | 342 | } |
295 | else if EQ("reflock") { | 343 | else if EQ("reflock") { |
296 | lua_pushnumber(lua_ref(1)); | 344 | reg[getreg] = lua_ref(L, 1); |
297 | reg[getreg(&pc)] = lua_pop(); | ||
298 | } | 345 | } |
299 | else if EQ("getref") { | 346 | else if EQ("getref") { |
300 | int n = getreg(&pc); | 347 | int n = getreg; |
301 | reg[n] = lua_getref((int)lua_getnumber(reg[getreg(&pc)])); | 348 | reg[n] = lua_getref(L, getnum); |
302 | } | 349 | } |
303 | else if EQ("unref") { | 350 | else if EQ("unref") { |
304 | lua_unref((int)lua_getnumber(reg[getreg(&pc)])); | 351 | lua_unref(L, getnum); |
305 | } | ||
306 | else if EQ("getparam") { | ||
307 | int n = getreg(&pc); | ||
308 | reg[n] = lua_getparam(getnum(&pc)+1); /* skips the command itself */ | ||
309 | } | ||
310 | else if EQ("getresult") { | ||
311 | int n = getreg(&pc); | ||
312 | reg[n] = lua_getparam(getnum(&pc)); | ||
313 | } | 352 | } |
314 | else if EQ("setglobal") { | 353 | else if EQ("setglobal") { |
315 | lua_setglobal(getname(&pc)); | 354 | lua_setglobal(L, getname); |
316 | } | ||
317 | else if EQ("pushglobals") { | ||
318 | lua_pushglobals(); | ||
319 | } | 355 | } |
320 | else if EQ("pushstring") { | 356 | else if EQ("pushstring") { |
321 | lua_pushstring(getname(&pc)); | 357 | lua_pushstring(L, getname); |
322 | } | ||
323 | else if EQ("pushreg") { | ||
324 | lua_pushobject(reg[getreg(&pc)]); | ||
325 | } | 358 | } |
326 | else if EQ("call") { | 359 | else if EQ("call") { |
327 | if (lua_call(getname(&pc))) lua_error(NULL); | 360 | int narg = getnum; |
361 | int nres = getnum; | ||
362 | if (lua_call(L, narg, nres)) lua_error(L, NULL); | ||
328 | } | 363 | } |
329 | else if EQ("gettable") { | 364 | else if EQ("gettable") { |
330 | reg[getreg(&pc)] = lua_gettable(); | 365 | lua_gettable(L); |
331 | } | 366 | } |
332 | else if EQ("rawget") { | 367 | else if EQ("rawget") { |
333 | reg[getreg(&pc)] = lua_rawget(); | 368 | lua_rawget(L); |
334 | } | 369 | } |
335 | else if EQ("settable") { | 370 | else if EQ("settable") { |
336 | lua_settable(); | 371 | lua_settable(L); |
337 | } | 372 | } |
338 | else if EQ("rawset") { | 373 | else if EQ("rawset") { |
339 | lua_rawset(); | 374 | lua_rawset(L); |
340 | } | 375 | } |
341 | else if EQ("tag") { | 376 | else if EQ("tag") { |
342 | lua_pushnumber(lua_tag(reg[getreg(&pc)])); | 377 | int n = getreg; |
378 | reg[n] = lua_tag(L, getnum); | ||
343 | } | 379 | } |
344 | else if EQ("type") { | 380 | else if EQ("type") { |
345 | lua_pushstring(lua_type(reg[getreg(&pc)])); | 381 | lua_pushstring(L, lua_type(L, getnum)); |
346 | } | ||
347 | else if EQ("next") { | ||
348 | int n = getreg(&pc); | ||
349 | n = lua_next(reg[n], (int)lua_getnumber(reg[getreg(&pc)])); | ||
350 | lua_pushnumber(n); | ||
351 | } | 382 | } |
352 | else if EQ("equal") { | 383 | else if EQ("equal") { |
353 | int n1 = getreg(&pc); | 384 | int n1 = getreg; |
354 | int n2 = getreg(&pc); | 385 | int n2 = getnum; |
355 | lua_pushnumber(lua_equal(reg[n1], reg[n2])); | 386 | int n3 = getnum; |
387 | reg[n1] = lua_equal(L, n2, n3); | ||
356 | } | 388 | } |
357 | else if EQ("pushusertag") { | 389 | else if EQ("pushusertag") { |
358 | int val = getreg(&pc); | 390 | int val = getnum; |
359 | int tag = getreg(&pc); | 391 | int tag = getnum; |
360 | lua_pushusertag((void *)(int)lua_getnumber(reg[val]), | 392 | lua_pushusertag(L, (void *)val, tag); |
361 | (int)lua_getnumber(reg[tag])); | ||
362 | } | 393 | } |
363 | else if EQ("udataval") { | 394 | else if EQ("udataval") { |
364 | int n = getreg(&pc); | 395 | int n = getreg; |
365 | lua_pushnumber((int)lua_getuserdata(reg[getreg(&pc)])); | 396 | reg[n] = (int)lua_touserdata(L, getnum); |
366 | reg[n] = lua_pop(); | ||
367 | } | 397 | } |
368 | else if EQ("settagmethod") { | 398 | else if EQ("settagmethod") { |
369 | int n = getreg(&pc); | 399 | int n = getnum; |
370 | lua_settagmethod((int)lua_getnumber(reg[n]), getname(&pc)); | 400 | lua_settagmethod(L, n, getname); |
371 | } | ||
372 | else if EQ("beginblock") { | ||
373 | lua_beginblock(); | ||
374 | } | ||
375 | else if EQ("endblock") { | ||
376 | lua_endblock(); | ||
377 | } | 401 | } |
378 | else if EQ("newstate") { | 402 | else if EQ("newstate") { |
379 | int stacksize = getnum(&pc); | 403 | int stacksize = getnum; |
380 | lua_State *L1 = lua_newstate(stacksize, getnum(&pc)); | 404 | lua_State *L1 = lua_newstate(stacksize, getnum); |
381 | if (L1) | 405 | if (L1) |
382 | lua_pushuserdata(L1); | 406 | lua_pushuserdata(L, L1); |
383 | else | 407 | else |
384 | lua_pushnil(); | 408 | lua_pushnil(L); |
385 | } | 409 | } |
386 | else if EQ("closestate") { | 410 | else if EQ("closestate") { |
387 | (lua_close)((lua_State *)lua_getuserdata(reg[getreg(&pc)])); | 411 | (lua_close)((lua_State *)lua_touserdata(L, getnum)); |
388 | } | 412 | } |
389 | else if EQ("doremote") { | 413 | else if EQ("doremote") { |
390 | lua_Object ol1 = reg[getreg(&pc)]; | 414 | int ol1 = getnum; |
391 | lua_Object str = reg[getreg(&pc)]; | 415 | int str = getnum; |
392 | lua_State *L1; | 416 | lua_State *L1; |
393 | lua_Object temp; | ||
394 | int status; | 417 | int status; |
395 | if (!lua_isuserdata(ol1) || !lua_isstring(str)) | 418 | if (!lua_isuserdata(L, ol1) || !lua_isstring(L, str)) |
396 | lua_error("bad arguments for `doremote'"); | 419 | lua_error(L, "bad arguments for `doremote'"); |
397 | L1 = (lua_State *)lua_getuserdata(ol1); | 420 | L1 = (lua_State *)lua_touserdata(L, ol1); |
398 | status = (lua_dostring)(L1, lua_getstring(str)); | 421 | status = lua_dostring(L1, lua_tostring(L, str)); |
399 | if (status != 0) { | 422 | if (status != 0) { |
400 | lua_pushnil(); | 423 | lua_pushnil(L); |
401 | lua_pushnumber(status); | 424 | lua_pushnumber(L, status); |
402 | } | 425 | } |
403 | else { | 426 | else { |
404 | int i = 1; | 427 | int i = 0; |
405 | while ((temp = (lua_getresult)(L1, i++)) != LUA_NOOBJECT) | 428 | while (!lua_isnull(L, ++i)) |
406 | lua_pushstring((lua_getstring)(L1, temp)); | 429 | lua_pushstring(L, lua_tostring(L1, i)); |
407 | } | 430 | } |
408 | } | 431 | } |
409 | #if LUA_DEPRECATETFUNCS | 432 | else luaL_verror(L, "unknown instruction %.30s", buff); |
410 | else if EQ("rawsetglobal") { | ||
411 | lua_rawsetglobal(getname(&pc)); | ||
412 | } | ||
413 | else if EQ("rawgetglobal") { | ||
414 | int n = getreg(&pc); | ||
415 | reg[n] = lua_rawgetglobal(getname(&pc)); | ||
416 | } | ||
417 | #endif | ||
418 | else luaL_verror(lua_state, "unknown command in `testC': %.20s", inst); | ||
419 | } | 433 | } |
434 | return 0; | ||
420 | } | 435 | } |
421 | 436 | ||
422 | /* }====================================================== */ | 437 | /* }====================================================== */ |
@@ -424,22 +439,20 @@ static void testC (void) { | |||
424 | 439 | ||
425 | 440 | ||
426 | static const struct luaL_reg tests_funcs[] = { | 441 | static const struct luaL_reg tests_funcs[] = { |
427 | {"hash", (lua_CFunction)hash_query}, | 442 | {"hash", hash_query}, |
428 | {"limits", (lua_CFunction)get_limits}, | 443 | {"limits", get_limits}, |
429 | {"listcode", (lua_CFunction)listcode}, | 444 | {"listcode", listcode}, |
430 | {"liststrings", (lua_CFunction)liststrings}, | 445 | {"liststrings", liststrings}, |
431 | {"listlocals", (lua_CFunction)listlocals}, | 446 | {"listlocals", listlocals}, |
432 | {"querystr", (lua_CFunction)string_query}, | 447 | {"querystr", string_query}, |
433 | {"querytab", (lua_CFunction)table_query}, | 448 | {"querytab", table_query}, |
434 | {"testC", (lua_CFunction)testC}, | 449 | {"testC", testC}, |
435 | {"totalmem", (lua_CFunction)mem_query} | 450 | {"totalmem", mem_query} |
436 | }; | 451 | }; |
437 | 452 | ||
438 | 453 | ||
439 | void luaB_opentests (lua_State *L) { | 454 | void luaB_opentests (lua_State *L) { |
440 | if (lua_state != NULL) return; /* do not open tests for auxiliar states */ | 455 | luaL_openl(L, tests_funcs); |
441 | lua_state = L; | ||
442 | luaL_openl(tests_funcs); | ||
443 | } | 456 | } |
444 | 457 | ||
445 | #endif | 458 | #endif |