diff options
| author | iamcheeseman <[email protected]> | 2026-04-14 12:48:43 -0400 |
|---|---|---|
| committer | iamcheeseman <[email protected]> | 2026-04-14 12:48:43 -0400 |
| commit | cfa04f1cd06a7024aca7dba96f930ba130b0f9b4 (patch) | |
| tree | 4f3148ddf51c2111b9e3e387ee24f0b2f118ee53 /uscript | |
| parent | 968a7292f0b88f9485f4511e48acbee36cf71036 (diff) | |
microscript: add core:log and core:len
Diffstat (limited to 'uscript')
| -rw-r--r-- | uscript/uscript.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/uscript/uscript.c b/uscript/uscript.c index ee02f15..a7e3ca1 100644 --- a/uscript/uscript.c +++ b/uscript/uscript.c @@ -8,9 +8,40 @@ #include "vm.h" #include "parser.h" +void core_print(int argc) +{ + (void)argc; + + char *str = val_to_str(vm_peek(), NULL); + olog(str); + mem_free(str); + + vm_push(create_zilch()); +} + +void core_len(int argc) +{ + (void)argc; + + struct us_val val = vm_peek(); + switch (val.type) { + case VAL_ARR: + vm_push(create_num(da_len(get_arr(val)->e))); + break; + case VAL_STR: + vm_push(create_num(get_str(val)->len)); + break; + default: + vm_push(create_zilch()); + } +} + void us_init(void) { init_vm(); + + us_set_cfunc("core:len", core_len, 1); + us_set_cfunc("core:log", core_print, 1); } void us_deinit(void) |
