summaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2012-10-22 23:31:07 +0100
committerStephen Dolan <mu@netsoc.tcd.ie>2012-10-22 23:31:07 +0100
commit2a610da2d14583a08f016d0f985db65203d1f76f (patch)
tree5c98e3ff524ec652b4bbfce0fc6eeda1f793409f /builtin.c
parent93f80b27260743dc0ea092dfdbaf81666b853508 (diff)
Allow the 'keys' function to take arrays.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index c3d6af19..f184ff7f 100644
--- a/builtin.c
+++ b/builtin.c
@@ -228,6 +228,12 @@ static void f_keys(jv input[], jv output[]) {
}
free(keys);
jv_free(input[0]);
+ } else if (jv_get_kind(input[0]) == JV_KIND_ARRAY) {
+ int n = jv_array_length(input[0]);
+ output[0] = jv_array();
+ for (int i=0; i<n; i++){
+ output[0] = jv_array_set(output[0], i, jv_number(i));
+ }
} else {
output[0] = jv_invalid_with_msg(jv_string_fmt("'keys' only supports object, not %s",
jv_kind_name(jv_get_kind(input[0]))));