diff options
Diffstat (limited to 'script-beta/workspace')
-rw-r--r-- | script-beta/workspace/require-path.lua | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/script-beta/workspace/require-path.lua b/script-beta/workspace/require-path.lua index a9bd6fc0..c21f598a 100644 --- a/script-beta/workspace/require-path.lua +++ b/script-beta/workspace/require-path.lua @@ -1,7 +1,38 @@ local m = {} ---- `aaa/bbb/ccc.lua` 与 `?.lua` 将返回 `a.b.c` -function m.getVisiblePath(path, searcher) +m.cache = {} + +--- `aaa/bbb/ccc.lua` 与 `?.lua` 将返回 `aaa.bbb.cccc` +local function getOnePath(path, searcher) + local stemPath = path + : gsub('%.[^%.]+$', '') + : gsub('[/\\]+', '.') + local stemSearcher = searcher + : gsub('%.[^%.]+$', '') + : gsub('[/\\]+', '.') + local start = stemSearcher:match '()%?' or 1 + for pos = start, #stemPath do + local word = stemPath:sub(start, pos) + local newSearcher = stemSearcher:gsub('%?', word) + if newSearcher == stemPath then + return word + end + end + return nil +end + +function m.getVisiblePath(path, searchers) + if not m.cache[path] then + local result = {} + m.cache[path] = result + for _, searcher in ipairs(searchers) do + end + end + return m.cache[path] +end + +function m.flush() + m.cache = {} end return m |