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

View File

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