mirror of
https://github.com/lua/lua
synced 2024-11-26 14:51:21 +03:00
inheritance is not built-in
This commit is contained in:
parent
0a5dce5704
commit
62ec3797d5
40
hash.c
40
hash.c
@ -3,7 +3,7 @@
|
|||||||
** hash manager for lua
|
** hash manager for lua
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_hash="$Id: hash.c,v 2.11 1994/11/02 20:29:09 roberto Exp roberto $";
|
char *rcs_hash="$Id: hash.c,v 2.12 1994/11/03 22:20:15 roberto Exp $";
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -235,47 +235,17 @@ static void rehash (Hash *t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** If the hash node is present, return its pointer, otherwise search
|
** If the hash node is present, return its pointer, otherwise return
|
||||||
** the node at parent table, recursively, if there is parent.
|
** null.
|
||||||
** If no parent and the node is not present, return a static nil object.
|
|
||||||
*/
|
*/
|
||||||
Object *lua_hashget (Hash *t, Object *ref)
|
Object *lua_hashget (Hash *t, Object *ref)
|
||||||
{
|
{
|
||||||
static int count = 1000;
|
|
||||||
static Object nil_obj = {LUA_T_NIL, {NULL}};
|
|
||||||
int h = present(t, ref);
|
int h = present(t, ref);
|
||||||
if (tag(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h));
|
if (tag(ref(node(t, h))) != LUA_T_NIL) return val(node(t, h));
|
||||||
if (--count == 0)
|
else return NULL;
|
||||||
lua_reportbug ("hierarchy too deep (maybe there is an inheritance loop)");
|
|
||||||
{ /* check "parent" or "godparent" field */
|
|
||||||
Hash *p;
|
|
||||||
Object parent;
|
|
||||||
Object godparent;
|
|
||||||
tag(&parent) = LUA_T_STRING; svalue(&parent) = "parent";
|
|
||||||
tag(&godparent) = LUA_T_STRING; svalue(&godparent) = "godparent";
|
|
||||||
|
|
||||||
h = present(t, &parent);
|
|
||||||
p = tag(ref(node(t, h))) != LUA_T_NIL && tag(val(node(t, h))) == LUA_T_ARRAY ?
|
|
||||||
avalue(val(node(t, h))) : NULL;
|
|
||||||
if (p != NULL)
|
|
||||||
{
|
|
||||||
Object *r = lua_hashget(p, ref);
|
|
||||||
if (tag(r) != LUA_T_NIL) { count++; return r; }
|
|
||||||
}
|
|
||||||
|
|
||||||
h = present(t, &godparent);
|
|
||||||
p = tag(ref(node(t, h))) != LUA_T_NIL && tag(val(node(t, h))) == LUA_T_ARRAY ?
|
|
||||||
avalue(val(node(t, h))) : NULL;
|
|
||||||
if (p != NULL)
|
|
||||||
{
|
|
||||||
Object *r = lua_hashget(p, ref);
|
|
||||||
if (tag(r) != LUA_T_NIL) { count++; return r; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
return &nil_obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** If the hash node is present, return its pointer, otherwise create a new
|
** If the hash node is present, return its pointer, otherwise create a new
|
||||||
** node for the given reference and also return its pointer.
|
** node for the given reference and also return its pointer.
|
||||||
|
Loading…
Reference in New Issue
Block a user