From c5e4305ef888d80092dd4e123f7fee8e19f99537 Mon Sep 17 00:00:00 2001 From: CPunch Date: Fri, 25 Aug 2023 21:28:41 -0500 Subject: [PATCH] refactored cobj.c:printObject() uses obj type strings from cosmoO_typeStr --- src/cobj.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/cobj.c b/src/cobj.c index 75afbe8..15aed52 100644 --- a/src/cobj.c +++ b/src/cobj.c @@ -698,60 +698,61 @@ int cosmoO_count(CState *state, CObj *obj) void printObject(CObj *o) { + printf("%s ", cosmoO_typeStr(o)); switch (o->type) { case COBJ_STRING: { CObjString *objStr = (CObjString *)o; - printf(" \"%.*s\"", objStr->length, objStr->str); + printf("\"%.*s\"", objStr->length, objStr->str); break; } case COBJ_OBJECT: { - printf(" %p", (void *)o); + printf("%p", (void *)o); break; } case COBJ_TABLE: { CObjTable *tbl = (CObjTable *)o; - printf(" %p", (void *)tbl); + printf("%p", (void *)tbl); break; } case COBJ_FUNCTION: { CObjFunction *objFunc = (CObjFunction *)o; if (objFunc->name != NULL) - printf(" %.*s", objFunc->name->length, objFunc->name->str); + printf("%.*s", objFunc->name->length, objFunc->name->str); else - printf(" %s", UNNAMEDCHUNK); + printf("%s", UNNAMEDCHUNK); break; } case COBJ_CFUNCTION: { CObjCFunction *objCFunc = (CObjCFunction *)o; - printf(" %p", (void *)objCFunc->cfunc); + printf("%p", (void *)objCFunc->cfunc); break; } case COBJ_ERROR: { CObjError *err = (CObjError *)o; - printf(" %p -> ", (void *)o); + printf("%p -> ", (void *)o); printValue(err->err); break; } case COBJ_METHOD: { CObjMethod *method = (CObjMethod *)o; - printf(" %p -> ", (void *)method); + printf("%p -> ", (void *)method); printValue(method->func); break; } case COBJ_CLOSURE: { CObjClosure *closure = (CObjClosure *)o; - printf(" %p -> ", (void *)closure); + printf("%p -> ", (void *)closure); printObject((CObj *)closure->function); // just print the function break; } case COBJ_UPVALUE: { CObjUpval *upval = (CObjUpval *)o; - printf(" %p -> ", (void *)upval->val); + printf("%p -> ", (void *)upval->val); printValue(*upval->val); break; } default: - printf("", (void *)o); + printf("%p", (void *)o); } }