diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-14 13:41:38 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-11-14 13:41:38 -0200 |
| commit | 097edd388494bf8d294adb101b9c5fda688813e1 (patch) | |
| tree | ecf43d85ab01e5c939ae7b125befc15b9fa23c27 /ltests.c | |
| parent | 5c5d9b27031f0a7fcf61df86cd242105c38485d6 (diff) | |
| download | lua-097edd388494bf8d294adb101b9c5fda688813e1.tar.gz lua-097edd388494bf8d294adb101b9c5fda688813e1.tar.bz2 lua-097edd388494bf8d294adb101b9c5fda688813e1.zip | |
better names for auxiliar functions
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 64 |
1 files changed, 32 insertions, 32 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.141 2002/11/13 11:31:39 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.142 2002/11/14 11:51:23 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 | */ |
| @@ -178,7 +178,7 @@ void luaI_printcode (Proto *pt, int size) { | |||
| 178 | static int listcode (lua_State *L) { | 178 | static int listcode (lua_State *L) { |
| 179 | int pc; | 179 | int pc; |
| 180 | Proto *p; | 180 | Proto *p; |
| 181 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 181 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 182 | 1, "Lua function expected"); | 182 | 1, "Lua function expected"); |
| 183 | p = clvalue(index(L, 1))->l.p; | 183 | p = clvalue(index(L, 1))->l.p; |
| 184 | lua_newtable(L); | 184 | lua_newtable(L); |
| @@ -197,7 +197,7 @@ static int listcode (lua_State *L) { | |||
| 197 | static int listk (lua_State *L) { | 197 | static int listk (lua_State *L) { |
| 198 | Proto *p; | 198 | Proto *p; |
| 199 | int i; | 199 | int i; |
| 200 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 200 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 201 | 1, "Lua function expected"); | 201 | 1, "Lua function expected"); |
| 202 | p = clvalue(index(L, 1))->l.p; | 202 | p = clvalue(index(L, 1))->l.p; |
| 203 | lua_newtable(L); | 203 | lua_newtable(L); |
| @@ -212,10 +212,10 @@ static int listk (lua_State *L) { | |||
| 212 | 212 | ||
| 213 | static int listlocals (lua_State *L) { | 213 | static int listlocals (lua_State *L) { |
| 214 | Proto *p; | 214 | Proto *p; |
| 215 | int pc = luaL_check_int(L, 2) - 1; | 215 | int pc = luaL_checkint(L, 2) - 1; |
| 216 | int i = 0; | 216 | int i = 0; |
| 217 | const char *name; | 217 | const char *name; |
| 218 | luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 218 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
| 219 | 1, "Lua function expected"); | 219 | 1, "Lua function expected"); |
| 220 | p = clvalue(index(L, 1))->l.p; | 220 | p = clvalue(index(L, 1))->l.p; |
| 221 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) | 221 | while ((name = luaF_getlocalname(p, ++i, pc)) != NULL) |
| @@ -248,7 +248,7 @@ static int mem_query (lua_State *L) { | |||
| 248 | return 3; | 248 | return 3; |
| 249 | } | 249 | } |
| 250 | else { | 250 | else { |
| 251 | memdebug_memlimit = luaL_check_int(L, 1); | 251 | memdebug_memlimit = luaL_checkint(L, 1); |
| 252 | return 0; | 252 | return 0; |
| 253 | } | 253 | } |
| 254 | } | 254 | } |
| @@ -256,13 +256,13 @@ static int mem_query (lua_State *L) { | |||
| 256 | 256 | ||
| 257 | static int hash_query (lua_State *L) { | 257 | static int hash_query (lua_State *L) { |
| 258 | if (lua_isnone(L, 2)) { | 258 | if (lua_isnone(L, 2)) { |
| 259 | luaL_arg_check(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); | 259 | luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); |
| 260 | lua_pushnumber(L, tsvalue(index(L, 1))->tsv.hash); | 260 | lua_pushnumber(L, tsvalue(index(L, 1))->tsv.hash); |
| 261 | } | 261 | } |
| 262 | else { | 262 | else { |
| 263 | TObject *o = index(L, 1); | 263 | TObject *o = index(L, 1); |
| 264 | Table *t; | 264 | Table *t; |
| 265 | luaL_check_type(L, 2, LUA_TTABLE); | 265 | luaL_checktype(L, 2, LUA_TTABLE); |
| 266 | t = hvalue(index(L, 2)); | 266 | t = hvalue(index(L, 2)); |
| 267 | lua_pushnumber(L, luaH_mainposition(t, o) - t->node); | 267 | lua_pushnumber(L, luaH_mainposition(t, o) - t->node); |
| 268 | } | 268 | } |
| @@ -283,8 +283,8 @@ static int stacklevel (lua_State *L) { | |||
| 283 | 283 | ||
| 284 | static int table_query (lua_State *L) { | 284 | static int table_query (lua_State *L) { |
| 285 | const Table *t; | 285 | const Table *t; |
| 286 | int i = luaL_opt_int(L, 2, -1); | 286 | int i = luaL_optint(L, 2, -1); |
| 287 | luaL_check_type(L, 1, LUA_TTABLE); | 287 | luaL_checktype(L, 1, LUA_TTABLE); |
| 288 | t = hvalue(index(L, 1)); | 288 | t = hvalue(index(L, 1)); |
| 289 | if (i == -1) { | 289 | if (i == -1) { |
| 290 | lua_pushnumber(L, t->sizearray); | 290 | lua_pushnumber(L, t->sizearray); |
| @@ -316,7 +316,7 @@ static int table_query (lua_State *L) { | |||
| 316 | 316 | ||
| 317 | static int string_query (lua_State *L) { | 317 | static int string_query (lua_State *L) { |
| 318 | stringtable *tb = &G(L)->strt; | 318 | stringtable *tb = &G(L)->strt; |
| 319 | int s = luaL_opt_int(L, 2, 0) - 1; | 319 | int s = luaL_optint(L, 2, 0) - 1; |
| 320 | if (s==-1) { | 320 | if (s==-1) { |
| 321 | lua_pushnumber(L ,tb->nuse); | 321 | lua_pushnumber(L ,tb->nuse); |
| 322 | lua_pushnumber(L ,tb->size); | 322 | lua_pushnumber(L ,tb->size); |
| @@ -338,8 +338,8 @@ static int string_query (lua_State *L) { | |||
| 338 | 338 | ||
| 339 | static int tref (lua_State *L) { | 339 | static int tref (lua_State *L) { |
| 340 | int level = lua_gettop(L); | 340 | int level = lua_gettop(L); |
| 341 | int lock = luaL_opt_int(L, 2, 1); | 341 | int lock = luaL_optint(L, 2, 1); |
| 342 | luaL_check_any(L, 1); | 342 | luaL_checkany(L, 1); |
| 343 | lua_pushvalue(L, 1); | 343 | lua_pushvalue(L, 1); |
| 344 | lua_pushnumber(L, lua_ref(L, lock)); | 344 | lua_pushnumber(L, lua_ref(L, lock)); |
| 345 | assert(lua_gettop(L) == level+1); /* +1 for result */ | 345 | assert(lua_gettop(L) == level+1); /* +1 for result */ |
| @@ -348,34 +348,34 @@ static int tref (lua_State *L) { | |||
| 348 | 348 | ||
| 349 | static int getref (lua_State *L) { | 349 | static int getref (lua_State *L) { |
| 350 | int level = lua_gettop(L); | 350 | int level = lua_gettop(L); |
| 351 | lua_getref(L, luaL_check_int(L, 1)); | 351 | lua_getref(L, luaL_checkint(L, 1)); |
| 352 | assert(lua_gettop(L) == level+1); | 352 | assert(lua_gettop(L) == level+1); |
| 353 | return 1; | 353 | return 1; |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | static int unref (lua_State *L) { | 356 | static int unref (lua_State *L) { |
| 357 | int level = lua_gettop(L); | 357 | int level = lua_gettop(L); |
| 358 | lua_unref(L, luaL_check_int(L, 1)); | 358 | lua_unref(L, luaL_checkint(L, 1)); |
| 359 | assert(lua_gettop(L) == level); | 359 | assert(lua_gettop(L) == level); |
| 360 | return 0; | 360 | return 0; |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | static int metatable (lua_State *L) { | 363 | static int metatable (lua_State *L) { |
| 364 | luaL_check_any(L, 1); | 364 | luaL_checkany(L, 1); |
| 365 | if (lua_isnone(L, 2)) { | 365 | if (lua_isnone(L, 2)) { |
| 366 | if (lua_getmetatable(L, 1) == 0) | 366 | if (lua_getmetatable(L, 1) == 0) |
| 367 | lua_pushnil(L); | 367 | lua_pushnil(L); |
| 368 | } | 368 | } |
| 369 | else { | 369 | else { |
| 370 | lua_settop(L, 2); | 370 | lua_settop(L, 2); |
| 371 | luaL_check_type(L, 2, LUA_TTABLE); | 371 | luaL_checktype(L, 2, LUA_TTABLE); |
| 372 | lua_setmetatable(L, 1); | 372 | lua_setmetatable(L, 1); |
| 373 | } | 373 | } |
| 374 | return 1; | 374 | return 1; |
| 375 | } | 375 | } |
| 376 | 376 | ||
| 377 | static int newuserdata (lua_State *L) { | 377 | static int newuserdata (lua_State *L) { |
| 378 | size_t size = luaL_check_int(L, 1); | 378 | size_t size = luaL_checkint(L, 1); |
| 379 | char *p = cast(char *, lua_newuserdata(L, size)); | 379 | char *p = cast(char *, lua_newuserdata(L, size)); |
| 380 | while (size--) *p++ = '\0'; | 380 | while (size--) *p++ = '\0'; |
| 381 | return 1; | 381 | return 1; |
| @@ -383,7 +383,7 @@ static int newuserdata (lua_State *L) { | |||
| 383 | 383 | ||
| 384 | 384 | ||
| 385 | static int pushuserdata (lua_State *L) { | 385 | static int pushuserdata (lua_State *L) { |
| 386 | lua_pushlightuserdata(L, cast(void *, luaL_check_int(L, 1))); | 386 | lua_pushlightuserdata(L, cast(void *, luaL_checkint(L, 1))); |
| 387 | return 1; | 387 | return 1; |
| 388 | } | 388 | } |
| 389 | 389 | ||
| @@ -397,7 +397,7 @@ static int udataval (lua_State *L) { | |||
| 397 | static int doonnewstack (lua_State *L) { | 397 | static int doonnewstack (lua_State *L) { |
| 398 | lua_State *L1 = lua_newthread(L); | 398 | lua_State *L1 = lua_newthread(L); |
| 399 | size_t l; | 399 | size_t l; |
| 400 | const char *s = luaL_check_lstr(L, 1, &l); | 400 | const char *s = luaL_checklstring(L, 1, &l); |
| 401 | int status = luaL_loadbuffer(L1, s, l, s); | 401 | int status = luaL_loadbuffer(L1, s, l, s); |
| 402 | if (status == 0) | 402 | if (status == 0) |
| 403 | status = lua_pcall(L1, 0, 0, 0); | 403 | status = lua_pcall(L1, 0, 0, 0); |
| @@ -407,12 +407,12 @@ static int doonnewstack (lua_State *L) { | |||
| 407 | 407 | ||
| 408 | 408 | ||
| 409 | static int s2d (lua_State *L) { | 409 | static int s2d (lua_State *L) { |
| 410 | lua_pushnumber(L, *cast(const double *, luaL_check_string(L, 1))); | 410 | lua_pushnumber(L, *cast(const double *, luaL_checkstring(L, 1))); |
| 411 | return 1; | 411 | return 1; |
| 412 | } | 412 | } |
| 413 | 413 | ||
| 414 | static int d2s (lua_State *L) { | 414 | static int d2s (lua_State *L) { |
| 415 | double d = luaL_check_number(L, 1); | 415 | double d = luaL_checknumber(L, 1); |
| 416 | lua_pushlstring(L, cast(char *, &d), sizeof(d)); | 416 | lua_pushlstring(L, cast(char *, &d), sizeof(d)); |
| 417 | return 1; | 417 | return 1; |
| 418 | } | 418 | } |
| @@ -430,7 +430,7 @@ static int newstate (lua_State *L) { | |||
| 430 | } | 430 | } |
| 431 | 431 | ||
| 432 | static int loadlib (lua_State *L) { | 432 | static int loadlib (lua_State *L) { |
| 433 | lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1))); | 433 | lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_checknumber(L, 1))); |
| 434 | lua_register(L1, "mathlibopen", lua_mathlibopen); | 434 | lua_register(L1, "mathlibopen", lua_mathlibopen); |
| 435 | lua_register(L1, "strlibopen", lua_strlibopen); | 435 | lua_register(L1, "strlibopen", lua_strlibopen); |
| 436 | lua_register(L1, "iolibopen", lua_iolibopen); | 436 | lua_register(L1, "iolibopen", lua_iolibopen); |
| @@ -440,16 +440,16 @@ static int loadlib (lua_State *L) { | |||
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | static int closestate (lua_State *L) { | 442 | static int closestate (lua_State *L) { |
| 443 | lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1))); | 443 | lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_checknumber(L, 1))); |
| 444 | lua_close(L1); | 444 | lua_close(L1); |
| 445 | lua_unlock(L); /* close cannot unlock that */ | 445 | lua_unlock(L); /* close cannot unlock that */ |
| 446 | return 0; | 446 | return 0; |
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | static int doremote (lua_State *L) { | 449 | static int doremote (lua_State *L) { |
| 450 | lua_State *L1 = cast(lua_State *,cast(unsigned long,luaL_check_number(L, 1))); | 450 | lua_State *L1 = cast(lua_State *,cast(unsigned long,luaL_checknumber(L, 1))); |
| 451 | size_t lcode; | 451 | size_t lcode; |
| 452 | const char *code = luaL_check_lstr(L, 2, &lcode); | 452 | const char *code = luaL_checklstring(L, 2, &lcode); |
| 453 | int status; | 453 | int status; |
| 454 | lua_settop(L1, 0); | 454 | lua_settop(L1, 0); |
| 455 | status = luaL_loadbuffer(L1, code, lcode, code); | 455 | status = luaL_loadbuffer(L1, code, lcode, code); |
| @@ -471,13 +471,13 @@ static int doremote (lua_State *L) { | |||
| 471 | 471 | ||
| 472 | 472 | ||
| 473 | static int log2_aux (lua_State *L) { | 473 | static int log2_aux (lua_State *L) { |
| 474 | lua_pushnumber(L, luaO_log2(luaL_check_int(L, 1))); | 474 | lua_pushnumber(L, luaO_log2(luaL_checkint(L, 1))); |
| 475 | return 1; | 475 | return 1; |
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | 478 | ||
| 479 | static int test_do (lua_State *L) { | 479 | static int test_do (lua_State *L) { |
| 480 | const char *p = luaL_check_string(L, 1); | 480 | const char *p = luaL_checkstring(L, 1); |
| 481 | if (*p == '@') | 481 | if (*p == '@') |
| 482 | lua_dofile(L, p+1); | 482 | lua_dofile(L, p+1); |
| 483 | else | 483 | else |
| @@ -536,7 +536,7 @@ static const char *getname_aux (char *buff, const char **pc) { | |||
| 536 | 536 | ||
| 537 | static int testC (lua_State *L) { | 537 | static int testC (lua_State *L) { |
| 538 | char buff[30]; | 538 | char buff[30]; |
| 539 | const char *pc = luaL_check_string(L, 1); | 539 | const char *pc = luaL_checkstring(L, 1); |
| 540 | for (;;) { | 540 | for (;;) { |
| 541 | const char *inst = getname; | 541 | const char *inst = getname; |
| 542 | if EQ("") return 0; | 542 | if EQ("") return 0; |
| @@ -657,11 +657,11 @@ static int testC (lua_State *L) { | |||
| 657 | } | 657 | } |
| 658 | else if EQ("loadstring") { | 658 | else if EQ("loadstring") { |
| 659 | size_t sl; | 659 | size_t sl; |
| 660 | const char *s = luaL_check_lstr(L, getnum, &sl); | 660 | const char *s = luaL_checklstring(L, getnum, &sl); |
| 661 | luaL_loadbuffer(L, s, sl, s); | 661 | luaL_loadbuffer(L, s, sl, s); |
| 662 | } | 662 | } |
| 663 | else if EQ("loadfile") { | 663 | else if EQ("loadfile") { |
| 664 | luaL_loadfile(L, luaL_check_string(L, getnum)); | 664 | luaL_loadfile(L, luaL_checkstring(L, getnum)); |
| 665 | } | 665 | } |
| 666 | else if EQ("setmetatable") { | 666 | else if EQ("setmetatable") { |
| 667 | lua_setmetatable(L, getnum); | 667 | lua_setmetatable(L, getnum); |
| @@ -724,7 +724,7 @@ static void fim (void) { | |||
| 724 | int luaB_opentests (lua_State *L) { | 724 | int luaB_opentests (lua_State *L) { |
| 725 | lua_userstateopen(L); /* init lock */ | 725 | lua_userstateopen(L); /* init lock */ |
| 726 | lua_state = L; /* keep first state to be opened */ | 726 | lua_state = L; /* keep first state to be opened */ |
| 727 | luaL_opennamedlib(L, "T", tests_funcs, 0); | 727 | luaL_openlib(L, "T", tests_funcs, 0); |
| 728 | atexit(fim); | 728 | atexit(fim); |
| 729 | return 0; | 729 | return 0; |
| 730 | } | 730 | } |
