mirror of
https://github.com/CPunch/Cosmo.git
synced 2026-01-03 06:00:43 +00:00
CObjMethod refactor
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include "cobj.h"
|
||||
#include "cmem.h"
|
||||
|
||||
void cosmoB_loadlibrary(CState *state) {
|
||||
void cosmoB_loadLibrary(CState *state) {
|
||||
cosmoM_freezeGC(state);
|
||||
cosmoV_register(state, "print", cosmoV_newObj(cosmoO_newCFunction(state, cosmoB_print)));
|
||||
cosmoM_unfreezeGC(state);
|
||||
@@ -18,4 +18,28 @@ CValue cosmoB_print(CState *state, int nargs, CValue *args) {
|
||||
printf("\n");
|
||||
|
||||
return cosmoV_newNil(); // print doesn't return any args
|
||||
}
|
||||
|
||||
CValue cosmoB_dsetMeta(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]);
|
||||
|
||||
obj->meta = meta; // boom done
|
||||
}
|
||||
|
||||
return cosmoV_newNil(); // nothing
|
||||
}
|
||||
CValue cosmoB_dgetMeta(CState *state, int nargs, CValue *args) {
|
||||
return cosmoV_newObj(cosmoV_readObject(args[0])->meta); // just return the meta
|
||||
}
|
||||
|
||||
void cosmoB_loadDebug(CState *state) {
|
||||
cosmoV_pushString(state, "getMeta");
|
||||
cosmoV_pushCFunction(state, cosmoB_dgetMeta);
|
||||
cosmoV_pushString(state, "setMeta");
|
||||
cosmoV_pushCFunction(state, cosmoB_dsetMeta);
|
||||
cosmoV_pushObject(state, 2);
|
||||
|
||||
state->metaObj = cosmoV_readObject(*cosmoV_pop(state));
|
||||
}
|
||||
Reference in New Issue
Block a user