fixed __index

This commit is contained in:
2020-11-20 15:10:49 -06:00
parent 85e7deae7b
commit 6d45c0a676
2 changed files with 33 additions and 3 deletions

View File

@@ -206,7 +206,11 @@ CObjString *cosmoO_allocateString(CState *state, const char *str, size_t sz, uin
bool cosmoO_getObject(CState *state, CObjObject *object, CValue key, CValue *val) {
if (!cosmoT_get(&object->tbl, key, val)) { // if the field doesn't exist in the object, check the proto
if (object->proto != NULL) { // sanity check
// first though, check for __index, if that exists, call it
// first though, check for a member of the proto object, if it fails then lookup __index
if (cosmoO_getObject(state, object->proto, key, val))
return true;
// then check for __index, if that exists, call it
if (cosmoO_getIString(state, object->proto, ISTRING_INDEX, val)) {
cosmoV_pushValue(state, *val); // push function
cosmoV_pushValue(state, cosmoV_newObj(object)); // push object
@@ -215,8 +219,6 @@ bool cosmoO_getObject(CState *state, CObjObject *object, CValue key, CValue *val
*val = *cosmoV_pop(state); // set value to the return value of __index
return true;
}
return cosmoO_getObject(state, object->proto, key, val);
}
return false; // no protoobject to check against