diff options
Diffstat (limited to 'ltable.c')
-rw-r--r-- | ltable.c | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 2.10 2004/11/24 19:20:21 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.11 2004/12/03 20:50:25 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -122,7 +122,7 @@ static int arrayindex (const TValue *key) { | |||
122 | /* | 122 | /* |
123 | ** returns the index of a `key' for table traversals. First goes all | 123 | ** returns the index of a `key' for table traversals. First goes all |
124 | ** elements in the array part, then elements in the hash part. The | 124 | ** elements in the array part, then elements in the hash part. The |
125 | ** beginning and end of a traversal are signalled by -1. | 125 | ** beginning of a traversal is signalled by -1. |
126 | */ | 126 | */ |
127 | static int findindex (lua_State *L, Table *t, StkId key) { | 127 | static int findindex (lua_State *L, Table *t, StkId key) { |
128 | int i; | 128 | int i; |
@@ -131,12 +131,20 @@ static int findindex (lua_State *L, Table *t, StkId key) { | |||
131 | if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ | 131 | if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ |
132 | return i-1; /* yes; that's the index (corrected to C) */ | 132 | return i-1; /* yes; that's the index (corrected to C) */ |
133 | else { | 133 | else { |
134 | const TValue *v = luaH_get(t, key); | 134 | Node *n = luaH_mainposition(t, key); |
135 | if (v == &luaO_nilobject) | 135 | do { /* check whether `key' is somewhere in the chain */ |
136 | luaG_runerror(L, "invalid key for `next'"); | 136 | /* key may be dead already, but it is ok to use it in `next' */ |
137 | i = cast(int, (cast(const lu_byte *, v) - | 137 | if (luaO_rawequalObj(key2tval(n), key) || |
138 | cast(const lu_byte *, gval(gnode(t, 0)))) / sizeof(Node)); | 138 | (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && |
139 | return i + t->sizearray; /* hash elements are numbered after array ones */ | 139 | gcvalue(gkey(n)) == gcvalue(key))) { |
140 | i = n - gnode(t, 0); /* key index in hash table */ | ||
141 | /* hash elements are numbered after array ones */ | ||
142 | return i + t->sizearray; | ||
143 | } | ||
144 | else n = gnext(n); | ||
145 | } while (n); | ||
146 | luaG_runerror(L, "invalid key for `next'"); /* key not found */ | ||
147 | return 0; /* to avoid warnings */ | ||
140 | } | 148 | } |
141 | } | 149 | } |
142 | 150 | ||