summaryrefslogtreecommitdiff
path: root/xmake/scripts/base/utils.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-20 10:40:16 +0800
committerruki <[email protected]>2015-05-20 10:40:16 +0800
commitd0c91342731cdbaa3e25e239574ce41593297ee1 (patch)
treecab29bc6d12be7aa4f67e6dad5a57dbe73717220 /xmake/scripts/base/utils.lua
parent9c161e7f113de8c020df176c1fab87e8c93083f5 (diff)
make the current project configure
Diffstat (limited to 'xmake/scripts/base/utils.lua')
-rw-r--r--xmake/scripts/base/utils.lua61
1 files changed, 58 insertions, 3 deletions
diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua
index 61998339e..7e4322eb9 100644
--- a/xmake/scripts/base/utils.lua
+++ b/xmake/scripts/base/utils.lua
@@ -76,7 +76,7 @@ function utils._dump_with_level(object, exclude, level)
for l = 1, level do
io.write(" ")
end
- io.write("{\n")
+ io.write("{\n")
-- dump body
local i = 0
@@ -85,12 +85,11 @@ function utils._dump_with_level(object, exclude, level)
-- exclude some keys
if not exclude or type(k) ~= "string" or not k:find(exclude) then
- -- dump spaces
+ -- dump spaces and separator
for l = 1, level do
io.write(" ")
end
- -- dump separator
io.write(utils.ifelse(i == 0, " ", ", "))
-- dump key
@@ -134,6 +133,23 @@ function utils.dump(object, exclude)
return object
end
+-- unwrap object if be only one
+function utils.unwrap(object)
+
+ -- check
+ assert(object)
+
+ -- unwrap it
+ if type(object) == "table" and table.getn(object) == 1 then
+ for _, v in pairs(object) do
+ return v
+ end
+ end
+
+ -- ok
+ return object
+end
+
-- wrap object to table
function utils.wrap(object)
@@ -144,6 +160,45 @@ function utils.wrap(object)
if type(object) ~= "table" then
return {object}
end
+
+ -- ok
+ return object
+end
+
+-- remove repeat from the given array
+function utils.unique(array)
+
+ -- check
+ assert(array)
+
+ -- remove repeat
+ if type(array) == "table" then
+
+ -- not only one?
+ if table.getn(array) ~= 1 then
+
+ -- make unique table
+ local unique = {}
+ for _, v in ipairs(array) do
+ if type(v) == "string" then
+ unique[v] = v
+ else
+ unique["\"" .. v .. "\""] = v
+ end
+ end
+
+ -- make array again
+ array = {}
+ local i = 1
+ for _, v in pairs(unique) do
+ array[i] = v
+ i = i + 1
+ end
+ end
+ end
+
+ -- ok
+ return array
end
-- return module: utils