summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-03-31 09:04:21 +0800
committerruki <[email protected]>2017-03-31 09:04:21 +0800
commita3feda517c9f9cfc6dca04278a96c2671510511b (patch)
tree8bfb13cfd46d080fbd2fb0f5b55a519cee478cfe
parent9add6351f3b19c569d5eafecadf659297070522a (diff)
improve print for interpreter
-rw-r--r--xmake/core/sandbox/modules/interpreter/print.lua29
1 files changed, 27 insertions, 2 deletions
diff --git a/xmake/core/sandbox/modules/interpreter/print.lua b/xmake/core/sandbox/modules/interpreter/print.lua
index 50346047a..f33afecea 100644
--- a/xmake/core/sandbox/modules/interpreter/print.lua
+++ b/xmake/core/sandbox/modules/interpreter/print.lua
@@ -22,11 +22,36 @@
-- @file print.lua
--
+-- load modules
+local try = require("sandbox/modules/try")
+local catch = require("sandbox/modules/catch")
+
-- print format string
function _print(format, ...)
- -- done
- io.write(string.format(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(string.format(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
-- load module