summaryrefslogtreecommitdiff
path: root/core/src
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
parent6de3254bd605d481b07b4f498b58c4896752089b (diff)
impl fwatcher.wait
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/fwatcher/wait.c23
-rw-r--r--core/src/xmake/io/poller_wait.c17
2 files changed, 37 insertions, 3 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;
}
diff --git a/core/src/xmake/io/poller_wait.c b/core/src/xmake/io/poller_wait.c
index 008f1366e..7389faacf 100644
--- a/core/src/xmake/io/poller_wait.c
+++ b/core/src/xmake/io/poller_wait.c
@@ -54,7 +54,22 @@ static tb_void_t xm_io_poller_event(tb_poller_ref_t poller, tb_poller_object_ref
if (priv) lua_pushstring(g_lua, (tb_char_t const*)priv);
else lua_pushlightuserdata(g_lua, object->ref.ptr);
lua_rawseti(g_lua, -2, 2);
- lua_pushinteger(g_lua, (tb_int_t)events);
+ if (object->type == TB_POLLER_OBJECT_FWATCHER)
+ {
+ lua_newtable(g_lua);
+ tb_fwatcher_event_t* event = (tb_fwatcher_event_t*)events;
+ if (event)
+ {
+ lua_pushstring(g_lua, "path");
+ lua_pushstring(g_lua, event->filepath);
+ lua_settable(g_lua, -3);
+
+ lua_pushstring(g_lua, "type");
+ lua_pushinteger(g_lua, event->event);
+ lua_settable(g_lua, -3);
+ }
+ }
+ else lua_pushinteger(g_lua, (tb_int_t)events);
lua_rawseti(g_lua, -2, 3);
lua_rawseti(g_lua, -2, ++g_events_count);
}