- Notifications
You must be signed in to change notification settings - Fork18
hoelzro/linotify
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A Lua binding for the Linux inotify library
To buildinotify.so, simply typemake.
All of the constants are contained in theinotify table returned byrequire. Constants are named after their counterparts in the C headerfile (for example:inotify.IN_ACCESS).
The only function to be found in the inotify table isinit, which returns aninotify handle.
init can optionally take a table a single argument. This table shouldcontain attributes for the inotify handle's creation. The supportedattributes are:
- blocking - If set to false, the I/O operations performed on thisinotify handle are non-blocking. Otherwise, they are blocking.
Inotify handles have a variety of methods:
Reads events from the handle, returning a table. Each element of the tableis itself a table, with the members of theinotify_event struct as itskeys and values (except for len). If the handle is in non-blocking mode andno events are available, an empty table is returned. If an error occurs,nil,the error message, and errno are returned.
Returns an iterator that reads events from the handle, one at a time.Each value yielded from the iterator is a table with the members of theinotify_event struct as its keys and values (except for len). If anerror occurs during reading, an error is thrown. If this method isrun on a handle in non-blocking mode, it will yield events until nomore events are available without blocking.
Closes the inotify event handle. This is done automatically on garbagecollection.
Adds a watch onevent_masks for the file located at path, returning awatch identifier on success, and the traditionalnil, error, errno tripleton error.event_masks is a variadic sequence of integer constants, takenfrominotify.IN_*.
All of the values inevent_masks are OR'd together but this can also be donemanually withbit.bor(). The following two examples are equivalent:
-- Event masks passed as argumentslocalhandle=inotify.init()localwd=handle:addwatch('/tmp/foo/',inotify.IN_CREATE,inotify.IN_MOVE)-- Event masks passed as a single, manually OR'd variablelocalhandle=inotify.init()localoptions=bit.bor(inotify.IN_CREATE,inotify.IN_MOVE)localwd=handle:addwatch('/tmp/foo/',options)
Removes the watch specified by watchid from the list of watches for thisinotify handle. Returns true on success, andnil, error, errno on error.
Returns the integer file descriptor for the given handle. Useful whenused in combination with an event loop.
Alias forhandle:fileno().
localinotify=require'inotify'localhandle=inotify.init()-- Watch for new files and renameslocalwd=handle:addwatch('/home/rob/',inotify.IN_CREATE,inotify.IN_MOVE)localevents=handle:read()for_,evinipairs(events)doprint(ev.name..' was created or renamed')end-- Done automatically on close, I think, but kept to be thoroughhandle:rmwatch(wd)handle:close()
localinotify=require'inotify'localhandle=inotify.init()-- Watch for new files and renameslocalwd=handle:addwatch('/home/rob/',inotify.IN_CREATE,inotify.IN_MOVE)forevinhandle:events()doprint(ev.name..' was created or renamed')end-- Done automatically on close, I think, but kept to be thoroughhandle:rmwatch(wd)handle:close()
As of version 0.3, the globalinotify table has been completely removed.You now need to handle the return value fromrequire, like so:
localinotify=require'inotify'
About
Inotify bindings for Lua
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors8
Uh oh!
There was an error while loading.Please reload this page.