diff src/json.c @ 7864:6b0891de44a9 v7.4.1229

commit https://github.com/vim/vim/commit/fb1f62691eae7c79a28b3b17a60e72ce198c71a2 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 31 20:24:32 2016 +0100 patch 7.4.1229 Problem: "eval" and "expr" channel commands don't work yet. Solution: Implement them. Update the error numbers. Also add "redraw".
author Christian Brabandt <cb@256bit.org>
date Sun, 31 Jan 2016 20:30:04 +0100
parents 6f81cf49da14
children 17e6ff1a74f1
line wrap: on
line diff
--- 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)
 {