diff options
author | ubq323 <ubq323@ubq323.website> | 2024-07-23 17:00:56 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-07-23 17:00:56 +0100 |
commit | aa0485fe33204169724d020f9c5e3b91e558ab1e (patch) | |
tree | 909ea369aa38854fe98396c61ecab6c600533f7a /lib.c | |
parent | 726f9e814b29b4496d07c92323dc55dcf93c2a87 (diff) |
add pend builtin function
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -40,7 +40,21 @@ static Val fn_len(State *S, int nargs, Val *args) { ObjArr *a = AS_ARR(args[0]); return VAL_NUM(a->len); } - +static Val fn_pend(State *S, int nargs, Val *args) { + CHECK(nargs > 0, "need at least 1 arg to ,"); + ObjArr *a = objarr_new(S); + for (int i = 0; i < nargs; i++) { + Val v = args[i]; + if (!IS_ARR(v)) + objarr_append(S, a, v); + else { + ObjArr *b = AS_ARR(v); + for (int j = 0; j < b->len; j++) + objarr_append(S, a, b->d[j]); + } + } + return VAL_OBJ(a); +} typedef struct { @@ -55,6 +69,7 @@ static BuiltinFunc builtin_funcs[] = { { "arr", fn_arr }, { "append", fn_append }, { "len", fn_len }, + { ",", fn_pend }, { 0 }, }; |