Changes in object model: separate class objects to store vtable. Also, nicer UTF-8 display of big numbers.

This commit is contained in:
Hisham Muhammad
2012-12-05 15:12:20 +00:00
parent 2a73405cd0
commit 00b324bfc1
64 changed files with 662 additions and 566 deletions

View File

@ -26,12 +26,6 @@ typedef struct ListItem_ {
}*/
#ifdef DEBUG
char* LISTITEM_CLASS = "ListItem";
#else
#define LISTITEM_CLASS NULL
#endif
static void ListItem_delete(Object* cast) {
ListItem* this = (ListItem*)cast;
free(this->value);
@ -49,11 +43,13 @@ static void ListItem_display(Object* cast, RichString* out) {
RichString_write(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/);
}
ObjectClass ListItem_class = {
.display = ListItem_display,
.delete = ListItem_delete
};
ListItem* ListItem_new(const char* value, int key) {
ListItem* this = malloc(sizeof(ListItem));
Object_setClass(this, LISTITEM_CLASS);
((Object*)this)->display = ListItem_display;
((Object*)this)->delete = ListItem_delete;
ListItem* this = AllocThis(ListItem);
this->value = strdup(value);
this->key = key;
return this;