aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/typval.c
diff options
context:
space:
mode:
authorBlaž Hrastnik <blaz@mxxn.io>2020-04-29 00:27:14 +0900
committerBlaž Hrastnik <blaz@mxxn.io>2020-04-29 11:15:49 +0900
commitc477b19bdca0cc57e08f5fb93f647767ea84dd3e (patch)
tree8a931968ac4d76fd8684e829a9030303f0fb3a36 /src/nvim/eval/typval.c
parentc7d3630e214012667e855c30cde2808a5fe59650 (diff)
downloadrneovim-c477b19bdca0cc57e08f5fb93f647767ea84dd3e.tar.gz
rneovim-c477b19bdca0cc57e08f5fb93f647767ea84dd3e.tar.bz2
rneovim-c477b19bdca0cc57e08f5fb93f647767ea84dd3e.zip
vim-patch:8.2.0084: complete item "user_data" can only be a string
Problem: Complete item "user_data" can only be a string. Solution: Accept any type of variable. (closes vim/vim#5412) https://github.com/vim/vim/commit/0892832bb6c7e322fcae8560eaad5a8140ee4a06
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r--src/nvim/eval/typval.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 773e493d0b..35130f6f40 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -1429,6 +1429,23 @@ dictitem_T *tv_dict_find(const dict_T *const d, const char *const key,
return TV_DICT_HI2DI(hi);
}
+/// Get a typval item from a dictionary and copy it into "rettv".
+///
+/// @param[in] d Dictionary to check.
+/// @param[in] key Dictionary key.
+/// @param[in] rettv Return value.
+/// @return OK in case of success or FAIL if nothing was found.
+int tv_dict_get_tv(dict_T *d, const char *const key, typval_T *rettv)
+{
+ dictitem_T *const di = tv_dict_find(d, key, -1);
+ if (di == NULL) {
+ return FAIL;
+ }
+
+ tv_copy(&di->di_tv, rettv);
+ return OK;
+}
+
/// Get a number item from a dictionary
///
/// Returns 0 if the entry does not exist.
@@ -1588,6 +1605,26 @@ int tv_dict_add_list(dict_T *const d, const char *const key,
return OK;
}
+/// Add a typval entry to dictionary.
+///
+/// @param[out] d Dictionary to add entry to.
+/// @param[in] key Key to add.
+/// @param[in] key_len Key length.
+///
+/// @return FAIL if out of memory or key already exists.
+int tv_dict_add_tv(dict_T *d, const char *key, const size_t key_len,
+ typval_T *tv)
+{
+ dictitem_T *const item = tv_dict_item_alloc_len(key, key_len);
+
+ tv_copy(tv, &item->di_tv);
+ if (tv_dict_add(d, item) == FAIL) {
+ tv_dict_item_free(item);
+ return FAIL;
+ }
+ return OK;
+}
+
/// Add a dictionary entry to dictionary
///
/// @param[out] d Dictionary to add entry to.