diff options
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -21,6 +21,26 @@ static Val fn_say(State *S, int nargs, Val *args) { } +// lists +static Val fn_arr(State *S, int nargs, Val *args) { + CHECK(nargs == 0, "need 0 args to arr"); + ObjArr *o = objarr_new(S); + return VAL_OBJ(o); +} +static Val fn_append(State *S, int nargs, Val *args) { + CHECK(nargs == 2, "need 2 args to append"); + CHECK(IS_ARR(args[0]), "can only append to arr"); + ObjArr *a = AS_ARR(args[0]); + objarr_append(S, a, args[1]); + 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"); + ObjArr *a = AS_ARR(args[0]); + return VAL_NUM(a->len); +} + typedef struct { @@ -31,6 +51,10 @@ static BuiltinFunc builtin_funcs[] = { { "clock", fn_clock }, { "say", fn_say }, { "write", fn_write }, + + { "arr", fn_arr }, + { "append", fn_append }, + { "len", fn_len }, { 0 }, }; |