summaryrefslogtreecommitdiff
path: root/xmake/core/base/dump.lua
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-07-01 15:20:09 +0800
committerOpportunityLiu <[email protected]>2019-07-01 15:20:09 +0800
commit35dbc87a2c7e36e8cd3d6e81acd84ff3d5542ba8 (patch)
tree15f2861adc7c19a6c4d942ebbc832340cbcb68fa /xmake/core/base/dump.lua
parentf40152174188626df4b70ca1b9044a721fd3c6e8 (diff)
add tostring metamethod dump
Diffstat (limited to 'xmake/core/base/dump.lua')
-rw-r--r--xmake/core/base/dump.lua14
1 files changed, 11 insertions, 3 deletions
diff --git a/xmake/core/base/dump.lua b/xmake/core/base/dump.lua
index d117cf112..56b98f2ef 100644
--- a/xmake/core/base/dump.lua
+++ b/xmake/core/base/dump.lua
@@ -110,10 +110,11 @@ end
-- print table
function dump._print_table(value, first_indent, remain_indent, printed_set)
+ local first_level = not printed_set
io.write(first_indent)
- local __tostring = rawget(getmetatable(value) or {}, "__tostring")
- if __tostring then
- return dump._print_default(__tostring(value, value))
+ local strrep = rawget(getmetatable(value) or {}, "__tostring") and tostring(value)
+ if not first_level and strrep then
+ return dump._print_default(strrep)
end
printed_set = printed_set or { len = 0 }
io.write(colors.translate("${dim}{"))
@@ -128,6 +129,13 @@ function dump._print_table(value, first_indent, remain_indent, printed_set)
io.write("\n")
printed_set[value] = printed_set.len
first_value = false
+ if strrep then
+ io.write(inner_indent)
+ dump._print_keyword("(tostring)")
+ io.write(colors.translate("${dim} = "))
+ dump._print_scalar(strrep)
+ io.write(",\n")
+ end
else
io.write(",\n")
end