lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Cary O'Brien wrote:

> This sort of event-driven interface is available in TCL (which also
> has plain old select) .  It is called "fileevent".  You can set up
> callbacks to run when the file is readable or writeable.  This lets
> you set up multi-threaded (sort of) programs without threads.  TCL
> handles the select loop.  This originally came out of the requirements
> of running TCL under X (i.e. TK), but I use it a lot for server
> programs that have to manage multiple clients.
> > Or another one: simulate an event queue.  You register fds.  The next-
> > event function selects if no events are present and then builds events
> > on the select result.  (This version may get problems because it
> > caches results.)
> >
> > The question is: is it easier to export select and make the register/wait
> > in the highlevel or to implement it completely in C?
> >
> The fileevent interface and having the select loop in the interpreter
> allows some incredible things to happen.
> I have one very, very complex server implemented with fileevents [1].
> I can start TCL from the command line, start the server from this
> TCL session, and since the interpreter multiplexes both console and
> application IO for me I can examine global data structures and run
> functions from the command line WHILE THE SERVER IS RUNNING.
> The event-driven framework in TCL is way beyond any other scripting
> language, including Python and Perl.
> But this is a lot of work to add to LUA probably.

I don't really think that this would be too difficult: Actually, I wrote
such a thing some time ago, although it is not very clean and very C
file descriptor centric, and so I wouldn't give it away right now. But
essentially, it is a generic C representation of an event source (for
now, file descriptor and timer) and a main loop consisting of repetitive
calls to an event dispatcher. And it's easy for the main loop to invoke
e.g. Lua callbacks.