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 /core/src/xmake | |
| parent | 4a0ac3ab3b236df85fcad676a2570128a3363f07 (diff) | |
add path.getabsolute
Diffstat (limited to 'core/src/xmake')
| -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 |
5 files changed, 107 insertions, 4 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; |
