]> git.lizzy.rs Git - uwu-lang.git/blob - api/str.c
Unify value types
[uwu-lang.git] / api / str.c
1 #include <string.h>
2 #include <stdlib.h>
3 #include "str.h"
4
5 UwUVMValue uwustr_create(const char *value)
6 {
7         return (UwUVMValue) {
8                 .type = &uwustr_type,
9                 .data = strdup(value),
10         };
11 }
12
13 char *uwustr_get(UwUVMValue vm_value)
14 {
15         vm_value.type->print(vm_value.data);
16 }
17
18 static void *uwustr_copy(void *data)
19 {
20         return strdup(data);
21 }
22
23 static char *uwustr_print(void *data)
24 {
25         return strdup(data);
26 }
27
28 UwUVMType uwustr_type = {
29         .copy = &uwustr_copy,
30         .delete = &free,
31         .print = &uwustr_print,
32 };