aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lua/stdlib.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-09-27 18:16:58 +0200
committerGitHub <noreply@github.com>2022-09-27 18:16:58 +0200
commitd84abfeb1d9f0dbd03c6089a94756f2a8468a612 (patch)
tree4d194e67ecc3b626ff703bd0b13042fb6e4b57c9 /src/nvim/lua/stdlib.c
parentf46060c4cbc1efe100019075214def53fe4d47b3 (diff)
parentc7d30c152d1639523d05154e245ea60ed9a51a2b (diff)
downloadrneovim-d84abfeb1d9f0dbd03c6089a94756f2a8468a612.tar.gz
rneovim-d84abfeb1d9f0dbd03c6089a94756f2a8468a612.tar.bz2
rneovim-d84abfeb1d9f0dbd03c6089a94756f2a8468a612.zip
Merge pull request #15373 from smolck/lua-notify-dictwatcher
fix(nvim): notify dict watchers on nvim_set_var and vim.g setter
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r--src/nvim/lua/stdlib.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c
index 9b1890403e..498f956ed9 100644
--- a/src/nvim/lua/stdlib.c
+++ b/src/nvim/lua/stdlib.c
@@ -369,12 +369,19 @@ int nlua_setvar(lua_State *lstate)
return 0;
}
+ bool watched = tv_dict_is_watched(dict);
+
if (del) {
// Delete the key
if (di == NULL) {
// Doesn't exist, nothing to do
return 0;
} else {
+ // Notify watchers
+ if (watched) {
+ tv_dict_watcher_notify(dict, key.data, NULL, &di->di_tv);
+ }
+
// Delete the entry
tv_dict_item_remove(dict, di);
}
@@ -388,17 +395,29 @@ int nlua_setvar(lua_State *lstate)
return luaL_error(lstate, "Couldn't convert lua value");
}
+ typval_T oldtv = TV_INITIAL_VALUE;
+
if (di == NULL) {
// Need to create an entry
di = tv_dict_item_alloc_len(key.data, key.size);
tv_dict_add(dict, di);
} else {
+ if (watched) {
+ tv_copy(&di->di_tv, &oldtv);
+ }
// Clear the old value
tv_clear(&di->di_tv);
}
// Update the value
tv_copy(&tv, &di->di_tv);
+
+ // Notify watchers
+ if (watched) {
+ tv_dict_watcher_notify(dict, key.data, &tv, &oldtv);
+ tv_clear(&oldtv);
+ }
+
// Clear the temporary variable
tv_clear(&tv);
}