summaryrefslogtreecommitdiff
path: root/xmake/core/base/path.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-03-13 15:38:53 +0800
committerruki <[email protected]>2022-03-13 15:38:53 +0800
commit2a1697f9d16bf58f99e827e3fb17b2581f26c1cd (patch)
treed9334d78370350847c68c153c69f9ee64ae683d8 /xmake/core/base/path.lua
parentd5eb35f0c29ddb3f1944368f74315e686e7a52dd (diff)
improve path.directory
Diffstat (limited to 'xmake/core/base/path.lua')
-rw-r--r--xmake/core/base/path.lua19
1 files changed, 19 insertions, 0 deletions
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