From 0260cf0c08efd022be56cb81c460b932a27f4fa8 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 28 Jul 2022 22:32:32 +0800 Subject: pass events to watch scripts --- xmake/plugins/watch/main.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xmake/plugins/watch/main.lua b/xmake/plugins/watch/main.lua index f7b628d0c..e5fadad3b 100644 --- a/xmake/plugins/watch/main.lua +++ b/xmake/plugins/watch/main.lua @@ -54,7 +54,7 @@ function _add_watchdirs() end -- run command -function _run_command() +function _run_command(events) try { function () @@ -72,7 +72,7 @@ function _run_command() elseif scriptfile and os.isfile(scriptfile) and path.extension(scriptfile) == ".lua" then local script = import(path.basename(scriptfile), {rootdir = path.directory(scriptfile), anonymous = true}) - script() + script(events) elseif os.isfile(os.projectfile()) then local argv = {"build", "-y"} if option.get("verbose") then @@ -111,6 +111,7 @@ function main() -- do watch local count = 0 + local events = {} while true do local ok, event = fwatcher.wait(300) if ok > 0 then @@ -123,9 +124,10 @@ function main() status = "deleted" end print(event.path, status) + table.insert(events, event) count = count + 1 elseif count > 0 then - _run_command() + _run_command(events) count = 0 end end -- cgit v1.3.1