aboutsummaryrefslogtreecommitdiff
path: root/api/str.c
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-12-30 14:18:15 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-12-30 14:18:15 +0100
commitecc06c082036aa93f6810ec21e73610c55f5a57b (patch)
treeaff479c3bc5b39ead9f65dffb01d399b341fa4ba /api/str.c
downloaduwu-lang-ecc06c082036aa93f6810ec21e73610c55f5a57b.tar.xz
Initial commit
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);
+ }
+}