diff options
| author | ruki <[email protected]> | 2016-07-31 18:44:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-07-31 18:44:18 +0800 |
| commit | de05bd361137a2971875f9ba4d30cea926823913 (patch) | |
| tree | ae2df01a1b269099795aa992593df38f938a485c | |
| parent | 68b869763491ff6eb97085b8536ef1b7c72fd2bd (diff) | |
try to format errors and add uuid interface
| -rwxr-xr-x | core/src/xmake/machine.c | 2 | ||||
| -rwxr-xr-x | core/src/xmake/makefile | 1 | ||||
| -rwxr-xr-x | core/src/xmake/os/uuid.c | 50 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/string.lua | 12 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 17 |
6 files changed, 75 insertions, 9 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index b877eb3c1..280069f7b 100755 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -54,6 +54,7 @@ typedef struct __xm_machine_impl_t // the os functions tb_int_t xm_os_find(lua_State* lua); +tb_int_t xm_os_uuid(lua_State* lua); tb_int_t xm_os_isdir(lua_State* lua); tb_int_t xm_os_rmdir(lua_State* lua); tb_int_t xm_os_mkdir(lua_State* lua); @@ -99,6 +100,7 @@ tb_int_t xm_process_close(lua_State* lua); static luaL_Reg const g_os_functions[] = { { "find", xm_os_find } +, { "uuid", xm_os_uuid } , { "isdir", xm_os_isdir } , { "rmdir", xm_os_rmdir } , { "mkdir", xm_os_mkdir } diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 4b692eda3..09d0767e1 100755 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -15,6 +15,7 @@ xmake_C_FILES += \ xmake \ machine \ os/find \ + os/uuid \ os/isdir \ os/rmdir \ os/mkdir \ diff --git a/core/src/xmake/os/uuid.c b/core/src/xmake/os/uuid.c new file mode 100755 index 000000000..c30d52815 --- /dev/null +++ b/core/src/xmake/os/uuid.c @@ -0,0 +1,50 @@ +/*!The Make-like Build Utility based on Lua + * + * 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) 2015 - 2016, ruki All rights reserved. + * + * @author ruki + * @file uuid.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "uuid" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_uuid(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the name + tb_char_t const* name = luaL_checkstring(lua, 1); + tb_used(name); + + + // ok + return 1; +} diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index e5c088140..923496fc3 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -454,7 +454,7 @@ function os.raise(msg, ...) -- raise it if msg then - error(string.format(msg, ...)) + error(string.tryformat(msg, ...)) else error() end diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua index ad178895b..22a84d9f4 100644 --- a/xmake/core/base/string.lua +++ b/xmake/core/base/string.lua @@ -136,5 +136,17 @@ function string:less(other) return string.strcmp(self, other) < 0 end +-- try to format +function string.tryformat(format, ...) + + -- attempt to format it + local ok, str = pcall(string.format, format, ...) + if ok then + return str + else + return format + end +end + -- return module: string return string diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index eba9bcf35..aa70d8b47 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -26,6 +26,7 @@ local utils = utils or {} -- load modules local option = require("base/option") local colors = require("base/colors") +local string = require("base/string") -- print format string with newline function utils.print(format, ...) @@ -34,7 +35,7 @@ function utils.print(format, ...) assert(format) -- trace - print(string.format(format, ...)) + print(string.tryformat(format, ...)) end -- print format string without newline @@ -44,7 +45,7 @@ function utils.printf(format, ...) assert(format) -- trace - io.write(string.format(format, ...)) + io.write(string.tryformat(format, ...)) end -- print format string and colors with newline @@ -54,7 +55,7 @@ function utils.cprint(format, ...) assert(format) -- trace - print(colors(string.format(format, ...))) + print(colors(string.tryformat(format, ...))) end -- print format string and colors without newline @@ -64,7 +65,7 @@ function utils.cprintf(format, ...) assert(format) -- trace - io.write(colors(string.format(format, ...))) + io.write(colors(string.tryformat(format, ...))) end -- the verbose function @@ -74,7 +75,7 @@ function utils.verbose(format, ...) if option.get("verbose") and format ~= nil then -- trace - print(string.format(format, ...)) + print(string.tryformat(format, ...)) end end @@ -85,7 +86,7 @@ function utils.verror(format, ...) if option.get("verbose") and format ~= nil then -- trace - utils.cprint("${bright red}error: ${default red}" .. string.format(format, ...)) + utils.cprint("${bright red}error: ${default red}" .. string.tryformat(format, ...)) end end @@ -94,7 +95,7 @@ function utils.error(format, ...) -- trace if format ~= nil then - utils.cprint("${bright red}error: ${default red}" .. string.format(format, ...)) + utils.cprint("${bright red}error: ${default red}" .. string.tryformat(format, ...)) end end @@ -105,7 +106,7 @@ function utils.warning(format, ...) assert(format) -- format message - local msg = "${bright yellow}warning: ${default yellow}" .. string.format(format, ...) + local msg = "${bright yellow}warning: ${default yellow}" .. string.tryformat(format, ...) -- init warnings utils._WARNINGS = utils._WARNINGS or {} |
