From 2a1697f9d16bf58f99e827e3fb17b2581f26c1cd Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 13 Mar 2022 15:38:53 +0800 Subject: improve path.directory --- xmake/core/base/path.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index 49850c42b..8860b2af9 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -38,6 +38,25 @@ function path.normalize(p) return path.translate(p, {normalize = true}) end +-- get the directory of the path, compatible with lower version core binary +if not path.directory then + function path.directory(p, sep) + local i = 0 + if sep then + -- if the path has been normalized, we can quickly find it with a unique path separator prompt + i = p:lastof(sep, true) or 0 + else + i = math.max(p:lastof('/', true) or 0, p:lastof('\\', true) or 0) + end + if i > 0 then + if i > 1 then i = i - 1 end + return p:sub(1, i) + else + return "." + end + end +end + -- get the filename of the path function path.filename(p, sep) local i = 0 -- cgit v1.3.1