OP_COUNT expects a dictionary

This commit is contained in:
CPunch 2020-12-12 17:34:54 -06:00
parent b1facfc92f
commit d03175c9c5

View File

@ -562,17 +562,17 @@ bool cosmoV_execute(CState *state) {
} }
break; break;
} }
case OP_COUNT: { // pop 1 value off the stack & if it's an object return the ammount of active entries it has case OP_COUNT: { // pop 1 value off the stack & if it's a dictionary return the ammount of active entries it has
StkPtr temp = cosmoV_getTop(state, 0); StkPtr temp = cosmoV_getTop(state, 0);
if (!IS_OBJ(*temp) || cosmoV_readObj(*temp)->type != COBJ_OBJECT) { if (!IS_OBJ(*temp) || cosmoV_readObj(*temp)->type != COBJ_DICT) {
cosmoV_error(state, "Expected object, got %s!", cosmoV_typeStr(*temp)); cosmoV_error(state, "Expected object, got %s!", cosmoV_typeStr(*temp));
break; break;
} }
CObjObject *obj = (CObjObject*)cosmoV_readObj(*temp); CObjDict *dict = (CObjDict*)cosmoV_readObj(*temp);
cosmoV_pop(state); cosmoV_pop(state);
cosmoV_pushNumber(state, cosmoT_count(&obj->tbl)); // pushes the count onto the stack cosmoV_pushNumber(state, cosmoT_count(&dict->tbl)); // pushes the count onto the stack
break; break;
} }
case OP_CONCAT: { case OP_CONCAT: {