summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-23 00:46:52 +0800
committerruki <[email protected]>2022-07-23 00:46:52 +0800
commit84735799089b6232f1d6d61e103614fbc9e5d17e (patch)
tree397f324da4454013a1ecc26e5a61dd77f19c0893 /core/src
parent2882d942dd406f1443bf171424f06513c6f7d4e5 (diff)
add fwatcher add/remove
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/engine.c6
-rw-r--r--core/src/xmake/fwatcher/add.c64
-rw-r--r--core/src/xmake/fwatcher/remove.c62
-rw-r--r--core/src/xmake/fwatcher/wait.c54
-rw-r--r--core/src/xmake/makefile3
5 files changed, 189 insertions, 0 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index 9bd925a03..7c904fb38 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -247,6 +247,9 @@ tb_int_t xm_process_close(lua_State* lua);
// the fwatcher functions
tb_int_t xm_fwatcher_open(lua_State* lua);
+tb_int_t xm_fwatcher_add(lua_State* lua);
+tb_int_t xm_fwatcher_remove(lua_State* lua);
+tb_int_t xm_fwatcher_wait(lua_State* lua);
tb_int_t xm_fwatcher_close(lua_State* lua);
// the sandbox functions
@@ -496,6 +499,9 @@ static luaL_Reg const g_process_functions[] =
static luaL_Reg const g_fwatcher_functions[] =
{
{ "open", xm_fwatcher_open }
+, { "add", xm_fwatcher_add }
+, { "remove", xm_fwatcher_remove }
+, { "wait", xm_fwatcher_wait }
, { "close", xm_fwatcher_close }
, { tb_null, tb_null }
};
diff --git a/core/src/xmake/fwatcher/add.c b/core/src/xmake/fwatcher/add.c
new file mode 100644
index 000000000..a71ce83f1
--- /dev/null
+++ b/core/src/xmake/fwatcher/add.c
@@ -0,0 +1,64 @@
+/*!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 add.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "fwatcher.add"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
+// fwatcher.add(watchdir, recursion)
+tb_int_t xm_fwatcher_add(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get the fwatcher
+ tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1);
+ tb_check_return_val(fwatcher, 0);
+
+ // get watchdir
+ tb_char_t const* watchdir = luaL_checkstring(lua, 2);
+ tb_check_return_val(watchdir, 0);
+
+ // get recursion
+ tb_bool_t recursion = lua_toboolean(lua, 3);
+
+ // add watchdir
+ tb_bool_t ok = tb_fwatcher_add(fwatcher, watchdir, recursion);
+
+ // save result
+ lua_pushboolean(lua, ok);
+ return 1;
+}
diff --git a/core/src/xmake/fwatcher/remove.c b/core/src/xmake/fwatcher/remove.c
new file mode 100644
index 000000000..334e0a938
--- /dev/null
+++ b/core/src/xmake/fwatcher/remove.c
@@ -0,0 +1,62 @@
+/*!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 remove.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "fwatcher.remove"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
+// fwatcher.remove(watchdir)
+tb_int_t xm_fwatcher_remove(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get the fwatcher
+ tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1);
+ tb_check_return_val(fwatcher, 0);
+
+ // get watchdir
+ tb_char_t const* watchdir = luaL_checkstring(lua, 2);
+ tb_check_return_val(watchdir, 0);
+
+ // remove watchdir
+ tb_bool_t ok = tb_fwatcher_remove(fwatcher, watchdir);
+
+ // save result
+ lua_pushboolean(lua, ok);
+ return 1;
+}
+
diff --git a/core/src/xmake/fwatcher/wait.c b/core/src/xmake/fwatcher/wait.c
new file mode 100644
index 000000000..66bc0eed4
--- /dev/null
+++ b/core/src/xmake/fwatcher/wait.c
@@ -0,0 +1,54 @@
+/*!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 wait.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "fwatcher.wait"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+
+// fwatcher.wait(p)
+tb_int_t xm_fwatcher_wait(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get the fwatcher
+ tb_fwatcher_ref_t fwatcher = (tb_fwatcher_ref_t)xm_lua_topointer(lua, 1);
+ tb_check_return_val(fwatcher, 0);
+
+ // save result: ok
+ lua_pushboolean(lua, tb_true);
+ return 1;
+}
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index bccb7a2ba..5d017f0b0 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -116,6 +116,9 @@ xmake_C_FILES += \
process/kill \
process/close \
fwatcher/open \
+ fwatcher/add \
+ fwatcher/remove \
+ fwatcher/wait \
fwatcher/close \
sandbox/interactive \
semver/parse \