aboutsummaryrefslogtreecommitdiff
path: root/api/str.c
diff options
context:
space:
mode:
Diffstat (limited to 'api/str.c')
-rw-r--r--api/str.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/api/str.c b/api/str.c
new file mode 100644
index 0000000..c634fc2
--- /dev/null
+++ b/api/str.c
@@ -0,0 +1,32 @@
+#include <string.h>
+#include "../src/util.h"
+#include "str.h"
+
+UwUVMValue uwustr_create(const char *value)
+{
+ return (UwUVMValue) {
+ .type = VT_STR,
+ .value = {
+ .str_value = strdup(value),
+ },
+ };
+}
+
+char *uwustr_get(UwUVMValue vm_value)
+{
+ switch (vm_value.type) {
+ case VT_INT:
+ return asprintf_wrapper("%d", vm_value.value.int_value);
+
+ case VT_STR:
+ return strdup(vm_value.value.str_value);
+
+ case VT_REF:
+ return asprintf_wrapper("[Function reference: %p]", vm_value.value.ref_value);
+
+ case VT_NAT:
+ return vm_value.value.nat_value.type->print
+ ? vm_value.value.nat_value.type->print(vm_value.value.nat_value.data)
+ : asprintf_wrapper("[Native value: %p: %p]", vm_value.value.nat_value.data, vm_value.value.nat_value.type);
+ }
+}