Giter Site home page Giter Site logo

lualibevent's Introduction

LualibEvent
-----------

usage:

include "levent"

module functions:
=================

levent.newbase()
----------------
Creates a new 'base' object.  All other objects are created in the context of a base object.

levent.fdfromfile(fileobject)
----------------------
Given a standard Lua file object, this function returns the corresponding file descriptor as an integer.  To be used for the.  Should be associated with the file object's metatable, ie:

	setfdaccessor (getmetatable(io.input()), fdfromfile)

levent.setfdaccessor (metatable, fdaccessor)
-------------------------------------
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.

levent.fdfromvalue (value)
-------------------
Given a value, this function uses the previously assigned fdaccessors to return the file descriptor of the underlying file.


base object methods:
====================

base:newevent (file, callback, evtype)
---------------------------------
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.

base:newevbuf (file, readcb, writecb, errorcb)
-----------------------------------------
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 function is called when the read buffer has at least <lowwater> bytes readable.

The writecb function is called when the write buffer has less than <lowwater> bytes on it.

base:loop ([<homany>])
--------------------
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.


event object methods
====================

event:start()
-------------
Activates the event object.

event:stop()
------------
Deactivates the event object.

event:delete()
--------------
Kills the event object, releasing the C structure and making the Lua object invalid.


buffered event object methods
=============================

bufevent:start()
-------------
Activates the buffered event object.

bufevent:stop()
---------------
Deactivates the event object.

bufevent:read([size])
---------------------
Reads up to <size> bytes from the input buffer.  If size is nil or missing, it reads the whole buffer.

bufevent:readline()
-------------------
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).

bufevent:write (data)
---------------------
Writes the given data to the ouput buffer.

lualibevent's People

Contributors

javierguerragiraldez avatar

Watchers

James Cloos avatar Chanjun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.