diff options
| author | ruki <[email protected]> | 2015-05-17 10:28:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-17 10:28:22 +0800 |
| commit | 7be8238f634969e80e678f59ab418900f846b094 (patch) | |
| tree | 75c956fde24193c7d6e21a7406de5cc8518d9ab8 /core/src | |
| parent | b7344cd33b93ba1a1aa96eea057adf4b71f7139a (diff) | |
add some os interfaces
Diffstat (limited to 'core/src')
| -rwxr-xr-x | core/src/xmake/machine.c | 33 | ||||
| -rwxr-xr-x | core/src/xmake/makefile | 9 | ||||
| -rwxr-xr-x | core/src/xmake/os/cpdir.c | 53 | ||||
| -rwxr-xr-x | core/src/xmake/os/cpfile.c | 53 | ||||
| -rwxr-xr-x | core/src/xmake/os/exists.c | 52 | ||||
| -rwxr-xr-x | core/src/xmake/os/isdir.c | 53 | ||||
| -rwxr-xr-x | core/src/xmake/os/isfile.c | 53 | ||||
| -rwxr-xr-x | core/src/xmake/os/mkdir.c | 52 | ||||
| -rw-r--r-- | core/src/xmake/os/prefix.h | 35 | ||||
| -rwxr-xr-x | core/src/xmake/os/rename.c | 53 | ||||
| -rwxr-xr-x | core/src/xmake/os/rmdir.c | 52 | ||||
| -rwxr-xr-x | core/src/xmake/os/rmfile.c | 52 |
12 files changed, 548 insertions, 2 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 375f12bd8..dd4ae864c 100755 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -49,6 +49,17 @@ typedef struct __xm_machine_impl_t * declaration */ +// the os functions +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); +tb_int_t xm_os_cpdir(lua_State* lua); +tb_int_t xm_os_isfile(lua_State* lua); +tb_int_t xm_os_rmfile(lua_State* lua); +tb_int_t xm_os_cpfile(lua_State* lua); +tb_int_t xm_os_rename(lua_State* lua); +tb_int_t xm_os_exists(lua_State* lua); + // the path functions tb_int_t xm_path_absolute(lua_State* lua); tb_int_t xm_path_translate(lua_State* lua); @@ -64,6 +75,21 @@ tb_int_t xm_preprocessor_loadx(lua_State* lua); * globals */ +// the os functions +static luaL_Reg const g_os_functions[] = +{ + { "isdir", xm_os_isdir } +, { "rmdir", xm_os_rmdir } +, { "mkdir", xm_os_mkdir } +, { "cpdir", xm_os_cpdir } +, { "isfile", xm_os_isfile } +, { "rmfile", xm_os_rmfile } +, { "cpfile", xm_os_cpfile } +, { "rename", xm_os_rename } +, { "exists", xm_os_exists } +, { tb_null, tb_null } +}; + // the path functions static luaL_Reg const g_path_functions[] = { @@ -83,8 +109,8 @@ static luaL_Reg const g_string_functions[] = // the preprocessor functions static luaL_Reg const g_preprocessor_functions[] = { - { "loadx", xm_preprocessor_loadx } -, { tb_null, tb_null } + { "loadx", xm_preprocessor_loadx } +, { tb_null, tb_null } }; /* ////////////////////////////////////////////////////////////////////////////////////// @@ -207,6 +233,9 @@ xm_machine_ref_t xm_machine_init() // open lua libraries luaL_openlibs(impl->lua); + // bind os functions + luaL_register(impl->lua, "os", g_os_functions); + // bind path functions luaL_register(impl->lua, "path", g_path_functions); diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index e0b530bb1..899ceaf3a 100755 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -14,6 +14,15 @@ xmake_CONFIG = y xmake_C_FILES += \ xmake \ machine \ + os/isdir \ + os/rmdir \ + os/mkdir \ + os/cpdir \ + os/isfile \ + os/rmfile \ + os/cpfile \ + os/rename \ + os/exists \ path/absolute \ path/translate \ path/is_absolute \ diff --git a/core/src/xmake/os/cpdir.c b/core/src/xmake/os/cpdir.c new file mode 100755 index 000000000..349b8c1cb --- /dev/null +++ b/core/src/xmake/os/cpdir.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 cpdir.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "cpdir" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_cpdir(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the source and destination + tb_char_t const* src = luaL_checkstring(lua, 1); + tb_char_t const* dst = luaL_checkstring(lua, 2); + tb_check_return_val(src && dst, 0); + + // done os.cpdir(src, dst) + lua_pushboolean(lua, tb_directory_copy(src, dst)); + + // ok + return 1; +} diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c new file mode 100755 index 000000000..49ac4f062 --- /dev/null +++ b/core/src/xmake/os/cpfile.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 cpfile.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "cpfile" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_cpfile(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the source and destination + tb_char_t const* src = luaL_checkstring(lua, 1); + tb_char_t const* dst = luaL_checkstring(lua, 2); + tb_check_return_val(src && dst, 0); + + // done os.cpfile(src, dst) + lua_pushboolean(lua, tb_file_copy(src, dst)); + + // ok + return 1; +} diff --git a/core/src/xmake/os/exists.c b/core/src/xmake/os/exists.c new file mode 100755 index 000000000..797b1c7d0 --- /dev/null +++ b/core/src/xmake/os/exists.c @@ -0,0 +1,52 @@ +/*!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 exists.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "exists" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_exists(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); + + // done os.exists(path) + lua_pushboolean(lua, tb_file_info(path, tb_null)); + + // ok + return 1; +} diff --git a/core/src/xmake/os/isdir.c b/core/src/xmake/os/isdir.c new file mode 100755 index 000000000..d85468625 --- /dev/null +++ b/core/src/xmake/os/isdir.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 isdir.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "isdir" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_isdir(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); + + // done os.isdir(path) + tb_file_info_t info = {0}; + lua_pushboolean(lua, tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_DIRECTORY)); + + // ok + return 1; +} diff --git a/core/src/xmake/os/isfile.c b/core/src/xmake/os/isfile.c new file mode 100755 index 000000000..33fa69236 --- /dev/null +++ b/core/src/xmake/os/isfile.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 isfile.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "isfile" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_isfile(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); + + // done os.isfile(path) + tb_file_info_t info = {0}; + lua_pushboolean(lua, tb_file_info(path, &info) && (info.type == TB_FILE_TYPE_FILE)); + + // ok + return 1; +} diff --git a/core/src/xmake/os/mkdir.c b/core/src/xmake/os/mkdir.c new file mode 100755 index 000000000..9c22e15b9 --- /dev/null +++ b/core/src/xmake/os/mkdir.c @@ -0,0 +1,52 @@ +/*!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 mkdir.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "mkdir" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_mkdir(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); + + // done os.mkdir(path) + lua_pushboolean(lua, tb_directory_create(path)); + + // ok + return 1; +} diff --git a/core/src/xmake/os/prefix.h b/core/src/xmake/os/prefix.h new file mode 100644 index 000000000..68cf6ce0f --- /dev/null +++ b/core/src/xmake/os/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_OS_PREFIX_H +#define XM_OS_PREFIX_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "../prefix.h" +#include "luajit/luajit.h" + + +#endif + + diff --git a/core/src/xmake/os/rename.c b/core/src/xmake/os/rename.c new file mode 100755 index 000000000..b715b7d35 --- /dev/null +++ b/core/src/xmake/os/rename.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 rename.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "rename" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_rename(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // get the source and destination + tb_char_t const* src = luaL_checkstring(lua, 1); + tb_char_t const* dst = luaL_checkstring(lua, 2); + tb_check_return_val(src && dst, 0); + + // done os.rename(src, dst) + lua_pushboolean(lua, tb_file_rename(src, dst)); + + // ok + return 1; +} diff --git a/core/src/xmake/os/rmdir.c b/core/src/xmake/os/rmdir.c new file mode 100755 index 000000000..2daba8207 --- /dev/null +++ b/core/src/xmake/os/rmdir.c @@ -0,0 +1,52 @@ +/*!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 rmdir.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "rmdir" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_rmdir(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); + + // done os.rmdir(path) + lua_pushboolean(lua, tb_directory_remove(path)); + + // ok + return 1; +} diff --git a/core/src/xmake/os/rmfile.c b/core/src/xmake/os/rmfile.c new file mode 100755 index 000000000..0b6b96b8b --- /dev/null +++ b/core/src/xmake/os/rmfile.c @@ -0,0 +1,52 @@ +/*!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 rmfile.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "rmfile" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_rmfile(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); + + // done os.rmfile(path) + lua_pushboolean(lua, tb_file_remove(path)); + + // ok + return 1; +} |
