summaryrefslogtreecommitdiff
path: root/xmake/scripts/base/utils.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-02 10:50:54 +0800
committerruki <[email protected]>2015-06-02 10:50:54 +0800
commit4b85064e874d050de835f4a4a0b2158f1405a6aa (patch)
treec3f0ccec578302d4ad215198014d7f6331975546 /xmake/scripts/base/utils.lua
parentbf6315e4e63270175eb27d9ab73dc98f3408cea8 (diff)
reimpl unique for flags
Diffstat (limited to 'xmake/scripts/base/utils.lua')
-rw-r--r--xmake/scripts/base/utils.lua30
1 files changed, 17 insertions, 13 deletions
diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua
index 7e4322eb9..c51e9eeb2 100644
--- a/xmake/scripts/base/utils.lua
+++ b/xmake/scripts/base/utils.lua
@@ -153,8 +153,10 @@ end
-- wrap object to table
function utils.wrap(object)
- -- check
- assert(object)
+ -- no object?
+ if not object then
+ return {}
+ end
-- wrap it if not table
if type(object) ~= "table" then
@@ -176,24 +178,26 @@ function utils.unique(array)
-- not only one?
if table.getn(array) ~= 1 then
-
- -- make unique table
+
+ -- done
+ local exists = {}
local unique = {}
for _, v in ipairs(array) do
if type(v) == "string" then
- unique[v] = v
+ if not exists[v] then
+ exists[v] = true
+ unique[table.getn(unique) + 1] = v
+ end
else
- unique["\"" .. v .. "\""] = v
+ if not exists["\"" .. v .. "\""] then
+ exists["\"" .. v .. "\""] = true
+ unique[table.getn(unique) + 1] = v
+ end
end
end
- -- make array again
- array = {}
- local i = 1
- for _, v in pairs(unique) do
- array[i] = v
- i = i + 1
- end
+ -- update it
+ array = unique
end
end