summaryrefslogtreecommitdiff
path: root/xmake/core/base/table.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-08 10:30:48 +0800
committerruki <[email protected]>2017-02-08 10:30:48 +0800
commit0dd09d0248bb07ca897d666ff13feaae19a3d93e (patch)
tree96cb83fb812b0e995a34cbf0ed562e8f3c5b471a /xmake/core/base/table.lua
parent495724f2c5c22501520de05715f6ef18f2bd484d (diff)
add os.argv
Diffstat (limited to 'xmake/core/base/table.lua')
-rw-r--r--xmake/core/base/table.lua111
1 files changed, 61 insertions, 50 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index 6c37ae219..3767fc1c4 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -25,6 +25,18 @@
-- define module: table
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
+end
+
-- join all objects and tables
function table.join(...)
@@ -69,18 +81,6 @@ function table.join2(self, ...)
return self
end
--- 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
-end
-
-- copy the table to self
function table.copy(copied)
@@ -116,6 +116,55 @@ function table.copy2(self, copied)
end
+-- inherit interfaces and create a new instance
+function table.inherit(...)
+
+ -- init instance
+ local classes = {...}
+ local instance = {}
+ for _, clasz in ipairs(classes) do
+ for k, v in pairs(clasz) do
+ if type(v) == "function" then
+ instance[k] = v
+ end
+ end
+ end
+
+ -- ok?
+ return instance
+end
+
+-- inherit interfaces from the given class
+function table.inherit2(self, ...)
+
+ -- check
+ assert(self)
+
+ -- init instance
+ local classes = {...}
+ for _, clasz in ipairs(classes) do
+ for k, v in pairs(clasz) do
+ if type(v) == "function" and self[k] == nil then
+ self[k] = v
+ end
+ end
+ end
+
+ -- ok?
+ return self
+end
+
+-- slice table array
+function table.slice(self, first, last, step)
+
+ -- slice it
+ local sliced = {}
+ for i = first or 1, last or #self, step or 1 do
+ sliced[#sliced + 1] = self[i]
+ end
+ return sliced
+end
+
-- is array?
function table.is_array(self)
@@ -321,43 +370,5 @@ function table.unique(array)
return array
end
--- inherit interfaces and create a new instance
-function table.inherit(...)
-
- -- init instance
- local classes = {...}
- local instance = {}
- for _, clasz in ipairs(classes) do
- for k, v in pairs(clasz) do
- if type(v) == "function" then
- instance[k] = v
- end
- end
- end
-
- -- ok?
- return instance
-end
-
--- inherit interfaces from the given class
-function table.inherit2(self, ...)
-
- -- check
- assert(self)
-
- -- init instance
- local classes = {...}
- for _, clasz in ipairs(classes) do
- for k, v in pairs(clasz) do
- if type(v) == "function" and self[k] == nil then
- self[k] = v
- end
- end
- end
-
- -- ok?
- return self
-end
-
-- return module: table
return table