summaryrefslogtreecommitdiff
path: root/src/json.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-01-31 20:24:32 +0100
committerBram Moolenaar <Bram@vim.org>2016-01-31 20:24:32 +0100
commitfb1f62691eae7c79a28b3b17a60e72ce198c71a2 (patch)
tree92456937dc3d372bf30b97df3c5b5148ea2a8243 /src/json.c
parent155500077c80cdb5d9c63996000c011b66a676bf (diff)
downloadvim-git-fb1f62691eae7c79a28b3b17a60e72ce198c71a2.tar.gz
patch 7.4.1229v7.4.1229
Problem: "eval" and "expr" channel commands don't work yet. Solution: Implement them. Update the error numbers. Also add "redraw".
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c
index 7256a8ced..a56104217 100644
--- a/src/json.c
+++ b/src/json.c
@@ -33,6 +33,33 @@ json_encode(typval_T *val)
return ga.ga_data;
}
+/*
+ * Encode ["nr", "val"] into a JSON format string.
+ * Returns NULL when out of memory.
+ */
+ char_u *
+json_encode_nr_expr(int nr, typval_T *val)
+{
+ typval_T listtv;
+ typval_T nrtv;
+ char_u *text;
+
+ nrtv.v_type = VAR_NUMBER;
+ nrtv.vval.v_number = nr;
+ if (rettv_list_alloc(&listtv) == FAIL)
+ return NULL;
+ if (list_append_tv(listtv.vval.v_list, &nrtv) == FAIL
+ || list_append_tv(listtv.vval.v_list, val) == FAIL)
+ {
+ list_unref(listtv.vval.v_list);
+ return NULL;
+ }
+
+ text = json_encode(&listtv);
+ list_unref(listtv.vval.v_list);
+ return text;
+}
+
static void
write_string(garray_T *gap, char_u *str)
{