summaryrefslogtreecommitdiff
path: root/uscript/uscript.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-04-17 22:48:52 -0400
committeriamcheeseman <[email protected]>2026-04-17 22:48:52 -0400
commitf328d3b2bea11f6b89bf4b3707205ecd8496b93d (patch)
tree6d3fdb155a7d4c19332f54790b1d6ae89ae0b04f /uscript/uscript.c
parentde5d3ebdbc674bf8f1e324ee5b43c51af288a286 (diff)
microscript: add maps
Diffstat (limited to 'uscript/uscript.c')
-rw-r--r--uscript/uscript.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/uscript/uscript.c b/uscript/uscript.c
index 008bcbe..6afdb25 100644
--- a/uscript/uscript.c
+++ b/uscript/uscript.c
@@ -4,9 +4,10 @@
#include "dyn_arr.h"
#include "lex.h"
+#include "map.h"
+#include "parser.h"
#include "val.h"
#include "vm.h"
-#include "parser.h"
void core_print(int argc)
{
@@ -116,6 +117,17 @@ void arr_iter(int argc)
vm_push(wrap_cfunc(cfunc));
}
+void map_has(int argc)
+{
+ (void)argc;
+ if (vm_get(0).type != VAL_MAP)
+ us_err("map:has expected a map");
+
+ struct us_map *map = get_map(vm_get(0));
+ bool has = map_get_value(map, vm_get(1), NULL);
+ vm_push(create_bool(has));
+}
+
void us_init(void)
{
init_vm();
@@ -126,6 +138,8 @@ void us_init(void)
us_set_cfunc("arr:iter", arr_iter, 1);
us_set_cfunc("arr:add", arr_add, 2);
+
+ us_set_cfunc("map:has", map_has, 2);
}
void us_deinit(void)
@@ -159,3 +173,4 @@ void us_set_cfunc(const char *c_name, us_cfunc_sig c, int argc)
int global = declare_global(name);
set_global(global, wrap_cfunc(create_cfunc(name, c, argc)));
}
+