Minor CObj* refactor, added cosmoO_lock and cosmoO_unlock

- cosmoO_getUser* and cosmoO_setUser* no longer take the `CState*` argument
- if a set is performed on a locked object an error is thrown
This commit is contained in:
2021-02-06 18:51:47 -06:00
parent 8151cde6f3
commit 5faa40bdef
4 changed files with 64 additions and 24 deletions

View File

@@ -223,6 +223,7 @@ COSMO_API void cosmoB_loadObjLib(CState *state) {
// make the object and set the protoobject for all runtime-allocated objects
CObjObject *obj = cosmoV_makeObject(state, i + 2); // + 2 for the getter/setter tables
cosmoO_lock(obj); // lock so pesky people don't mess with it (feel free to remove if debugging)
cosmoV_registerProtoObject(state, COBJ_OBJECT, obj);
// register "object" to the global table
@@ -431,6 +432,7 @@ void cosmoB_loadStrLib(CState *state) {
// make the object and set the protoobject for all strings
CObjObject *obj = cosmoV_makeObject(state, i);
cosmoO_lock(obj); // lock so pesky people don't mess with it (feel free to remove if debugging)
cosmoV_registerProtoObject(state, COBJ_STRING, obj);
// register "string" to the global table