lua-users home
lua-l archive

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


On Mon, Mar 22, 2010 at 1:06 PM, Valerio Schiavoni
<valerio.schiavoni@gmail.com> wrote:
> the twisted python framework provides a very elegant mechanism to do
> asynchronous programming, through so called 'deferred'.
> See doc here: http://twistedmatrix.com/documents/current/core/howto/defer.html
>
> I was wondering if there's support for this programming style in the
> language itself (looking at the doc I don't think so), or if
> something similar is provided by Lua frameworks.

Lua doesn't need language support for this, any more than python does.

A deferred is just an object returned to a caller that has an internal
list of callbacks. The caller adds callback functions to it, and the
callee, at some future time, causes the callbacks to be triggered with
a value. twisted's deferred has some complex but useful chaining
behaviours associated with callbacks that could be implemented, but
its not much code not matter how you slice it.

But deferreds aren't useful without event loop integration, so that's
what you really want, the event framework.

And that I don't know much about in lua, sorry. Copas is coroutine
based, but you could use it, there are also various bindings to
libevent and/or /dev/epoll you might be able to use, depending on your
platform. you'll find them if you google.

Cheers,
Sam