mirror of https://github.com/rusefi/lua.git
Implementacao de heranca multipla.
This commit is contained in:
parent
1ea0d09281
commit
b826a39919
68
hash.c
68
hash.c
|
@ -3,7 +3,7 @@
|
||||||
** hash manager for lua
|
** hash manager for lua
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_hash="$Id: hash.c,v 2.5 1994/08/17 15:03:11 celes Exp $";
|
char *rcs_hash="$Id: hash.c,v 2.6 1994/08/17 17:41:23 celes Exp celes $";
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -265,23 +265,61 @@ static void rehash (Hash *t)
|
||||||
*/
|
*/
|
||||||
Object *lua_hashget (Hash *t, Object *ref)
|
Object *lua_hashget (Hash *t, Object *ref)
|
||||||
{
|
{
|
||||||
|
static int count = 1000;
|
||||||
static Object nil_obj = {T_NIL, {NULL}};
|
static Object nil_obj = {T_NIL, {NULL}};
|
||||||
Object parent;
|
int h = present(t, ref);
|
||||||
int count = 1000;
|
if (h < 0) return NULL;
|
||||||
tag(&parent) = T_STRING;
|
if (tag(ref(node(t, h))) != T_NIL) return val(node(t, h));
|
||||||
svalue(&parent) = "parent";
|
if (--count == 0)
|
||||||
do
|
|
||||||
{
|
{
|
||||||
int h = present(t, ref);
|
lua_reportbug ("hierarchy too deep (maybe there is an inheritance loop)");
|
||||||
if (h < 0) return NULL;
|
return &nil_obj;
|
||||||
if (tag(ref(node(t, h))) != T_NIL) return val(node(t, h));
|
}
|
||||||
|
|
||||||
h = present(t, &parent); /* assert(p >= 0); */
|
{ /* check "parent" field */
|
||||||
t = tag(ref(node(t, h))) != T_NIL && tag(val(node(t, h))) == T_ARRAY ?
|
Hash *p;
|
||||||
|
Object parent;
|
||||||
|
tag(&parent) = T_STRING;
|
||||||
|
svalue(&parent) = "parent";
|
||||||
|
h = present(t, &parent); /* assert(h >= 0); */
|
||||||
|
p = tag(ref(node(t, h))) != T_NIL && tag(val(node(t, h))) == T_ARRAY ?
|
||||||
avalue(val(node(t, h))) : NULL;
|
avalue(val(node(t, h))) : NULL;
|
||||||
} while (t != NULL && --count);
|
if (p != NULL)
|
||||||
if (count == 0)
|
{
|
||||||
lua_reportbug ("hierarchy too deep (maybe there is an inheritance loop)");
|
Object *r = lua_hashget(p, ref);
|
||||||
|
if (tag(r) != T_NIL) { count++; return r; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{ /* check "parents" field */
|
||||||
|
Hash *ps;
|
||||||
|
Object parents;
|
||||||
|
tag(&parents) = T_STRING;
|
||||||
|
svalue(&parents) = "parents";
|
||||||
|
h = present(t, &parents); /* assert(h >= 0); */
|
||||||
|
ps = tag(ref(node(t, h))) != T_NIL && tag(val(node(t, h))) == T_ARRAY ?
|
||||||
|
avalue(val(node(t, h))) : NULL;
|
||||||
|
if (ps != NULL)
|
||||||
|
{
|
||||||
|
Hash *p;
|
||||||
|
Object index;
|
||||||
|
tag(&index) = T_NUMBER;
|
||||||
|
nvalue(&index) = 1;
|
||||||
|
h = present(ps, &index);
|
||||||
|
p = tag(ref(node(ps, h))) != T_NIL && tag(val(node(ps, h))) == T_ARRAY ?
|
||||||
|
avalue(val(node(ps, h))) : NULL;
|
||||||
|
while (p != NULL)
|
||||||
|
{
|
||||||
|
Object *r = lua_hashget(p, ref);
|
||||||
|
if (tag(r) != T_NIL) { count++; return r; }
|
||||||
|
nvalue(&index)++;
|
||||||
|
h = present(ps, &index);
|
||||||
|
p = tag(ref(node(ps, h))) != T_NIL && tag(val(node(ps, h))) == T_ARRAY ?
|
||||||
|
avalue(val(node(ps, h))) : NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count++;
|
||||||
return &nil_obj;
|
return &nil_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue