diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 61 |
1 files changed, 23 insertions, 38 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.96 2001/11/06 21:41:43 roberto Exp $ | 2 | ** $Id: ltests.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ |
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 | */ |
@@ -240,13 +240,13 @@ static int mem_query (lua_State *L) { | |||
240 | 240 | ||
241 | static int hash_query (lua_State *L) { | 241 | static int hash_query (lua_State *L) { |
242 | if (lua_isnull(L, 2)) { | 242 | if (lua_isnull(L, 2)) { |
243 | luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, "string expected"); | 243 | luaL_arg_check(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); |
244 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->tsv.hash); | 244 | lua_pushnumber(L, tsvalue(luaA_index(L, 1))->tsv.hash); |
245 | } | 245 | } |
246 | else { | 246 | else { |
247 | TObject *o = luaA_index(L, 1); | 247 | TObject *o = luaA_index(L, 1); |
248 | Table *t; | 248 | Table *t; |
249 | luaL_check_rawtype(L, 2, LUA_TTABLE); | 249 | luaL_check_type(L, 2, LUA_TTABLE); |
250 | t = hvalue(luaA_index(L, 2)); | 250 | t = hvalue(luaA_index(L, 2)); |
251 | lua_pushnumber(L, luaH_mainposition(t, o) - t->node); | 251 | lua_pushnumber(L, luaH_mainposition(t, o) - t->node); |
252 | } | 252 | } |
@@ -257,7 +257,7 @@ static int hash_query (lua_State *L) { | |||
257 | static int table_query (lua_State *L) { | 257 | static int table_query (lua_State *L) { |
258 | const Table *t; | 258 | const Table *t; |
259 | int i = luaL_opt_int(L, 2, -1); | 259 | int i = luaL_opt_int(L, 2, -1); |
260 | luaL_check_rawtype(L, 1, LUA_TTABLE); | 260 | luaL_check_type(L, 1, LUA_TTABLE); |
261 | t = hvalue(luaA_index(L, 1)); | 261 | t = hvalue(luaA_index(L, 1)); |
262 | if (i == -1) { | 262 | if (i == -1) { |
263 | lua_pushnumber(L, t->sizearray); | 263 | lua_pushnumber(L, t->sizearray); |
@@ -333,6 +333,18 @@ static int unref (lua_State *L) { | |||
333 | return 0; | 333 | return 0; |
334 | } | 334 | } |
335 | 335 | ||
336 | static int eventtable (lua_State *L) { | ||
337 | luaL_check_any(L, 1); | ||
338 | if (lua_isnull(L, 2)) | ||
339 | lua_geteventtable(L, 1); | ||
340 | else { | ||
341 | lua_settop(L, 2); | ||
342 | luaL_check_type(L, 2, LUA_TTABLE); | ||
343 | lua_seteventtable(L, 1); | ||
344 | } | ||
345 | return 1; | ||
346 | } | ||
347 | |||
336 | static int newuserdata (lua_State *L) { | 348 | static int newuserdata (lua_State *L) { |
337 | size_t size = luaL_check_int(L, 1); | 349 | size_t size = luaL_check_int(L, 1); |
338 | char *p = cast(char *, lua_newuserdata(L, size)); | 350 | char *p = cast(char *, lua_newuserdata(L, size)); |
@@ -345,24 +357,13 @@ static int newuserdatabox (lua_State *L) { | |||
345 | return 1; | 357 | return 1; |
346 | } | 358 | } |
347 | 359 | ||
348 | static int settag (lua_State *L) { | ||
349 | luaL_check_any(L, 1); | ||
350 | lua_pushvalue(L, 1); /* push value */ | ||
351 | lua_settag(L, luaL_check_int(L, 2)); | ||
352 | return 1; /* return value */ | ||
353 | } | ||
354 | 360 | ||
355 | static int udataval (lua_State *L) { | 361 | static int udataval (lua_State *L) { |
356 | luaL_check_rawtype(L, 1, LUA_TUSERDATA); | 362 | luaL_check_type(L, 1, LUA_TUSERDATA); |
357 | lua_pushnumber(L, cast(int, lua_touserdata(L, 1))); | 363 | lua_pushnumber(L, cast(int, lua_touserdata(L, 1))); |
358 | return 1; | 364 | return 1; |
359 | } | 365 | } |
360 | 366 | ||
361 | static int newtag (lua_State *L) { | ||
362 | lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1), | ||
363 | cast(int, lua_tonumber(L, 2)))); | ||
364 | return 1; | ||
365 | } | ||
366 | 367 | ||
367 | static int doonnewstack (lua_State *L) { | 368 | static int doonnewstack (lua_State *L) { |
368 | lua_State *L1 = lua_newthread(L, luaL_check_int(L, 1)); | 369 | lua_State *L1 = lua_newthread(L, luaL_check_int(L, 1)); |
@@ -435,16 +436,6 @@ static int doremote (lua_State *L) { | |||
435 | } | 436 | } |
436 | } | 437 | } |
437 | 438 | ||
438 | static int settagmethod (lua_State *L) { | ||
439 | int tag = luaL_check_int(L, 1); | ||
440 | const char *event = luaL_check_string(L, 2); | ||
441 | luaL_check_any(L, 3); | ||
442 | lua_gettagmethod(L, tag, event); | ||
443 | lua_pushvalue(L, 3); | ||
444 | lua_settagmethod(L, tag, event); | ||
445 | return 1; | ||
446 | } | ||
447 | |||
448 | 439 | ||
449 | static int log2_aux (lua_State *L) { | 440 | static int log2_aux (lua_State *L) { |
450 | lua_pushnumber(L, luaO_log2(luaL_check_int(L, 1))); | 441 | lua_pushnumber(L, luaO_log2(luaL_check_int(L, 1))); |
@@ -614,18 +605,14 @@ static int testC (lua_State *L) { | |||
614 | else if EQ("dostring") { | 605 | else if EQ("dostring") { |
615 | lua_dostring(L, luaL_check_string(L, getnum)); | 606 | lua_dostring(L, luaL_check_string(L, getnum)); |
616 | } | 607 | } |
617 | else if EQ("settagmethod") { | 608 | else if EQ("seteventtable") { |
618 | int tag = getnum; | 609 | lua_seteventtable(L, getnum); |
619 | const char *event = getname; | ||
620 | lua_settagmethod(L, tag, event); | ||
621 | } | 610 | } |
622 | else if EQ("gettagmethod") { | 611 | else if EQ("geteventtable") { |
623 | int tag = getnum; | 612 | lua_geteventtable(L, getnum); |
624 | const char *event = getname; | ||
625 | lua_gettagmethod(L, tag, event); | ||
626 | } | 613 | } |
627 | else if EQ("type") { | 614 | else if EQ("type") { |
628 | lua_pushstring(L, lua_type(L, getnum)); | 615 | lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); |
629 | } | 616 | } |
630 | else luaL_verror(L, "unknown instruction %.30s", buff); | 617 | else luaL_verror(L, "unknown instruction %.30s", buff); |
631 | } | 618 | } |
@@ -651,16 +638,14 @@ static const struct luaL_reg tests_funcs[] = { | |||
651 | {"unref", unref}, | 638 | {"unref", unref}, |
652 | {"d2s", d2s}, | 639 | {"d2s", d2s}, |
653 | {"s2d", s2d}, | 640 | {"s2d", s2d}, |
641 | {"eventtable", eventtable}, | ||
654 | {"newuserdata", newuserdata}, | 642 | {"newuserdata", newuserdata}, |
655 | {"newuserdatabox", newuserdatabox}, | 643 | {"newuserdatabox", newuserdatabox}, |
656 | {"settag", settag}, | ||
657 | {"udataval", udataval}, | 644 | {"udataval", udataval}, |
658 | {"newtag", newtag}, | ||
659 | {"doonnewstack", doonnewstack}, | 645 | {"doonnewstack", doonnewstack}, |
660 | {"newstate", newstate}, | 646 | {"newstate", newstate}, |
661 | {"closestate", closestate}, | 647 | {"closestate", closestate}, |
662 | {"doremote", doremote}, | 648 | {"doremote", doremote}, |
663 | {"settagmethod", settagmethod}, | ||
664 | {"log2", log2_aux}, | 649 | {"log2", log2_aux}, |
665 | {"totalmem", mem_query} | 650 | {"totalmem", mem_query} |
666 | }; | 651 | }; |