From faba0abf74dcdab3a4957bd8f13afa3c4dd19950 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 17 Aug 2024 21:29:40 +0100 Subject: add delete! and objarr_delete --- lib.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib.c') 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 }, -- cgit v1.2.3