1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-25 07:50:27 +00:00

Add pretty printing support for classes.

This commit is contained in:
Calvin Rose 2018-11-26 09:21:24 -05:00
parent 8bfea73ee7
commit 3c9aae3a63

View File

@ -548,7 +548,22 @@ static void janet_pretty_one(struct pretty *S, Janet x) {
case JANET_TABLE: case JANET_TABLE:
{ {
int istable = janet_checktype(x, JANET_TABLE); int istable = janet_checktype(x, JANET_TABLE);
janet_buffer_push_cstring(S->buffer, istable ? "@{" : "{"); janet_buffer_push_cstring(S->buffer, istable ? "@" : "{");
/* For object-like tables, print class name */
if (istable) {
JanetTable *t = janet_unwrap_table(x);
JanetTable *proto = t->proto;
if (NULL != proto) {
Janet name = janet_table_get(proto, janet_csymbolv(":name"));
if (janet_checktype(name, JANET_SYMBOL)) {
const uint8_t *sym = janet_unwrap_symbol(name);
janet_buffer_push_bytes(S->buffer, sym, janet_string_length(sym));
}
}
janet_buffer_push_cstring(S->buffer, "{");
}
S->depth--; S->depth--;
S->indent += 2; S->indent += 2;
if (S->depth == 0) { if (S->depth == 0) {