This is linotify, a binding for Linux's inotify library to Lua.

--- Building ---

To build inotify.so, simply chdir to the file this README is in, and
type 'make'.

--- Usage ---

All of the constants are contained in the global inotify table.
Constants are named after their counterparts in the C header file
(ex. inotify.IN_ACCESS).

The only function to be found in the inotify table is init, which
takes no arguments and returns an inotify handle.  Ex.

Inotify handles have a variety of methods:

handle:read()
    Reads events from the handle, returning a table.  Each element of the table
    is itself a table, with the members of the inotify_event struct as its
    keys and values (except for len).  If an error occurs, nil, the error
    message, and errno are returned.

handle:close()
    Closes the inotify event handle.  This is done automatically on garbage
    collection.

handle:addwatch(path, [event_masks...])
    Adds a watch on event_masks for the file located at path, returning a
    watch identifier on success, and the traditional nil, error, errno triplet
    on error.  event_masks is a variadic sequence of integer constants, taken
    from inotify.IN_*.  All of the values in event_masks are OR'd together.

handle:rmwatch(watchid)
    Removes the watch specified by watchid from the list of watches for this
    inotify handle.  Returns true on success, and nil, error, errno on error.

Here's a usage example:

local inotify = require 'inotify'
local handle = inotify.init()
-- watch my home for new files and renames
local wd = handle:addwatch('/home/rob/', inotify.IN_CREATE, inotify.IN_MOVE)
-- or handle:addwatch('/home/rob', bit.bor(inotify.IN_CREATE, inotify.IN_MOVE))

local events = handle:read()

for _, ev in ipairs(events) do
    print(ev.name .. ' was created or renamed')
end

handle:rmwatch(wd) -- done automatically when you close, I think, but kept to be thorough
handle:close()
