summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2022-03-09 23:25:38 +0800
committerruki <[email protected]>2022-03-09 23:25:38 +0800
commitfa2e4a9a5f21a8819beafb99a85652d83b7e5429 (patch)
tree8ae328914c4dd54012e0cf6cc013547acaa4caeb /core/src
parent4eb65435961776fbefcc11ed774b778532c2c8dd (diff)
improve path.directory
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/engine.c2
-rw-r--r--core/src/xmake/makefile1
-rw-r--r--core/src/xmake/path/absolute.c4
-rw-r--r--core/src/xmake/path/directory.c51
-rw-r--r--core/src/xmake/path/relative.c2
5 files changed, 55 insertions, 5 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index efc89977c..2f4efd60c 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -173,6 +173,7 @@ tb_int_t xm_io_poller_wait(lua_State* lua);
tb_int_t xm_path_relative(lua_State* lua);
tb_int_t xm_path_absolute(lua_State* lua);
tb_int_t xm_path_translate(lua_State* lua);
+tb_int_t xm_path_directory(lua_State* lua);
tb_int_t xm_path_is_absolute(lua_State* lua);
// the hash functions
@@ -366,6 +367,7 @@ static luaL_Reg const g_path_functions[] =
{ "relative", xm_path_relative }
, { "absolute", xm_path_absolute }
, { "translate", xm_path_translate }
+, { "directory", xm_path_directory }
, { "is_absolute", xm_path_is_absolute }
, { tb_null, tb_null }
};
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index c85696f1e..d25a12a9b 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -92,6 +92,7 @@ xmake_C_FILES += \
path/relative \
path/absolute \
path/translate \
+ path/directory \
path/is_absolute \
hash/uuid4 \
hash/sha256 \
diff --git a/core/src/xmake/path/absolute.c b/core/src/xmake/path/absolute.c
index b4baac03d..d8489d25f 100644
--- a/core/src/xmake/path/absolute.c
+++ b/core/src/xmake/path/absolute.c
@@ -45,10 +45,8 @@ tb_int_t xm_path_absolute(lua_State* lua)
// get the root
tb_char_t const* root = luaL_optstring(lua, 2, tb_null);
- // done path:absolute(root)
+ // do path:absolute(root)
tb_char_t data[TB_PATH_MAXN];
lua_pushstring(lua, tb_path_absolute_to(root, path, data, sizeof(data) - 1));
-
- // ok
return 1;
}
diff --git a/core/src/xmake/path/directory.c b/core/src/xmake/path/directory.c
new file mode 100644
index 000000000..b8ec7476d
--- /dev/null
+++ b/core/src/xmake/path/directory.c
@@ -0,0 +1,51 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file directory.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "directory"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_path_directory(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);
+
+ // do path:directory()
+ tb_char_t data[TB_PATH_MAXN];
+ tb_char_t const* dir = tb_path_directory(path, data, sizeof(data));
+ if (dir) lua_pushstring(lua, dir);
+ else lua_pushnil(lua);
+ return 1;
+}
diff --git a/core/src/xmake/path/relative.c b/core/src/xmake/path/relative.c
index 782f0f635..f64667747 100644
--- a/core/src/xmake/path/relative.c
+++ b/core/src/xmake/path/relative.c
@@ -48,7 +48,5 @@ tb_int_t xm_path_relative(lua_State* lua)
// done path:relative(root)
tb_char_t data[TB_PATH_MAXN];
lua_pushstring(lua, tb_path_relative_to(root, path, data, sizeof(data) - 1));
-
- // ok
return 1;
}