diff options
| author | Opportunity <[email protected]> | 2020-01-15 12:06:01 +0800 |
|---|---|---|
| committer | Opportunity <[email protected]> | 2020-01-15 12:06:01 +0800 |
| commit | f4e30b5e7879d4dbfbe4424f5f9156cb6cfdaf50 (patch) | |
| tree | bbd6789a15b4ffbe2040eba9dd61a047f92b2fcc /xmake/core/base/dump.lua | |
| parent | 9862d1b95fa5978eaf24d65f1ca5f151d410a14b (diff) | |
Improve dump
Diffstat (limited to 'xmake/core/base/dump.lua')
| -rw-r--r-- | xmake/core/base/dump.lua | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/xmake/core/base/dump.lua b/xmake/core/base/dump.lua index 3adb54133..5e7ed9b8f 100644 --- a/xmake/core/base/dump.lua +++ b/xmake/core/base/dump.lua @@ -88,17 +88,27 @@ function dump._print_function(func, as_key) end -- print value with default format -function dump._print_default(value) +function dump._print_default_scalar(value) io.write(dump._translate("${reset}${color.dump.default}"), dump._format("text.dump.default_format", "%s", value), dump._translate("${reset}")) end -- print udata value with scalar format function dump._print_udata_scalar(value) + local metatable = debug.getmetatable(value) + local tostringmethod = metatable and (rawget(metatable, "__todisplay") or rawget(metatable, "__tostring")) + if tostringmethod then + value = tostringmethod(value) + end io.write(dump._translate("${reset}${color.dump.udata}"), dump._format("text.dump.udata_format", "%s", value), dump._translate("${reset}")) end -- print table value with scalar format function dump._print_table_scalar(value) + local metatable = debug.getmetatable(value) + local tostringmethod = metatable and (rawget(metatable, "__todisplay") or rawget(metatable, "__tostring")) + if tostringmethod then + value = tostringmethod(value) + end io.write(dump._translate("${reset}${color.dump.table}"), dump._format("text.dump.table_format", "%s", value), dump._translate("${reset}")) end @@ -117,7 +127,7 @@ function dump._print_scalar(value, as_key) elseif type(value) == "table" then dump._print_table_scalar(value) else - dump._print_default(value) + dump._print_default_scalar(value) end end |
