Browse Source

"next" & "nextvar" check if argument is a result of previous calls

Roberto Ierusalimschy 28 years ago
parent
commit
067db30d71
2 changed files with 13 additions and 9 deletions
  1. 8 3
      hash.c
  2. 5 6
      table.c

+ 8 - 3
hash.c

@@ -3,7 +3,7 @@
 ** hash manager for lua
 ** hash manager for lua
 */
 */
 
 
-char *rcs_hash="$Id: hash.c,v 2.42 1997/05/08 20:43:30 roberto Exp roberto $";
+char *rcs_hash="$Id: hash.c,v 2.43 1997/05/14 18:38:29 roberto Exp roberto $";
 
 
 
 
 #include "luamem.h"
 #include "luamem.h"
@@ -327,6 +327,11 @@ void lua_next (void)
   t = avalue(luaI_Address(o));
   t = avalue(luaI_Address(o));
   if (lua_isnil(r))
   if (lua_isnil(r))
     hashnext(t, 0);
     hashnext(t, 0);
-  else
-    hashnext(t, present(t, luaI_Address(r))+1);
+  else {
+    int i = present(t, luaI_Address(r));
+    Node *n = node(t, i);
+    luaL_arg_check(ttype(ref(n))!=LUA_T_NIL && ttype(val(n))!=LUA_T_NIL,
+                   2, "key not found");
+    hashnext(t, i+1);
+  }
 }
 }

+ 5 - 6
table.c

@@ -3,7 +3,7 @@
 ** Module to control static tables
 ** Module to control static tables
 */
 */
 
 
-char *rcs_table="$Id: table.c,v 2.71 1997/06/09 17:28:14 roberto Exp roberto $";
+char *rcs_table="$Id: table.c,v 2.72 1997/06/17 18:09:31 roberto Exp roberto $";
 
 
 #include "luamem.h"
 #include "luamem.h"
 #include "auxlib.h"
 #include "auxlib.h"
@@ -224,11 +224,10 @@ void lua_pack (void)
 */
 */
 void luaI_nextvar (void)
 void luaI_nextvar (void)
 {
 {
-  Word next;
-  if (lua_isnil(lua_getparam(1)))
-    next = 0;
-  else 
-    next = luaI_findsymbolbyname(luaL_check_string(1)) + 1;
+  Word next = lua_isnil(lua_getparam(1)) ? 0 : 
+              luaI_findsymbolbyname(luaL_check_string(1))+1;
+  if (next != 0)
+    luaL_arg_check(s_ttype(next-1)!=LUA_T_NIL, 1, "undefined global name");
   while (next < lua_ntable && s_ttype(next) == LUA_T_NIL)
   while (next < lua_ntable && s_ttype(next) == LUA_T_NIL)
     next++;
     next++;
   if (next < lua_ntable) {
   if (next < lua_ntable) {