summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-22 16:42:52 +0800
committerruki <[email protected]>2022-05-22 16:42:52 +0800
commit603749bcd6eff68165f0e0695b532a6173580f67 (patch)
tree397df1c3ca928b25dffbf6089bb3d761954a6b03
parent268371fc70abcb8a7d455923e5d937ceeaa6a04c (diff)
improve table to support path
-rw-r--r--xmake/core/base/path.lua10
-rw-r--r--xmake/core/base/table.lua4
2 files changed, 12 insertions, 2 deletions
diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua
index edc6daa24..7ccb320e6 100644
--- a/xmake/core/base/path.lua
+++ b/xmake/core/base/path.lua
@@ -32,6 +32,7 @@ function _instance.new(p, transform)
instance._PATH = p
instance._TRANSFORM = transform
setmetatable(instance, _instance)
+ table.wraplock(instance)
return instance
end
@@ -131,12 +132,14 @@ end
-- - reduce "/xxx/.." => "/"
--
function path.normalize(p)
+ p = tostring(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)
+ p = tostring(p)
local i = 0
if sep then
-- if the path has been normalized, we can quickly find it with a unique path separator prompt
@@ -155,6 +158,7 @@ end
-- get the filename of the path
function path.filename(p, sep)
+ p = tostring(p)
local i = 0
if sep then
-- if the path has been normalized, we can quickly find it with a unique path separator prompt
@@ -171,6 +175,7 @@ end
-- get the basename of the path
function path.basename(p)
+ p = tostring(p)
local name = path.filename(p)
local i = name:lastof(".", true)
if i then
@@ -182,6 +187,7 @@ end
-- get the file extension of the path: .xxx
function path.extension(p, level)
+ p = tostring(p)
local i = p:lastof(".", true)
if i then
local ext = p:sub(i)
@@ -199,11 +205,13 @@ end
-- join path
function path.join(p, ...)
+ p = tostring(p)
return path.translate(p .. path.sep() .. table.concat({...}, path.sep()))
end
-- split path by the separator
function path.split(p)
+ p = tostring(p)
return p:split("[/\\]")
end
@@ -292,6 +300,7 @@ end
-- the last character is the path seperator?
function path.islastsep(p)
+ p = tostring(p)
local sep = p:sub(#p, #p)
return xmake._HOST == "windows" and (sep == '\\' or sep == '/') or (sep == '/')
end
@@ -319,6 +328,7 @@ end
-- get cygwin-style path on msys2/cygwin, e.g. "c:\xxx" -> "/c/xxx"
function path.cygwin_path(p)
+ p = tostring(p)
p = p:gsub("\\", "/")
local pos = p:find(":/")
if pos == 2 then
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index 6c2b3aaf4..b8e83cd40 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -93,7 +93,7 @@ end
function table.join(...)
local result = {}
for _, t in ipairs({...}) do
- if type(t) == "table" then
+ if type(t) == "table" and not t.__wraplocked__ then
for k, v in pairs(t) do
if type(k) == "number" then table.insert(result, v)
else result[k] = v end
@@ -108,7 +108,7 @@ end
-- join all objects and tables to self
function table.join2(self, ...)
for _, t in ipairs({...}) do
- if type(t) == "table" then
+ if type(t) == "table" and not t.__wraplocked__ then
for k, v in pairs(t) do
if type(k) == "number" then table.insert(self, v)
else self[k] = v end