diff options
| author | ruki <[email protected]> | 2015-05-03 16:34:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-03 16:34:32 +0800 |
| commit | 781bfd2dc99c8e0ca3063b6a3d6199f2390951f4 (patch) | |
| tree | 0ae5c503d3e0320e5b5f430afae17fd06556c11c | |
| parent | 4a0ac3ab3b236df85fcad676a2570128a3363f07 (diff) | |
add path.getabsolute
| -rwxr-xr-x | core/src/xmake/machine.c | 13 | ||||
| -rwxr-xr-x | core/src/xmake/makefile | 3 | ||||
| -rwxr-xr-x | core/src/xmake/path/getabsolute.c | 53 | ||||
| -rw-r--r-- | core/src/xmake/path/prefix.h | 35 | ||||
| -rwxr-xr-x | core/src/xmake/string/startswith.c | 7 | ||||
| -rwxr-xr-x | install | 2 | ||||
| -rw-r--r-- | xmake/scripts/_xmake_main.lua | 1 | ||||
| -rw-r--r-- | xmake/scripts/base/main.lua | 34 |
8 files changed, 133 insertions, 15 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 896f52446..ad993da9c 100755 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -52,6 +52,9 @@ typedef struct __xm_machine_impl_t * declaration */ +// the path functions +tb_int_t xm_path_getabsolute(lua_State* lua); + // the string functions tb_int_t xm_string_startswith(lua_State* lua); @@ -59,6 +62,13 @@ tb_int_t xm_string_startswith(lua_State* lua); * globals */ +// the path functions +static luaL_Reg const g_path_functions[] = +{ + { "getabsolute", xm_path_getabsolute } +, { tb_null, tb_null } +}; + // the string functions static luaL_Reg const g_string_functions[] = { @@ -190,6 +200,9 @@ xm_machine_ref_t xm_machine_init() // open lua libraries luaL_openlibs(impl->lua); + // bind path functions + luaL_register(impl->lua, "path", g_path_functions); + // bind string functions luaL_register(impl->lua, "string", g_string_functions); diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 5c7228962..35d8e9f7a 100755 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -14,7 +14,8 @@ xmake_CONFIG = y xmake_C_FILES += \ xmake \ machine \ - string/startswith + path/getabsolute \ + string/startswith # flags diff --git a/core/src/xmake/path/getabsolute.c b/core/src/xmake/path/getabsolute.c new file mode 100755 index 000000000..8d1bae3ed --- /dev/null +++ b/core/src/xmake/path/getabsolute.c @@ -0,0 +1,53 @@ +/*!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 getabsolute.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "getabsolute" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_path_getabsolute(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the path + tb_char_t const* path = luaL_checkstring(lua, 1); + tb_check_return_val(path, 0); + + // TODO + // done path:getabsolute() + tb_trace_i("%s", path); + + // ok + return 1; +} diff --git a/core/src/xmake/path/prefix.h b/core/src/xmake/path/prefix.h new file mode 100644 index 000000000..e8531347b --- /dev/null +++ b/core/src/xmake/path/prefix.h @@ -0,0 +1,35 @@ +/*!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 prefix.h + * + */ +#ifndef XM_PATH_PREFIX_H +#define XM_PATH_PREFIX_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "../prefix.h" +#include "luajit/luajit.h" + + +#endif + + diff --git a/core/src/xmake/string/startswith.c b/core/src/xmake/string/startswith.c index b7516e129..13d72af5c 100755 --- a/core/src/xmake/string/startswith.c +++ b/core/src/xmake/string/startswith.c @@ -41,12 +41,13 @@ tb_int_t xm_string_startswith(lua_State* lua) tb_assert_and_check_return_val(lua, 0); // get the string and prefix - tb_char_t const* string = luaL_optstring(lua, 1, tb_null); - tb_char_t const* prefix = luaL_optstring(lua, 2, tb_null); + size_t prefix_size = 0; + tb_char_t const* string = luaL_checkstring(lua, 1); + tb_char_t const* prefix = luaL_checklstring(lua, 2, &prefix_size); tb_check_return_val(string && prefix, 0); // done string:startswith(prefix) - lua_pushboolean(lua, !tb_strncmp(string, prefix, tb_strlen(prefix))); + lua_pushboolean(lua, !tb_strncmp(string, prefix, (tb_size_t)prefix_size)); // ok return 1; @@ -45,7 +45,7 @@ if [ $? -ne 0 ]; then exit; fi make c >> ../install.log make >> ../install.log if [ $? -ne 0 ]; then - make e + make o exit; fi make i diff --git a/xmake/scripts/_xmake_main.lua b/xmake/scripts/_xmake_main.lua index c407b8fae..7a6e5d738 100644 --- a/xmake/scripts/_xmake_main.lua +++ b/xmake/scripts/_xmake_main.lua @@ -25,7 +25,6 @@ xmake = xmake or {} xmake._ARGV = _ARGV xmake._VERSION = "XMake v1.0.1" xmake._PROGRAM_DIR = _PROGRAM_DIR -xmake._PROJECT_DIR = _PROJECT_DIR xmake._SCRIPTS_DIR = _PROGRAM_DIR .. "/scripts/" xmake._OPTIONS = {} diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index e790dacda..56e259efd 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -242,12 +242,12 @@ local menu = , {} , {'f', "file", "kv", "xmake.lua", "Read a given xmake.lua file." } - , {nil, nil, "v", nil, "Change to the given project directory." + , {'P', "project", "kv", nil, "Change to the given project directory." , "Search priority:" - , " 1. the last argument of the current command: ..." + , " 1. the given command argument" , " 2. the envirnoment variable: XMAKE_PROJECT_DIR" , " 3. the current directory" } - + , {} , {nil, "target", "v", nil, "Clean for the given target." , "Clean all targets if not exists." } @@ -279,9 +279,16 @@ function main.done_option() -- done help if options.help then + + -- print menu option.print_menu(options._ACTION) + + -- ok + return true + -- done version elseif options.version then + -- print title if option._MENU.title then print(option._MENU.title) @@ -291,13 +298,22 @@ function main.done_option() if option._MENU.copyright then print(option._MENU.copyright) end - -- done action - else - return main.done_action() + + -- ok + return true end - - -- ok - return true + + -- init the project directory + options.project = options.project or _PROJECT_DIR + options.project = path.getabsolute(options.project) + print(options.project) + + -- init the xmake.lua file path + options.file = options.file or "xmake.lua" + print(options.file) + + -- done action + return main.done_action() end -- the main function |
