diff options
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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 }, |