diff options
author | ubq323 <ubq323@ubq323.website> | 2024-08-17 21:31:12 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-08-17 21:31:17 +0100 |
commit | b90e206280859d2069c5ce02faf39c1a70202a08 (patch) | |
tree | 1c69b6b65da3dae8de6ada6c8caf73b0cf691add | |
parent | bc68a6aab9de8a90e07e7eb37283cea194dbe0ae (diff) |
add schars-ascii function
-rw-r--r-- | lib.c | 10 | ||||
-rw-r--r-- | tests/schars_ascii.bth | 1 | ||||
-rw-r--r-- | tests/schars_ascii.out | 2 |
3 files changed, 13 insertions, 0 deletions
@@ -136,6 +136,15 @@ static Val fn_ssplit(State *S, int nargs, Val *args) { return VAL_OBJ(out); } +static Val fn_schars_ascii(State *S, int nargs, Val *args) { + CHECK(nargs==1, "need exactly 1 args for schars-ascii"); + CHECK(IS_STRING(args[0]), "need string arg for schars-ascii"); + ObjString *s = AS_STRING(args[0]); + ObjArr *a = objarr_new(S); + for (int i = 0; i < s->len; i++) + objarr_append(S, a, VAL_OBJ(objstring_copy(S, &s->d[i], 1))); + return VAL_OBJ(a); +} // math static Val fn_sin(State *S, int nargs, Val *args) { @@ -188,6 +197,7 @@ static BuiltinFunc builtin_funcs[] = { { ",", fn_pend }, { "s,", fn_spend }, { "ssplit", fn_ssplit }, + { "schars-ascii", fn_schars_ascii }, { "sin", fn_sin }, { "cos", fn_cos }, diff --git a/tests/schars_ascii.bth b/tests/schars_ascii.bth new file mode 100644 index 0000000..402017b --- /dev/null +++ b/tests/schars_ascii.bth @@ -0,0 +1 @@ +(say (schars-ascii "hello world\n")) diff --git a/tests/schars_ascii.out b/tests/schars_ascii.out new file mode 100644 index 0000000..b00b046 --- /dev/null +++ b/tests/schars_ascii.out @@ -0,0 +1,2 @@ +[h e l l o w o r l d +] |