lubyk logo

Lubyk documentation

File

A simple OS file wrapper which can return file descriptors for read/write/events.

.new (path, mode)

Create a new file with the given mode. Mode values are:

Readprepare file for reading
Writeprepare file for writing
Eventslisten to file changes

:readLine ()

Read a line. Returns a string or nil on EOF.

:write (str)

Write a string to a file.

Events

:events (flags)

Listen for OS notifications on file changes. The flags determine which notifications are watched. You can combine flags by adding them. The function returns the notified event as a number.

DeleteEventVnode was removed.
WriteEventData contents changed.
ExtendEventSize increased.
AttribEventAttributes changed.
LinkEventLink count changed.
RenameEventVnode was renamed.
RevokeEventVnode access was revoked.
NoneEventNo specific vnode event: to test for EVFILT_READ activation.

Usage example:

local lens = require 'lens'
local File = lens.File
local DELETE, WRITE = File.DeleteEvent, File.WriteEvent
f = lens.File('foo.lua', File.Events)
while true do
  local ev = f:events(DELETE + WRITE)
  if ev == DELETE then
    print(f.path, 'deleted')
    break
  else
    print(f.path, File.EventName[ev])
  end
end

.eventMap

Translate an event number to a table with keys representing active flags.