1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-24 12:17:41 +00:00

Allow iterating through the properties of core abstract types.

This commit is contained in:
Calvin Rose
2021-01-11 23:14:07 -06:00
parent dfbdd17dce
commit 61cca10cf6
10 changed files with 161 additions and 20 deletions

View File

@@ -147,6 +147,23 @@ int janet_getmethod(const uint8_t *method, const JanetMethod *methods, Janet *ou
return 0;
}
Janet janet_nextmethod(const JanetMethod *methods, Janet key) {
if (!janet_checktype(key, JANET_NIL)) {
while (methods->name) {
if (janet_keyeq(key, methods->name)) {
methods++;
break;
}
methods++;
}
}
if (methods->name) {
return janet_ckeywordv(methods->name);
} else {
return janet_wrap_nil();
}
}
DEFINE_GETTER(number, NUMBER, double)
DEFINE_GETTER(array, ARRAY, JanetArray *)
DEFINE_GETTER(tuple, TUPLE, const Janet *)