From fdc6e201533c4d2e0409dbda4ebedbf625ac0c63 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 27 Aug 2024 21:58:31 +0200 Subject: export the json module and move all json related code into json.lua In the future other modules can use the json implementation included in our lspc table. --- json.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'json.lua') diff --git a/json.lua b/json.lua index 631e7f5..876a889 100644 --- a/json.lua +++ b/json.lua @@ -1,3 +1,26 @@ +--- Find or provide a suitable json module for vis-lspc. +-- +-- @module json +local json = {} + +--- Json modules to use if they are included in LUA_PATH. +local json_impls = {'json', 'cjson', 'dkjson'} + +-- find a suitable json implementation +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 + return json + end + end +end + --[[ json.lua A compact pure-Lua JSON library. @@ -44,10 +67,6 @@ avoiding null values in your data to begin with. --]] - -local json = {} - - -- Internal functions. local function kind_of(obj) -- cgit v1.2.3