some toString functions
This commit is contained in:
parent
70807ed22b
commit
7ab2389632
@ -16,7 +16,30 @@ kt_define(u32, NULL, __toString_u32);
|
||||
kt_define(i64, NULL, __toString_i64);
|
||||
kt_define(u64, NULL, __toString_u64);
|
||||
|
||||
kt_define(ktDescriptor, NULL, NULL);
|
||||
|
||||
char* ktDescriptor_toString(ktDescriptor* d){
|
||||
const char* n="null";
|
||||
char *s0 = toString_u64(d->id, 0,0);
|
||||
char *s1 = toString_u64(d->size, 0,0);
|
||||
char *s2 = d->toString ? toString_hex(d->toString, sizeof(void*), 0,1,0) : n;
|
||||
char *s3 = d->freeMembers ? toString_hex(d->freeMembers, sizeof(void*), 0,1,0) : n;
|
||||
char *rez=cptr_concat("ktDescriptor {"
|
||||
" name:", d->name,
|
||||
" id:",s0,
|
||||
" size:",s1,
|
||||
" toString:",s2,
|
||||
" freeMembers:",s3,
|
||||
" }");
|
||||
free(s0);
|
||||
free(s1);
|
||||
if(s2!=n) free(s2);
|
||||
if(s3!=n) free(s3);
|
||||
return rez;
|
||||
}
|
||||
|
||||
char* _ktDescriptor_toString(void* _d, u32 fmt) { return ktDescriptor_toString(_d); }
|
||||
|
||||
kt_define(ktDescriptor, NULL, _ktDescriptor_toString);
|
||||
|
||||
typedef ktDescriptor* ktDescriptor_Ptr;
|
||||
|
||||
|
||||
@ -23,6 +23,8 @@ void kt_endInit();
|
||||
/// @param id id of registered type
|
||||
ktDescriptor* ktDescriptor_get(ktid id);
|
||||
|
||||
char* ktDescriptor_toString(ktDescriptor* d);
|
||||
|
||||
// call it to free heap-allocated ktDescriptors array
|
||||
void kt_free();
|
||||
|
||||
|
||||
@ -179,3 +179,33 @@ void kprint_setColor(kp_fmt f){
|
||||
StringBuilder_append_char(strb, ' ');
|
||||
StringBuilder_append_char(strb, ']');
|
||||
} */
|
||||
|
||||
static const char* _kp_colorNames[16]={
|
||||
"black",
|
||||
"dark_red",
|
||||
"dark_green",
|
||||
"dark_yellow",
|
||||
"dark_blue",
|
||||
"dark_magenta",
|
||||
"dark_cyan",
|
||||
"gray",
|
||||
"dark_gray",
|
||||
"red",
|
||||
"green",
|
||||
"yellow",
|
||||
"blue",
|
||||
"magenta",
|
||||
"cyan",
|
||||
"white"
|
||||
};
|
||||
|
||||
char* kp_bgColor_toString(kp_fmt c){
|
||||
u32 color_index=(c&0x00f00000)>>20;
|
||||
if(color_index>15) throw(ERR_WRONGINDEX);
|
||||
return _kp_colorNames[color_index];
|
||||
}
|
||||
char* kp_fgColor_toString(kp_fmt c){
|
||||
u32 color_index=(c&0x00f00000)>>24;
|
||||
if(color_index>15) throw(ERR_WRONGINDEX);
|
||||
return _kp_colorNames[color_index];
|
||||
}
|
||||
|
||||
@ -81,6 +81,9 @@ PACKED_ENUM(kp_bgColor,
|
||||
kp_bgWhite = 0x40f00000
|
||||
)
|
||||
|
||||
char* kp_bgColor_toString(kp_bgColor c);
|
||||
char* kp_fgColor_toString(kp_fgColor c);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user