diff options
| author | ruki <[email protected]> | 2017-01-04 09:05:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-01-06 17:20:08 +0800 |
| commit | 7d17523c795681265900d109c0ee26d2349eaf73 (patch) | |
| tree | 82ae673a7738e0e91180bc4bc0e236a621fc2825 | |
| parent | fb6f2e286398021f9c9a4331246cc3553efed925 (diff) | |
improve print api
| -rw-r--r-- | CHANGELOG.md | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 32 |
2 files changed, 33 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b1020690..ae704aa63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ * Support vs2017 for the project plugin * Improve gcc error and warning tips +* Improve lanuage module +* Improve print interface, support lua print and format output ### Bugs fixed @@ -194,6 +196,8 @@ * 工程生成插件支持vs2017 * 改进gcc/clang编译器警告和错误提示 +* 重构代码架构,改进多语言支持,更加方便灵活的扩展语言支持 +* 改进print接口,同时支持原生lua print以及格式化打印 ### Bugs修复 diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index 9cbeb41f1..017e59b64 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -24,6 +24,8 @@ local io = require("base/io") local utils = require("base/utils") local colors = require("base/colors") +local try = require("sandbox/modules/try") +local catch = require("sandbox/modules/catch") local vformat = require("sandbox/modules/vformat") local raise = require("sandbox/modules/raise") @@ -37,11 +39,35 @@ for k, v in pairs(utils) do end end --- print format string and the builtin variables with newline +-- print format string with newline +-- print builtin-variables with $(var) +-- print multi-variables with raw lua action +-- function sandbox_utils.print(format, ...) - -- done - io.write(vformat(format, ...) .. "\n") + -- print format string + if type(format) == "string" and format:find("%", 1, true) then + + local args = {...} + try + { + function () + -- attempt to print format string first + io.write(vformat(format, unpack(args)) .. "\n") + end, + catch + { + function () + -- print multi-variables with raw lua action + print(format, unpack(args)) + end + } + } + + else + -- print multi-variables with raw lua action + print(format, ...) + end end -- print format string and the builtin variables without newline |
