diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-10-22 23:31:07 +0100 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-10-22 23:31:07 +0100 |
commit | 2a610da2d14583a08f016d0f985db65203d1f76f (patch) | |
tree | 5c98e3ff524ec652b4bbfce0fc6eeda1f793409f /builtin.c | |
parent | 93f80b27260743dc0ea092dfdbaf81666b853508 (diff) |
Allow the 'keys' function to take arrays.
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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])))); |