brimworks / lua-ev

Lua integration with libev.
MIT License
225 stars 55 forks source link

Can't watch directories #2

Closed daurnimator closed 13 years ago

daurnimator commented 14 years ago

You can't seem to watch directories:

ev = require"ev"
do -- Add getfd function to file namespace
    local ok , posix = pcall ( require , "posix" )
    if ok then
        getmetatable ( io.stdin ).__index.getfd = posix.fileno
    else
        error ( "Unable to watch file descriptors" )
    end
end
loop=ev.Loop.new()
fd=io.open(".")
io = ev.IO.new ( print , fd:getfd() , ev.READ +ev.WRITE )
io:start(loop)
loop:loop()
print("Should never get here")
brimworks commented 14 years ago

Hello,

I'm a bit confused, since you titled this as "You can't watch directories", but the code sample is trying to monitor stdin (if I'm reading it correctly), but stdin is not a directory. FWIW, some of the test code in lua-ev tests that registering for stdin for WRITE's works:

https://github.com/brimworks/lua-ev/blob/master/test/test_ev_io.lua

Note that the code hard-codes a 1 for stdin.

daurnimator commented 14 years ago

Its trying to watch the current working directory (cwd) (via io.open(".") ) on my computer getfd is returning 4 for it.

daurnimator commented 14 years ago

Crap, didn't mean to close the bug.

brimworks commented 13 years ago

It sounds like you want a "stat" watcher (which unfortunately isn't implemented yet, but adding support for this in lua-ev should be trivial):

http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_stat_code_did_the_file_attri

Cheers, -Brian

brimworks commented 13 years ago

Hi daurnimator,

Did you want the stat() watcher implemented? Or did you want something else? If this request is no longer valid, then I would like to close the issue.

Thanks, -Brian

brimworks commented 13 years ago

Oops, I just realized that this issue is closed. Sorry for the spam.