aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/shared.lua
diff options
context:
space:
mode:
authorTristan Konolige <tristan.konolige@gmail.com>2020-04-18 17:04:37 -0600
committerGitHub <noreply@github.com>2020-04-19 01:04:37 +0200
commitbf0f74586153dfa8d550e1cfefd83ca9e0354171 (patch)
treeef631999ea9cb6d778bf5035eb4cdabd007d17ce /runtime/lua/vim/shared.lua
parentc5466ba6ef8333183e1c43c7e762e44539fb2358 (diff)
downloadrneovim-bf0f74586153dfa8d550e1cfefd83ca9e0354171.tar.gz
rneovim-bf0f74586153dfa8d550e1cfefd83ca9e0354171.tar.bz2
rneovim-bf0f74586153dfa8d550e1cfefd83ca9e0354171.zip
lua: allow deepcopy of functions (#12136)
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r--runtime/lua/vim/shared.lua11
1 files changed, 10 insertions, 1 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index 1bf1c63fd7..d18fcfaf95 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -8,6 +8,9 @@ local vim = vim or {}
--- Returns a deep copy of the given object. Non-table objects are copied as
--- in a typical Lua assignment, whereas table objects are copied recursively.
+--- Functions are naively copied, so functions in the copied table point to the
+--- same functions as those in the input table. Userdata and threads are not
+--- copied and will throw an error.
---
--@param orig Table to copy
--@returns New table of copied keys and (nested) values.
@@ -34,10 +37,16 @@ vim.deepcopy = (function()
string = _id,
['nil'] = _id,
boolean = _id,
+ ['function'] = _id,
}
return function(orig)
- return deepcopy_funcs[type(orig)](orig)
+ local f = deepcopy_funcs[type(orig)]
+ if f then
+ return f(orig)
+ else
+ error("Cannot deepcopy object of type "..type(orig))
+ end
end
end)()