aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2021-12-27 20:46:39 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2021-12-27 20:46:39 +0100
commit655dafe59e35a2bc7bd0785c342c47e3ea860c70 (patch)
tree58f04d1e2c1e743ea93ea7b7a5e902d2de52bb55 /init.lua
parent4d8420d30d47d738221845bb95759e9420cdb788 (diff)
downloadvis-lspc-655dafe59e35a2bc7bd0785c342c47e3ea860c70.tar.gz
vis-lspc-655dafe59e35a2bc7bd0785c342c47e3ea860c70.zip
try multiple json implementations
We try 'json', 'cjson' and 'dkjson' in that order before using our bundled fallback implementation.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua28
1 files changed, 18 insertions, 10 deletions
diff --git a/init.lua b/init.lua
index c8e0f04..e2dc90e 100644
--- a/init.lua
+++ b/init.lua
@@ -11,19 +11,27 @@ if not vis.communicate then
return {}
end
-local function load_fallback_json()
- return dofile(source_path .. 'json.lua')
-end
+local json
+local json_impls = {'json', 'cjson', 'dkjson'}
-- find a suitable json implementation
-local json
-if vis:module_exist('json') then
- json = require('json')
- if not json.encode or not json.decode then
- json = load_fallback_json()
+for _, json_impl in ipairs(json_impls) do
+ if vis:module_exist(json_impl) then
+ json = require(json_impl)
+ if not json.encode or not json.decode then
+ json = nil
+ end
+
+ -- found a usable json implementation
+ if json then
+ break
+ end
end
-else
- json = load_fallback_json()
+end
+
+-- We found no suitable implementation in json_impls -> use our fallback
+if not json then
+ json = dofile(source_path .. 'json.lua')
end
local jsonrpc = {}