feat: variant now uses mirror and drop to manage objects

main
Sara 2024-01-25 14:14:01 +01:00
parent 640ed84c1d
commit cccec929bc
2 changed files with 11 additions and 4 deletions

View File

@ -1,8 +1,10 @@
#include "variant.h"
#include "debug.h"
#include "ctype.h"
#include "mirror.h"
#include "string.h"
#include "strutil.h"
#include "drop.h"
#include "debug.h"
Variant variant_from_str(const char* str) {
size_t length = strlen(str);
@ -54,8 +56,12 @@ void destroy_contained(Variant* self) {
self->as_string = NULL;
break;
case Variant_Object:
free(self->as_object);
self->as_object = NULL;
if(TC_MIRRORS(self->as_object, Drop)) {
Drop drop = TC_CAST(self->as_object, Drop);
drop.tc->drop(drop.data);
}
self->as_object.data = NULL;
self->as_object.tc = NULL;
break;
}
}

View File

@ -2,6 +2,7 @@
#define _fencer_variant_h
#include "vmath.h"
#include "mirror.h"
typedef enum VariantType {
Variant_Undefined = 0x0,
@ -17,7 +18,7 @@ typedef struct Variant {
union {
double as_number;
Vector as_vector;
void* as_object;
Mirror as_object;
char* as_string;
};
} Variant;