summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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