Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Inotify bindings for Lua

License

NotificationsYou must be signed in to change notification settings

hoelzro/linotify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Lua binding for the Linux inotify library

Building

To buildinotify.so, simply typemake.

Usage

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:

handle:read()

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.

handle:events()

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.

handle:close()

Closes the inotify event handle. This is done automatically on garbagecollection.

handle:addwatch(path, [event_masks...])

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)

handle:rmwatch(watchid)

Removes the watch specified by watchid from the list of watches for thisinotify handle. Returns true on success, andnil, error, errno on error.

handle:fileno()

Returns the integer file descriptor for the given handle. Useful whenused in combination with an event loop.

handle:getfd()

Alias forhandle:fileno().

Example

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()

Example (Iterator)

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()

No More Global Table

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

Stars

Watchers

Forks

Packages

No packages published

Contributors8


[8]ページ先頭

©2009-2025 Movatter.jp