summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-03-18 10:40:57 +0800
committerruki <[email protected]>2016-03-18 10:40:57 +0800
commit8f5125ae1329d24b5265c4cb45b1890c3f175e60 (patch)
tree9c66f71fe62c5232c1ce93a35195377bae46f130
parentdbb2fe806d1e3232c418fb47351dd8d8354e2ca2 (diff)
rename utils.dump
-rw-r--r--xmake/core/base/table.lua92
-rw-r--r--xmake/core/base/utils.lua85
-rw-r--r--xmake/core/platform/platform.lua2
-rw-r--r--xmake/core/project/config.lua2
-rw-r--r--xmake/core/project/global.lua2
-rw-r--r--xmake/core/project/project.lua2
6 files changed, 96 insertions, 89 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua
index 363f6efe0..940a05f50 100644
--- a/xmake/core/base/table.lua
+++ b/xmake/core/base/table.lua
@@ -154,5 +154,97 @@ function table.is_dictionary(self)
return false
end
+-- dump it with the level
+function table._dump(self, exclude, level)
+
+ -- dump string
+ if type(self) == "string" then
+ io.write(string.format("%q", self))
+ -- dump boolean
+ elseif type(self) == "boolean" then
+ io.write(tostring(self))
+ -- dump number
+ elseif type(self) == "number" then
+ io.write(self)
+ -- dump function
+ elseif type(self) == "function" then
+ io.write("<function>")
+ -- dump table
+ elseif type(self) == "table" then
+
+ -- dump head
+ io.write("\n")
+ for l = 1, level do
+ io.write(" ")
+ end
+ io.write("{\n")
+
+ -- dump body
+ local i = 0
+ for k, v in pairs(self) do
+
+ -- exclude some keys
+ if not exclude or type(k) ~= "string" or not k:find(exclude) then
+
+ -- dump spaces and separator
+ for l = 1, level do
+ io.write(" ")
+ end
+
+ if i == 0 then
+ io.write(" ")
+ else
+ io.write(", ")
+ end
+
+ -- dump key
+ if type(k) == "string" then
+ io.write(k, " = ")
+ end
+
+ -- dump value
+ if not table._dump(v, exclude, level + 1) then
+ return false
+ end
+
+ -- dump newline
+ io.write("\n")
+ i = i + 1
+ end
+ end
+
+ -- dump tail
+ for l = 1, level do
+ io.write(" ")
+ end
+ io.write("}\n")
+ -- dump userdata
+ elseif type(self) == "userdata" then
+ io.write("<userdata>")
+ else
+ -- error
+ print("error: invalid object type: %s", type(self))
+ return false
+ end
+
+ -- ok
+ return true
+end
+
+-- dump it
+function table.dump(self, exclude, prefix)
+
+ -- dump prefix
+ if prefix then
+ io.write(prefix)
+ end
+
+ -- dump it
+ table._dump(self, exclude, 0)
+
+ -- return it
+ return self
+end
+
-- return module: table
return table
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index 36ff0718c..3ff7283fe 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -104,91 +104,6 @@ function utils.ifelse(a, b, c)
if a then return b else return c end
end
--- dump object with the level
-function utils._dump_with_level(object, exclude, level)
-
- -- dump string
- if type(object) == "string" then
- io.write(string.format("%q", object))
- -- dump boolean
- elseif type(object) == "boolean" then
- io.write(tostring(object))
- -- dump number
- elseif type(object) == "number" then
- io.write(object)
- -- dump function
- elseif type(object) == "function" then
- io.write("<function>")
- -- dump table
- elseif type(object) == "table" then
-
- -- dump head
- io.write("\n")
- for l = 1, level do
- io.write(" ")
- end
- io.write("{\n")
-
- -- dump body
- local i = 0
- for k, v in pairs(object) do
-
- -- exclude some keys
- if not exclude or type(k) ~= "string" or not k:find(exclude) then
-
- -- dump spaces and separator
- for l = 1, level do
- io.write(" ")
- end
-
- io.write(utils.ifelse(i == 0, " ", ", "))
-
- -- dump key
- if type(k) == "string" then
- io.write(k, " = ")
- end
-
- -- dump value
- if not utils._dump_with_level(v, exclude, level + 1) then
- return false
- end
-
- -- dump newline
- io.write("\n")
- i = i + 1
- end
- end
-
- -- dump tail
- for l = 1, level do
- io.write(" ")
- end
- io.write("}\n")
- else
- -- error
- utils.error("invalid object type: %s", type(object))
- return false
- end
-
- -- ok
- return true
-end
-
--- dump object
-function utils.dump(object, exclude, prefix)
-
- -- dump prefix
- if prefix then
- io.write(prefix)
- end
-
- -- dump it
- utils._dump_with_level(object, exclude, 0)
-
- -- return it
- return object
-end
-
-- unwrap object if be only one
function utils.unwrap(object)
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index 42e49f1d2..c0e974460 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -247,7 +247,7 @@ function platform.dump()
-- dump
if option.get("verbose") then
- utils.dump(platform._configs(config.get("plat")))
+ table.dump(platform._configs(config.get("plat")))
end
end
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index ab4a4c46d..1942ca5e6 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -207,7 +207,7 @@ end
function config.dump()
-- dump
- utils.dump(config.options(), "__%w*", "configure")
+ table.dump(config.options(), "__%w*", "configure")
end
diff --git a/xmake/core/project/global.lua b/xmake/core/project/global.lua
index 7f4ef0b3f..f4e386c08 100644
--- a/xmake/core/project/global.lua
+++ b/xmake/core/project/global.lua
@@ -154,7 +154,7 @@ end
function global.dump()
-- dump
- utils.dump(global.options(), "__%w*", "configure")
+ table.dump(global.options(), "__%w*", "configure")
end
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 231bdee3d..26efea453 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -825,7 +825,7 @@ function project.dump()
-- dump
if option.get("verbose") then
- utils.dump(project.targets())
+ table.dump(project.targets())
end
end