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:
Read | prepare file for reading |
Write | prepare file for writing |
Events | listen 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.
DeleteEvent | Vnode was removed. |
WriteEvent | Data contents changed. |
ExtendEvent | Size increased. |
AttribEvent | Attributes changed. |
LinkEvent | Link count changed. |
RenameEvent | Vnode was renamed. |
RevokeEvent | Vnode access was revoked. |
NoneEvent | No 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.