summaryrefslogtreecommitdiff
path: root/xmake/core/base
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 /xmake/core/base
parentd0615e6499637a780cefe2d69f61cc1457929120 (diff)
add table.append
Diffstat (limited to 'xmake/core/base')
-rw-r--r--xmake/core/base/interpreter.lua10
-rw-r--r--xmake/core/base/table.lua28
2 files changed, 12 insertions, 26 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)