summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-02-01 20:10:36 +0800
committerruki <[email protected]>2016-02-15 19:10:27 +0800
commit63093714d76f9895790524a20aa2a0f0fcb8007e (patch)
treeb3f3c61c003d2712a5b82beca9d2713af74e8eb8
parent0faab8456bcc516a5e09f7cf3647dd9625cbb616 (diff)
add vformat interfaces
-rw-r--r--xmake/core/base/interpreter.lua1
-rw-r--r--xmake/core/sandbox/builtin/format.lua (renamed from xmake/core/sandbox/builtin/abort.lua)8
-rw-r--r--xmake/core/sandbox/builtin/printf.lua5
-rw-r--r--xmake/core/sandbox/builtin/string.lua6
-rw-r--r--xmake/core/sandbox/builtin/utils.lua46
-rw-r--r--xmake/core/sandbox/builtin/vformat.lua26
-rw-r--r--xmake/core/sandbox/builtin/vprintf.lua (renamed from xmake/core/sandbox/builtin/dump.lua)7
7 files changed, 83 insertions, 16 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 302424711..7118055b0 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -446,6 +446,7 @@ function interpreter.init()
self:api_register_builtin("print", print)
self:api_register_builtin("pairs", pairs)
self:api_register_builtin("ipairs", ipairs)
+ self:api_register_builtin("format", string.format)
self:api_register_builtin("printf", utils.printf)
-- register the builtin modules for lua
diff --git a/xmake/core/sandbox/builtin/abort.lua b/xmake/core/sandbox/builtin/format.lua
index ea478e007..13417e546 100644
--- a/xmake/core/sandbox/builtin/abort.lua
+++ b/xmake/core/sandbox/builtin/format.lua
@@ -17,12 +17,10 @@
-- Copyright (C) 2009 - 2015, ruki All rights reserved.
--
-- @author ruki
--- @file abort.lua
+-- @file format.lua
--
--- load modules
-local utils = require("base/utils")
+-- return module
+return require("sandbox/builtin/string").format
--- load module
-return utils.abort
diff --git a/xmake/core/sandbox/builtin/printf.lua b/xmake/core/sandbox/builtin/printf.lua
index e49da1794..41acbf7c6 100644
--- a/xmake/core/sandbox/builtin/printf.lua
+++ b/xmake/core/sandbox/builtin/printf.lua
@@ -20,9 +20,6 @@
-- @file printf.lua
--
--- load modules
-local utils = require("base/utils")
-
-- load module
-return utils.printf
+return require("sandbox/builtin/utils").printf
diff --git a/xmake/core/sandbox/builtin/string.lua b/xmake/core/sandbox/builtin/string.lua
index 562e136f1..142842c5b 100644
--- a/xmake/core/sandbox/builtin/string.lua
+++ b/xmake/core/sandbox/builtin/string.lua
@@ -26,9 +26,11 @@ local string = require("base/string")
-- define module
local sandbox_builtin_string = sandbox_builtin_string or {}
--- filter string
-function sandbox_builtin_string.filter(format, ...)
+-- format string with the builtin variables
+function sandbox_builtin_string.vformat(format, ...)
+ -- done
+ return string.format(format, ...)
end
-- inherit the public interfaces of string
diff --git a/xmake/core/sandbox/builtin/utils.lua b/xmake/core/sandbox/builtin/utils.lua
new file mode 100644
index 000000000..96e8d74d9
--- /dev/null
+++ b/xmake/core/sandbox/builtin/utils.lua
@@ -0,0 +1,46 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file utils.lua
+--
+
+-- load modules
+local utils = require("base/utils")
+local string = require("sandbox/builtin/string")
+
+-- define module
+local sandbox_builtin_utils = sandbox_builtin_utils or {}
+
+-- printf with the builtin variables
+function sandbox_builtin_utils.vprintf(format, ...)
+
+ -- done
+ return print(string.vformat(format, ...))
+end
+
+-- inherit the public interfaces of utils
+for k, v in pairs(utils) do
+ if not k:startswith("_") and type(v) == "function" then
+ sandbox_builtin_utils[k] = v
+ end
+end
+
+-- return module
+return sandbox_builtin_utils
+
diff --git a/xmake/core/sandbox/builtin/vformat.lua b/xmake/core/sandbox/builtin/vformat.lua
new file mode 100644
index 000000000..462d5f54d
--- /dev/null
+++ b/xmake/core/sandbox/builtin/vformat.lua
@@ -0,0 +1,26 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file vformat.lua
+--
+
+-- return module
+return require("sandbox/builtin/string").vformat
+
+
diff --git a/xmake/core/sandbox/builtin/dump.lua b/xmake/core/sandbox/builtin/vprintf.lua
index 02d2b27c2..f0381aff4 100644
--- a/xmake/core/sandbox/builtin/dump.lua
+++ b/xmake/core/sandbox/builtin/vprintf.lua
@@ -17,12 +17,9 @@
-- Copyright (C) 2009 - 2015, ruki All rights reserved.
--
-- @author ruki
--- @file dump.lua
+-- @file vprintf.lua
--
--- load modules
-local utils = require("base/utils")
-
-- load module
-return utils.dump
+return require("sandbox/builtin/utils").vprintf