diff options
| author | ruki <[email protected]> | 2019-06-20 00:37:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-06-19 21:44:21 +0800 |
| commit | 368904bc150e3aeee0e906674a00f84cdd81f303 (patch) | |
| tree | b6a91ef459bcd4b5411a0c01fd1948a5e8d1712d | |
| parent | fe78b1755a16442fb91eba7cc232cd4446f755ee (diff) | |
modify code style
| -rw-r--r-- | xmake/core/base/dump.lua | 50 | ||||
| -rw-r--r-- | xmake/core/base/table.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua | 12 |
3 files changed, 35 insertions, 29 deletions
diff --git a/xmake/core/base/dump.lua b/xmake/core/base/dump.lua index f7012a539..463c05a96 100644 --- a/xmake/core/base/dump.lua +++ b/xmake/core/base/dump.lua @@ -25,8 +25,8 @@ local dump = dump or {} local colors = require("base/colors") local table = require("base/table") - -function dump._string(str, as_key) +-- print string +function dump._print_string(str, as_key) local quote = (not as_key) or (not str:match("^[a-zA-Z_][a-zA-Z0-9_]*$")) if quote then io.write(colors.translate("${reset}${color.dump.string_quote}\"${reset}${color.dump.string}", { patch_reset = false })) @@ -41,17 +41,20 @@ function dump._string(str, as_key) end end -function dump._keyword(keyword) +-- print keyword +function dump._print_keyword(keyword) io.write(colors.translate("${color.dump.keyword}" .. tostring(keyword))) end -function dump._number(num) +-- print number +function dump._print_number(num) io.write(colors.translate("${color.dump.number}" .. tostring(num))) end -function dump._function(func, as_key) +-- print function +function dump._print_function(func, as_key) if as_key then - return dump._default(func) + return dump._print_default(func) end local funcinfo = debug.getinfo(func) local srcinfo = funcinfo.short_src @@ -61,30 +64,33 @@ function dump._function(func, as_key) io.write(colors.translate("${color.dump.function}function ${bright}" .. (funcinfo.name or "") .. "${reset}${dim}" .. srcinfo)) end -function dump._default(value) +-- print value with default format +function dump._print_default(value) io.write(colors.translate("${color.dump.default}", { patch_reset = false })) local fmt = colors.theme():get("text.dump.default_format") or "%s" io.write(string.format(fmt, value)) io.write(colors.translate("${reset}", { patch_reset = false })) end -function dump._scalar(value, as_key) +-- print scalar value +function dump._print_scalar(value, as_key) if type(value) == "nil" then - dump._keyword("nil") + dump._print_keyword("nil") elseif type(value) == "boolean" then - dump._keyword(value) + dump._print_keyword(value) elseif type(value) == "number" then - dump._number(value) + dump._print_number(value) elseif type(value) == "string" then - dump._string(value, as_key) + dump._print_string(value, as_key) elseif type(value) == "function" then - dump._function(value, as_key) + dump._print_function(value, as_key) else - dump._default(value) + dump._print_default(value) end end -function dump._table(value, first_indent, remain_indent) +-- print table +function dump._print_table(value, first_indent, remain_indent) io.write(first_indent .. colors.translate("${dim}{")) local inner_indent = remain_indent .. " " local is_arr = table.is_array(value) @@ -98,13 +104,13 @@ function dump._table(value, first_indent, remain_indent) end io.write(inner_indent) if not is_arr or type(k) ~= "number" then - dump._scalar(k, true) + dump._print_scalar(k, true) io.write(colors.translate("${dim} = ")) end if type(v) == "table" then - dump._table(v, "", inner_indent) + dump._print_table(v, "", inner_indent) else - dump._scalar(v) + dump._print_scalar(v) end end if first_value then @@ -114,15 +120,15 @@ function dump._table(value, first_indent, remain_indent) end end +-- print value function dump._print(value, indent) indent = indent or "" - if type(value) == "table" then - dump._table(value, indent, indent:gsub(".", " ")) + dump._print_table(value, indent, indent:gsub(".", " ")) else io.write(indent) - dump._scalar(value) + dump._print_scalar(value) end end -return dump._print
\ No newline at end of file +return dump._print diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 3fd35c082..74b4723c2 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -258,7 +258,7 @@ end -- pack arguments into a table function table.pack(...) - return { n = select("#", ...), ... } + return { len = select("#", ...), ... } end -- unpack table values diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua index 5aa55a0c6..8580c0685 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua @@ -35,21 +35,21 @@ local dump = require("base/dump") function sandbox_core_sandbox._interactive_dump(...) local values = table.pack(...) -- do not use #values since nil might be included - local n = values.n - if n <= 1 then + local len = values.len + if len <= 1 then dump(values[1], "< ") io.write("\n") else local fmt = "< %d: " - if n >= 1000 then + if len >= 1000 then -- try `unpack({}, 1, 5000)`, wish you happy! fmt = "< %4d: " - elseif n >= 100 then + elseif len >= 100 then fmt = "< %3d: " - elseif n >= 10 then + elseif len >= 10 then fmt = "< %2d: " end - for i = 1, n do + for i = 1, len do dump(values[i], string.format(fmt, i)) io.write("\n") end |
