From 3c9aae3a63b8f06d165fcef154cdf9da748236a0 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 26 Nov 2018 09:21:24 -0500 Subject: [PATCH] Add pretty printing support for classes. --- src/core/string.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/string.c b/src/core/string.c index 331598e2..356b485c 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -548,7 +548,22 @@ static void janet_pretty_one(struct pretty *S, Janet x) { case 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->indent += 2; if (S->depth == 0) {