summaryrefslogtreecommitdiff
path: root/lib.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-08-17 21:29:40 +0100
committerubq323 <ubq323@ubq323.website>2024-08-17 21:29:52 +0100
commitfaba0abf74dcdab3a4957bd8f13afa3c4dd19950 (patch)
tree5dc4f0110ffe204e83fc9db94f52d0803416d25a /lib.c
parentfc5fb73c08d563ae441f785276f1304da7538fea (diff)
add delete! and objarr_delete
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index b4f5015..f4e9758 100644
--- a/lib.c
+++ b/lib.c
@@ -68,6 +68,15 @@ static Val fn_append(State *S, int nargs, Val *args) {
objarr_append(S, a, args[1]);
return args[0];
}
+static Val fn_delete(State *S, int nargs, Val *args) {
+ CHECK(nargs == 2, "need 2 args to delete!");
+ CHECK(IS_ARR(args[0]), "can only delete from arr");
+ CHECK(IS_NUM(args[1]), "can only delete using num index");
+ ObjArr *a = AS_ARR(args[0]);
+ size_t ix = (size_t)AS_NUM(args[1]);
+ objarr_delete(S, a, ix);
+ return args[0];
+}
static Val fn_len(State *S, int nargs, Val *args) {
CHECK(nargs == 1, "need 1 arg to len");
CHECK(IS_ARR(args[0]), "can only take length of arr");
@@ -174,6 +183,7 @@ static BuiltinFunc builtin_funcs[] = {
{ "arr", fn_arr },
{ "append!", fn_append },
+ { "delete!", fn_delete },
{ "#", fn_len },
{ ",", fn_pend },
{ "s,", fn_spend },