summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-08-08 23:37:41 +0800
committerruki <[email protected]>2017-08-08 23:37:41 +0800
commit24293af542a3167b616085317a4bfaac8e653a31 (patch)
tree706a00c565ef034bcfbb0c6ef8b595dd35d3052d
parentd0615e6499637a780cefe2d69f61cc1457929120 (diff)
add table.append
-rw-r--r--xmake/core/base/interpreter.lua10
-rw-r--r--xmake/core/base/table.lua28
-rw-r--r--xmake/core/project/option.lua5
-rw-r--r--xmake/core/project/target.lua5
4 files changed, 18 insertions, 30 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 5577b2a9a..32d38cf84 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -1072,10 +1072,7 @@ function interpreter:api_register_set_values(scope_kind, ...)
-- define implementation
local implementation = function (self, scope, name, ...)
-
- -- update values?
- scope[name] = {}
- table.join2(scope[name], ...)
+ scope[name] = {...}
end
-- register implementation
@@ -1090,10 +1087,8 @@ function interpreter:api_register_add_values(scope_kind, ...)
-- define implementation
local implementation = function (self, scope, name, ...)
-
- -- append values?
scope[name] = scope[name] or {}
- table.join2(scope[name], ...)
+ table.append(scope[name], ...)
end
-- register implementation
@@ -1282,7 +1277,6 @@ function interpreter:api_register_add_pathes(scope_kind, ...)
-- append values?
scope[name] = scope[name] or {}
table.join2(scope[name], self:_api_translate_pathes(...))
-
end
-- register implementation
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index 023166f69..db06f094f 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -27,11 +27,6 @@ local table = table or {}
-- clear the table
function table.clear(self)
-
- -- check
- assert(self and type(self) == "table")
-
- -- clear it
for k in next, self do
rawset(self, k, nil)
end
@@ -40,10 +35,8 @@ end
-- join all objects and tables
function table.join(...)
- -- done
- local args = {...}
local result = {}
- for _, t in ipairs(args) do
+ for _, t in ipairs({...}) do
if type(t) == "table" then
for k, v in pairs(t) do
if type(k) == "number" then table.insert(result, v)
@@ -53,20 +46,13 @@ function table.join(...)
table.insert(result, t)
end
end
-
- -- ok?
return result
end
-- join all objects and tables to self
function table.join2(self, ...)
- -- check
- assert(self and type(self) == "table")
-
- -- done
- local args = {...}
- for _, t in ipairs(args) do
+ for _, t in ipairs({...}) do
if type(t) == "table" then
for k, v in pairs(t) do
if type(k) == "number" then table.insert(self, v)
@@ -76,11 +62,17 @@ function table.join2(self, ...)
table.insert(self, t)
end
end
-
- -- ok?
return self
end
+-- append all objects to array
+function table.append(array, ...)
+ for _, value in ipairs({...}) do
+ table.insert(array, value)
+ end
+ return array
+end
+
-- copy the table to self
function table.copy(copied)
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 9571293de..314af0c40 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -258,7 +258,7 @@ function option:set(name_or_info, ...)
if type(name_or_info) == "string" then
local args = ...
if args ~= nil then
- self._INFO[name_or_info] = table.unique(table.join(...))
+ self._INFO[name_or_info] = table.unique({...})
else
self._INFO[name_or_info] = nil
end
@@ -272,7 +272,8 @@ end
-- add the value to the option info
function option:add(name_or_info, ...)
if type(name_or_info) == "string" then
- self._INFO[name_or_info] = table.unique(table.join(table.wrap(self._INFO[name_or_info]), ...))
+ local info = table.wrap(self._INFO[name_or_info])
+ self._INFO[name_or_info] = table.unique(table.append(info, ...))
elseif type(name_or_info) == "table" and #name_or_info == 0 then
for name, info in pairs(table.join(name_or_info, ...)) do
self:add(name, info)
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 9cf91343e..543b4f51c 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -77,7 +77,7 @@ function target:set(name_or_info, ...)
if type(name_or_info) == "string" then
local args = ...
if args ~= nil then
- self._INFO[name_or_info] = table.unique(table.join(...))
+ self._INFO[name_or_info] = table.unique({...})
else
self._INFO[name_or_info] = nil
end
@@ -91,7 +91,8 @@ end
-- add the value to the target info
function target:add(name_or_info, ...)
if type(name_or_info) == "string" then
- self._INFO[name_or_info] = table.unique(table.join(table.wrap(self._INFO[name_or_info]), ...))
+ local info = table.wrap(self._INFO[name_or_info])
+ self._INFO[name_or_info] = table.unique(table.append(info, ...))
elseif type(name_or_info) == "table" and #name_or_info == 0 then
for name, info in pairs(table.join(name_or_info, ...)) do
self:add(name, info)