lua-users home
lua-l archive

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




On Sat, Jan 25, 2020 at 8:47 AM Michal Kottman <michal.kottman@gmail.com> wrote:
On Sat, Jan 25, 2020, 11:50 AM Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
On Sat, 25 Jan 2020 at 07:08, Sean Conner <sean@conman.org> wrote:
>
> > The C library for Cqueues contains a proper event driven library written
> > ground up by William Ahern for use in Lua. It works with poll, epoll,
> > kqueues and whatever-the-heck Solaris uses. It *doesn't* support IOCP for
> > Windows. If we can add IOCP support then we have a superb socket library
> > for all platforms. I found a library stuffed inside another project that
> > claimed to be an epoll wrapper for IOCP. I can dig the info up if you like.
>

>   I want to keep the event driver module from the network module.  Granted,
> event drivers are mostly used for network applications, but there are times
> when you need them sans networking, such as dealing with character devices
> like serial ports or terminal IO.
>
>   A module like Cqueues is more of a framework than a library.  If there was
> a separate event module, then frameworks like Cqueues, lua-ev or turbo could
> gain access to the best underlying event structure for a given operating
> system. 

Hi, libuv is a hugely popular library in this area due to its use in
Node JS. 
You guys beat me to mentioning Libuv.   

This entire discussion reminds me of https://xkcd.com/927/ ("Standards").

That said I do enjoy the multiplatform libuv library, since it covers a large spectrum of what I'd consider "batteries" in the context of this discussion. A static build of Luvit+SQLite3 is my "tool of choice" - single static binary "distribution" that I can use both on my desktop and ARM machines like Raspberry Pi and Android.

The main downside for me is that it forces the "callback hell" programming model. Fortunately the "coro-fs" (and other) libraries by creationix make use of Lua coroutines for a more pleasant experience.
 
When I was looking for a web stack I briefly looked at luvit. Duarnimator mentioned his lua-http library based on cqueues and warned me of the callback pattern (that I later experienced with node.js). The beauty of cqueues is that it seamlessly integrates with Lua co-routines. I won't attempt an example in the 3 1/2 minutes I have to write this, but you simply write a function and cqueues handles everything. You don't need to deal asynchronous calls. It's like having a built in async/await pattern. So me - a nincompoop - was able to write a web tool that was so fast the hockey statistics website I was using blocked my IP Address and I had to throttle it.

cqueues is *brilliant* and the lua-http modules are awesome. The caveat to using cqueues is the same as using any event engine: If you have an error, it happens opaquely in the engine and it can often tear the entire application down. That's why node.js production code ALWAYS needs a restart service.

But, if you're using lua-http for simple web requests or a webserver, it's very easy and straight foward, albeit a little low level. 

Russ