Browse Source

auxiliar functions "luaH_setint" & "luaH_getint".

Roberto Ierusalimschy 27 years ago
parent
commit
41d9ea948c
2 changed files with 23 additions and 3 deletions
  1. 19 2
      ltable.c
  2. 4 1
      ltable.h

+ 19 - 2
ltable.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltable.c,v 1.11 1998/01/13 18:06:27 roberto Exp roberto $
+** $Id: ltable.c,v 1.12 1998/01/28 16:50:33 roberto Exp roberto $
 ** Lua tables (hash)
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -162,7 +162,7 @@ TObject *luaH_get (Hash *t, TObject *ref)
 {
 {
  int h = present(t, ref);
  int h = present(t, ref);
  if (ttype(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h));
  if (ttype(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h));
- else return NULL;
+ else return &luaO_nilobject;
 }
 }
 
 
 
 
@@ -214,3 +214,20 @@ Node *luaH_next (TObject *o, TObject *r)
     return hashnext(t, i+1);
     return hashnext(t, i+1);
   }
   }
 }
 }
+
+
+void luaH_setint (Hash *t, int ref, TObject *val) {
+  TObject index;
+  ttype(&index) = LUA_T_NUMBER;
+  nvalue(&index) = ref;
+  *(luaH_set(t, &index)) = *val;
+}
+
+
+TObject *luaH_getint (Hash *t, int ref) {
+  TObject index;
+  ttype(&index) = LUA_T_NUMBER;
+  nvalue(&index) = ref;
+  return luaH_get(t, &index);
+}
+

+ 4 - 1
ltable.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltable.h,v 1.4 1997/11/19 17:29:23 roberto Exp roberto $
+** $Id: ltable.h,v 1.5 1997/11/26 18:53:45 roberto Exp roberto $
 ** Lua tables (hash)
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -20,5 +20,8 @@ void luaH_free (Hash *frees);
 TObject *luaH_get (Hash *t, TObject *ref);
 TObject *luaH_get (Hash *t, TObject *ref);
 TObject *luaH_set (Hash *t, TObject *ref);
 TObject *luaH_set (Hash *t, TObject *ref);
 Node *luaH_next (TObject *o, TObject *r);
 Node *luaH_next (TObject *o, TObject *r);
+void luaH_setint (Hash *t, int ref, TObject *val);
+TObject *luaH_getint (Hash *t, int ref);
+
 
 
 #endif
 #endif