diff options
| author | ruki <[email protected]> | 2019-06-19 00:53:28 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-06-18 23:20:51 +0800 |
| commit | 5c06711d12932c02ab7b64a25135902fabf00675 (patch) | |
| tree | a4c12081725c3bf8d8dd2712ef320f947e282529 | |
| parent | d6d53fa5696b012d435506d3b88edb5851c269f8 (diff) | |
improve print for interactive mode
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua index 6bb1b715d..ad448e4be 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua @@ -24,8 +24,33 @@ local sandbox_core_sandbox = sandbox_core_sandbox or {} -- load modules local sandbox = require("sandbox/sandbox") local raise = require("sandbox/modules/raise") +local try = require("sandbox/modules/try") +local catch = require("sandbox/modules/catch") +local utils = require("base/utils") local history = require("project/history") +-- print variables for interactive mode +function sandbox_core_sandbox._interactive_print(format, ...) + + if type(format) == "string" and format:find("%", 1, true) then + local args = {...} + try + { + function () + utils._print(string.format(format, unpack(args))) + end, + catch + { + function (errors) + utils._print(format, unpack(args)) + end + } + } + else + utils._print(format, ...) + end +end + -- enter interactive mode function sandbox_core_sandbox.interactive() @@ -55,6 +80,9 @@ function sandbox_core_sandbox.interactive() end end + -- register print function for interactive mode + instance._PUBLIC.print = sandbox_core_sandbox._interactive_print + -- enter interactive mode with this new sandbox sandbox.interactive(instance._PUBLIC) |
