diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-31 10:29:47 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-31 10:29:47 -0300 |
| commit | a0de89d62a71b944e56264ec948e01cad12d5602 (patch) | |
| tree | 3c6083d3819d2a8613015b1b32fc421407a5427b /ltests.c | |
| parent | 21dc77b2afa6f7185b6f96b80f54569b68c4dca3 (diff) | |
| download | lua-a0de89d62a71b944e56264ec948e01cad12d5602.tar.gz lua-a0de89d62a71b944e56264ec948e01cad12d5602.tar.bz2 lua-a0de89d62a71b944e56264ec948e01cad12d5602.zip | |
simpler tests for simpler API
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 39 |
1 files changed, 11 insertions, 28 deletions
| @@ -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 | ||
| 338 | static int getnum (const char **pc, int *reg) { | 338 | static 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 | ||
| 358 | static int getreg (const char **pc) { | ||
| 359 | skip(pc); | ||
| 360 | (*pc)++; /* skip the `r' */ | ||
| 361 | return getnum(pc, NULL); | ||
| 362 | } | ||
| 363 | |||
| 364 | static const char *getname (char *buff, const char **pc) { | 356 | static 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 | ||
| 381 | static int testC (lua_State *L) { | 372 | static 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; |
