diff options
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 }, }; |