diff --git a/src/cbaselib.c b/src/cbaselib.c index 5bf7838..51039a7 100644 --- a/src/cbaselib.c +++ b/src/cbaselib.c @@ -20,12 +20,12 @@ CValue cosmoB_print(CState *state, int nargs, CValue *args) { return cosmoV_newNil(); // print doesn't return any args } -CValue cosmoB_dsetMeta(CState *state, int nargs, CValue *args) { +CValue cosmoB_dsetProto(CState *state, int nargs, CValue *args) { if (nargs == 2) { - CObjObject *obj = cosmoV_readObject(args[0]); // object to set meta too - CObjObject *meta = cosmoV_readObject(args[1]); + CObjObject *obj = cosmoV_readObject(args[0]); // object to set proto too + CObjObject *proto = cosmoV_readObject(args[1]); - obj->meta = meta; // boom done + obj->proto = proto; // boom done } else { cosmoV_error(state, "Expected 2 parameters, got %d!", nargs); } @@ -33,20 +33,20 @@ CValue cosmoB_dsetMeta(CState *state, int nargs, CValue *args) { return cosmoV_newNil(); // nothing } -CValue cosmoB_dgetMeta(CState *state, int nargs, CValue *args) { +CValue cosmoB_dgetProto(CState *state, int nargs, CValue *args) { if (nargs != 1) { cosmoV_error(state, "Expected 1 parameter, got %d!", nargs); } - return cosmoV_newObj(cosmoV_readObject(args[0])->meta); // just return the meta + return cosmoV_newObj(cosmoV_readObject(args[0])->proto); // just return the proto } void cosmoB_loadDebug(CState *state) { - cosmoV_pushString(state, "getMeta"); - cosmoV_pushCFunction(state, cosmoB_dgetMeta); - cosmoV_pushString(state, "setMeta"); - cosmoV_pushCFunction(state, cosmoB_dsetMeta); + cosmoV_pushString(state, "getProto"); + cosmoV_pushCFunction(state, cosmoB_dgetProto); + cosmoV_pushString(state, "setProto"); + cosmoV_pushCFunction(state, cosmoB_dsetProto); cosmoV_pushObject(state, 2); - state->metaObj = cosmoV_readObject(*cosmoV_pop(state)); + state->protoObj = cosmoV_readObject(*cosmoV_pop(state)); } \ No newline at end of file diff --git a/src/cmem.c b/src/cmem.c index 706caf5..db4a6fb 100644 --- a/src/cmem.c +++ b/src/cmem.c @@ -88,7 +88,7 @@ void blackenObject(CState *state, CObj *obj) { // mark everything this object is keeping track of CObjObject *cobj = (CObjObject*)obj; markTable(state, &cobj->tbl); - markObject(state, (CObj*)cobj->meta); + markObject(state, (CObj*)cobj->proto); break; } case COBJ_UPVALUE: { @@ -214,8 +214,8 @@ void markRoots(CState *state) { for (int i = 0; i < INTERNALSTRING_MAX; i++) markObject(state, (CObj*)state->internalStrings[i]); - // mark our meta object - markObject(state, (CObj*)state->metaObj); + // mark our proto object + markObject(state, (CObj*)state->protoObj); traceGrays(state); } diff --git a/src/cobj.c b/src/cobj.c index ea7df1b..fe55a13 100644 --- a/src/cobj.c +++ b/src/cobj.c @@ -94,7 +94,7 @@ bool cosmoO_equal(CObj* obj1, CObj* obj2) { CObjObject *cosmoO_newObject(CState *state) { CObjObject *obj = (CObjObject*)cosmoO_allocateBase(state, sizeof(CObjObject), COBJ_OBJECT); - obj->meta = state->metaObj; + obj->proto = state->protoObj; obj->user = NULL; // reserved for C API cosmoV_pushValue(state, cosmoV_newObj(obj)); // so our GC can keep track of it cosmoT_initTable(state, &obj->tbl, ARRAY_START); @@ -204,8 +204,8 @@ 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) && object->meta != NULL) { // if the field doesn't exist in the object, check the meta - return cosmoO_getObject(state, object->meta, key, val); + if (!cosmoT_get(&object->tbl, key, val) && object->proto != NULL) { // if the field doesn't exist in the object, check the proto + return cosmoO_getObject(state, object->proto, key, val); } return true; diff --git a/src/cobj.h b/src/cobj.h index ddd3a56..4aaf004 100644 --- a/src/cobj.h +++ b/src/cobj.h @@ -40,7 +40,7 @@ typedef struct CObjObject { CommonHeader; // "is a" CObj CTable tbl; void *user; // userdata (NULL by default) - struct CObjObject *meta; // metaobject, describes the behavior of the object + struct CObjObject *proto; // protoobject, describes the behavior of the object } CObjObject; typedef struct CObjFunction { diff --git a/src/cstate.c b/src/cstate.c index 929dc7c..306c100 100644 --- a/src/cstate.c +++ b/src/cstate.c @@ -30,7 +30,7 @@ CState *cosmoV_newState() { state->top = state->stack; state->frameCount = 0; state->openUpvalues = NULL; - state->metaObj = NULL; + state->protoObj = NULL; cosmoT_initTable(state, &state->strings, 8); // init string table cosmoT_initTable(state, &state->globals, 8); // init global table diff --git a/src/cstate.h b/src/cstate.h index ad70f4d..49fc2e2 100644 --- a/src/cstate.h +++ b/src/cstate.h @@ -38,7 +38,7 @@ typedef struct CState { int frameCount; CObjString *internalStrings[INTERNALSTRING_MAX]; // strings used internally by the VM, eg. __init - CObjObject *metaObj; // start met obj for all objects (NULL by default) + CObjObject *protoObj; // start met obj for all objects (NULL by default) } CState; COSMO_API CState *cosmoV_newState(); diff --git a/src/cvm.c b/src/cvm.c index 2e4f28e..155c1bf 100644 --- a/src/cvm.c +++ b/src/cvm.c @@ -184,14 +184,14 @@ COSMOVMRESULT cosmoV_call(CState *state, int args) { break; } case COBJ_OBJECT: { - CObjObject *metaObj = (CObjObject*)val->val.obj; + CObjObject *protoObj = (CObjObject*)val->val.obj; CObjObject *newObj = cosmoO_newObject(state); - newObj->meta = metaObj; + newObj->proto = protoObj; *val = cosmoV_newObj(newObj); CValue ret; // check if they defined an initalizer - if (cosmoV_getObject(state, metaObj, cosmoV_newObj(state->internalStrings[INTERNALSTRING_INIT]), &ret) && IS_METHOD(ret)) { + if (cosmoV_getObject(state, protoObj, cosmoV_newObj(state->internalStrings[INTERNALSTRING_INIT]), &ret) && IS_METHOD(ret)) { callMethod(state, cosmoV_readMethod(ret), args); cosmoV_pop(state); } else {