mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-12-04 22:46:31 +00:00
Compare commits
2 Commits
7f5e3ae8dc
...
a337e26229
Author | SHA1 | Date | |
---|---|---|---|
a337e26229 | |||
b7bb0773b1 |
@ -182,6 +182,32 @@ int cosmoB_ogetProto(CState *state, int nargs, CValue *args)
|
|||||||
return 1; // 1 result
|
return 1; // 1 result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cosmoB_ogetKeys(CState *state, int nargs, CValue *args)
|
||||||
|
{
|
||||||
|
if (nargs != 1)
|
||||||
|
cosmoV_error(state, "Expected 1 argument, got %d!", nargs);
|
||||||
|
|
||||||
|
if (!IS_OBJECT(args[0])) {
|
||||||
|
cosmoV_typeError(state, "object.__keys", "<object>", "%s", cosmoV_typeStr(args[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// push keys
|
||||||
|
CObjObject *obj = cosmoV_readObject(args[0]);
|
||||||
|
int cap = cosmoT_getCapacity(&obj->tbl);
|
||||||
|
int indx = 0;
|
||||||
|
for (int i = 0; i < cap; i++) {
|
||||||
|
CTableEntry *entry = &obj->tbl.table[i];
|
||||||
|
if (IS_NIL(entry->key))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
cosmoV_pushNumber(state, indx++);
|
||||||
|
cosmoV_pushValue(state, entry->key);
|
||||||
|
}
|
||||||
|
|
||||||
|
cosmoV_makeTable(state, indx);
|
||||||
|
return 1; // 1 result
|
||||||
|
}
|
||||||
|
|
||||||
int cosmoB_oisChild(CState *state, int nargs, CValue *args)
|
int cosmoB_oisChild(CState *state, int nargs, CValue *args)
|
||||||
{
|
{
|
||||||
if (nargs != 2) {
|
if (nargs != 2) {
|
||||||
@ -203,9 +229,9 @@ int cosmoB_oisChild(CState *state, int nargs, CValue *args)
|
|||||||
|
|
||||||
COSMO_API void cosmoB_loadObjLib(CState *state)
|
COSMO_API void cosmoB_loadObjLib(CState *state)
|
||||||
{
|
{
|
||||||
const char *identifiers[] = {"ischild"};
|
const char *identifiers[] = {"ischild", "keys"};
|
||||||
|
|
||||||
CosmoCFunction objLib[] = {cosmoB_oisChild};
|
CosmoCFunction objLib[] = {cosmoB_oisChild, cosmoB_ogetKeys};
|
||||||
|
|
||||||
// make object library object
|
// make object library object
|
||||||
cosmoV_pushString(state, "object");
|
cosmoV_pushString(state, "object");
|
||||||
@ -213,11 +239,11 @@ COSMO_API void cosmoB_loadObjLib(CState *state)
|
|||||||
// make __getter object for debug proto
|
// make __getter object for debug proto
|
||||||
cosmoV_pushString(state, "__getter");
|
cosmoV_pushString(state, "__getter");
|
||||||
|
|
||||||
// key & value pair
|
// key & value pairs
|
||||||
cosmoV_pushString(state, "__proto"); // key
|
cosmoV_pushString(state, "__proto"); // key
|
||||||
cosmoV_pushCFunction(state, cosmoB_ogetProto); // value
|
cosmoV_pushCFunction(state, cosmoB_ogetProto); // value
|
||||||
|
|
||||||
cosmoV_makeTable(state, 1);
|
cosmoV_makeTable(state, 2);
|
||||||
|
|
||||||
// make __setter table
|
// make __setter table
|
||||||
cosmoV_pushString(state, "__setter");
|
cosmoV_pushString(state, "__setter");
|
||||||
|
@ -592,8 +592,6 @@ static void group(CParseState *pstate, bool canAssign, Precedence prec)
|
|||||||
consume(pstate, TOKEN_RIGHT_PAREN, "Expected ')'");
|
consume(pstate, TOKEN_RIGHT_PAREN, "Expected ')'");
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WRITE_GLOBAL_OP(pstate, op, arg)
|
|
||||||
|
|
||||||
static void _etterAB(CParseState *pstate, uint8_t a, int b, bool isGlobal)
|
static void _etterAB(CParseState *pstate, uint8_t a, int b, bool isGlobal)
|
||||||
{
|
{
|
||||||
writeu8(pstate, a);
|
writeu8(pstate, a);
|
||||||
|
Loading…
Reference in New Issue
Block a user