-
Notifications
You must be signed in to change notification settings - Fork 4
Home
usage:
include "levent"
Creates a new ‘base’ object. All other objects are created in the context of a base object.
Given a standard Lua file object, this function returns the corresponding file descriptor as an integer. Should be associated with the file object’s metatable, ie:
setfdaccessor (getmetatable(io.input()), fdfromfile)
Associates a function (fdaccessor) with the an object type, caracterized by its metatable. fdaccessor must be a function that returns the file descriptor of an object with the given metatable.
Given a value, this function uses the previously assigned (to value ’s metatable) fdaccessor to return the file descriptor of the underlying file.
Creates a new event object. file must be an integer (a file descriptor) or any object whose metatable is registered with a corresponding fdaccessor. evtype is a string like "r"
, "w"
or "rw"
, to indicate if the callback function should be called when the file is readable, writeable, or on both events.
The callback function is called with the file as the sole parameter.
Creates a ‘buffered event’ object. This object adds buffers for reading and writing the given file. Each buffer has a ‘lowwater’ and ‘highwater’ threshold.
The readcb(file)
function is called when the read buffer has at least < lowwater > bytes readable.
The writecb(file)
function is called when the write buffer has less than < lowwater > bytes on it.
This is the central loop of an event-driven program. If the howmany
parameter is nil or missing, this function won’t finish while there’s at least one event object active. If howmany
is 0, it will service pending events if any and return immediately. If howmany
is > 0, it will wait until the next event is fired, service it, and return immediately.
h2.2event object methods
Activates the event object.
Deactivates the event object.
Kills the event object, releasing the C structure and making the Lua object invalid.
Activates the buffered event object.
Deactivates the event object.
Reads up to size
bytes from the input buffer. If size is nil
or missing, it reads the whole buffer.
Reads a single line from the input buffer. If there’s no linebreak already in the buffer, returns nil
and doesn’t drain the buffer (maybe the next event there will be a whole line available).
Writes the given data to the output buffer.