diff options
Diffstat (limited to 'lbuiltin.c')
-rw-r--r-- | lbuiltin.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.64 1999/10/04 17:51:04 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.65 1999/10/07 19:04:30 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -447,7 +447,7 @@ static void luaB_foreachvar (void) { | |||
447 | TObject f; /* see comment in 'foreachi' */ | 447 | TObject f; /* see comment in 'foreachi' */ |
448 | f = *luaA_Address(luaL_functionarg(1)); | 448 | f = *luaA_Address(luaL_functionarg(1)); |
449 | luaD_checkstack(4); /* for extra var name, f, var name, and globalval */ | 449 | luaD_checkstack(4); /* for extra var name, f, var name, and globalval */ |
450 | for (s = L->rootglobal; s; s = s->next) { | 450 | for (s = L->rootglobal; s; s = s->nextglobal) { |
451 | if (s->u.s.globalval.ttype != LUA_T_NIL) { | 451 | if (s->u.s.globalval.ttype != LUA_T_NIL) { |
452 | pushtagstring(s); /* keep (extra) s on stack to avoid GC */ | 452 | pushtagstring(s); /* keep (extra) s on stack to avoid GC */ |
453 | *(L->stack.top++) = f; | 453 | *(L->stack.top++) = f; |
@@ -606,6 +606,12 @@ static void mem_query (void) { | |||
606 | } | 606 | } |
607 | 607 | ||
608 | 608 | ||
609 | static void hash_query (void) { | ||
610 | const TObject *o = luaA_Address(luaL_nonnullarg(1)); | ||
611 | lua_pushnumber(luaH_hashindex(o)); | ||
612 | } | ||
613 | |||
614 | |||
609 | static void query_strings (void) { | 615 | static void query_strings (void) { |
610 | int h = luaL_check_int(1) - 1; | 616 | int h = luaL_check_int(1) - 1; |
611 | int s = luaL_opt_int(2, 0) - 1; | 617 | int s = luaL_opt_int(2, 0) - 1; |
@@ -617,10 +623,10 @@ static void query_strings (void) { | |||
617 | } | 623 | } |
618 | else { | 624 | else { |
619 | TaggedString *ts = L->string_root[h].hash[s]; | 625 | TaggedString *ts = L->string_root[h].hash[s]; |
620 | if (ts == NULL) lua_pushstring("<NIL>"); | 626 | for (ts = L->string_root[h].hash[s]; ts; ts = ts->nexthash) { |
621 | else if (ts == &luaS_EMPTY) lua_pushstring("<EMPTY>"); | 627 | if (ts->constindex == -1) lua_pushstring("<USERDATA>"); |
622 | else if (ts->constindex == -1) lua_pushstring("<USERDATA>"); | 628 | else lua_pushstring(ts->str); |
623 | else lua_pushstring(ts->str); | 629 | } |
624 | } | 630 | } |
625 | } | 631 | } |
626 | 632 | ||
@@ -707,9 +713,10 @@ static void testC (void) { | |||
707 | static const struct luaL_reg builtin_funcs[] = { | 713 | static const struct luaL_reg builtin_funcs[] = { |
708 | #ifdef DEBUG | 714 | #ifdef DEBUG |
709 | {"extra", extra_services}, | 715 | {"extra", extra_services}, |
716 | {"hash", hash_query}, | ||
717 | {"querystr", query_strings}, | ||
710 | {"testC", testC}, | 718 | {"testC", testC}, |
711 | {"totalmem", mem_query}, | 719 | {"totalmem", mem_query}, |
712 | {"querystr", query_strings}, | ||
713 | #endif | 720 | #endif |
714 | {"_ALERT", luaB_alert}, | 721 | {"_ALERT", luaB_alert}, |
715 | {"_ERRORMESSAGE", error_message}, | 722 | {"_ERRORMESSAGE", error_message}, |