lua-users home
lua-l archive

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


On Tue, Dec 6, 2011 at 5:34 AM, Axel Kittenberger <axkibe@gmail.com> wrote:
> There's no magic bullet to everything work together with everything.
> Maybe you could make some common API so you can plug in different
> reactors to handle that select()ish thing. But I don't see how getting
> all agree to that common API you suggest is better than to just all
> agree to the API of one event reactor. In case of using SDL Tim can
> sure shine some light on it, actually the same author as luvit did
> node-sdl, the SDL interface for node.

that's exactly what i found some time ago: not all interesting APIs
can give you a filedescriptor with the promise "mind your business,
i'll signal on this descriptor when something happens" like I/O does.

the only generic solution that i could imagine was making it (almost)
trivial to write helper threads: delegate all blocking calls to a
thread whose only job is to wait (blocked) until the call returns,
then signal to the main event loop.  the result is (obviously) my HTT
package, which includes a simple (but fast!) coroutine-based scheduler
so that the Lua side is easy to write too.

TL;DR: if the APIs are event-friendly, Lua makes it delightully easy
to write event-based code, by means of coroutines.  if the APIs are
strictly blocking, a slim C/threads adaptor is needed.

-- 
Javier