From 35dbc87a2c7e36e8cd3d6e81acd84ff3d5542ba8 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Mon, 1 Jul 2019 15:20:09 +0800 Subject: add tostring metamethod dump --- xmake/core/base/dump.lua | 14 +++++++++++--- xmake/core/sandbox/modules/winos.lua | 5 ++--- 2 files changed, 13 insertions(+), 6 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 diff --git a/xmake/core/sandbox/modules/winos.lua b/xmake/core/sandbox/modules/winos.lua index 0f495d4a9..ad3d298cc 100644 --- a/xmake/core/sandbox/modules/winos.lua +++ b/xmake/core/sandbox/modules/winos.lua @@ -26,13 +26,12 @@ local raise = require("sandbox/modules/raise") local sandbox_winos = sandbox_winos or {} -- inherit some builtin interfaces +sandbox_winos.oem_cp = winos.oem_cp sandbox_winos.ansi_cp = winos.ansi_cp -sandbox_winos.mbstoutf8 = winos.mbstoutf8 sandbox_winos.cp_info = winos.cp_info -sandbox_winos.oem_cp = winos.oem_cp -sandbox_winos.console_cp = winos.console_cp sandbox_winos.console_cp = winos.console_cp sandbox_winos.console_output_cp = winos.console_output_cp +sandbox_winos.mbstoutf8 = winos.mbstoutf8 sandbox_winos.registry_query = winos.registry_query sandbox_winos.logical_drives = winos.logical_drives -- cgit v1.3.1