From 426b30ed25c597554169474ff26543b8ac500652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 10 Sep 2020 16:43:07 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/workspace/require-path.lua | 35 ++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'script-beta/workspace') 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 -- cgit v1.2.3