diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2024-08-19 17:38:50 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2024-08-19 17:38:50 +0800 |
commit | 1a9fedaba146e90435debf3128c78aec74731b15 (patch) | |
tree | 3a5ef06267d8f32b196a1b5f0d44adc9b0520014 | |
parent | 7d2156d15be3f9d9d56bc092f58f1df0431c87c3 (diff) | |
download | lua-language-server-1a9fedaba146e90435debf3128c78aec74731b15.zip |
同步utility
-rw-r--r-- | script/utility.lua | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/script/utility.lua b/script/utility.lua index 936726f9..861c66ac 100644 --- a/script/utility.lua +++ b/script/utility.lua @@ -693,6 +693,21 @@ function m.sortCallbackOfIndex(arr) end end +---@param datas any[] +---@param scores integer[] +---@return SortByScoreCallback +function m.sortCallbackOfScore(datas, scores) + local map = {} + for i = 1, #datas do + local data = datas[i] + local score = scores[i] + map[data] = score + end + return function (v) + return map[v] + end +end + ---裁剪字符串 ---@param str string ---@param mode? '"left"'|'"right"' @@ -851,12 +866,13 @@ function m.multiTable(count, default) end }) end for _ = 3, count do + local tt = current current = setmetatable({}, { __index = function (t, k) if k == nil then return nil end - t[k] = current - return current + t[k] = tt + return tt end }) end return current |