summaryrefslogtreecommitdiff
path: root/core/src/xmake/fwatcher/wait.c
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-23 00:52:43 +0800
committerruki <[email protected]>2022-07-23 00:52:43 +0800
commitbf3a38003ae5b93010dd0d8b70155bf1b1ee305a (patch)
treef924fe448c67d490acc0af6b180496efb6bb916e /core/src/xmake/fwatcher/wait.c
parent6de3254bd605d481b07b4f498b58c4896752089b (diff)
impl fwatcher.wait
Diffstat (limited to 'core/src/xmake/fwatcher/wait.c')
-rw-r--r--core/src/xmake/fwatcher/wait.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/core/src/xmake/fwatcher/wait.c b/core/src/xmake/fwatcher/wait.c
index 66bc0eed4..f8bbd6b78 100644
--- a/core/src/xmake/fwatcher/wait.c
+++ b/core/src/xmake/fwatcher/wait.c
@@ -48,7 +48,26 @@ tb_int_t xm_fwatcher_wait(lua_State* lua)
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);
+ // get the timeout
+ tb_long_t timeout = (tb_long_t)luaL_checkinteger(lua, 2);
+
+ // wait fwatcher event
+ tb_fwatcher_event_t event;
+ tb_long_t ok = tb_fwatcher_wait(fwatcher, &event, timeout);
+
+ // save result
+ lua_pushinteger(lua, ok);
+ if (ok > 0)
+ {
+ lua_newtable(lua);
+ lua_pushstring(lua, "path");
+ lua_pushstring(lua, event.filepath);
+ lua_settable(lua, -3);
+
+ lua_pushstring(lua, "type");
+ lua_pushinteger(lua, event.event);
+ lua_settable(lua, -3);
+ return 2;
+ }
return 1;
}