File: onchange.lua

package info (click to toggle)
lua-luv 1.51.0-1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,464 kB
  • sloc: ansic: 6,996; makefile: 74; sh: 33
file content (28 lines) | stat: -rw-r--r-- 682 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
local uv = require('luv')

if #arg==0 then
    print(string.format("Usage: %s <command> <file1> [file2 ...]",arg[0]));
    return
end

for i=1,#arg do
    local fse = uv.new_fs_event()
    assert(uv.fs_event_start(fse,arg[i],{
        --"watch_entry"=true,"stat"=true,
        recursive=true
    },function (err,fname,status)
        if(err) then
            print("Error "..err)
        else
            print(string.format('Change detected in %s',
                uv.fs_event_getpath(fse)))
            for k,v in pairs(status) do
                print(k,v)
            end
            print('file changed:'..(fname and fname or ''))
        end
    end))

end

uv.run('default')