lua-users home
lua-l archive

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

After starting the luvit project over a year ago, I've learned a lot
about lua and the ecosystem.  Recently I've decided that cloning the
node.js environment doesn't have as much value as I initially

So, I'm starting a new effort that's many small modular parts.  These
are usable from stock lua or luajit.  The lua modules will be usable
from luvit and other similar platforms like lev and Richard's luv if


Moonslice is a pure lua library that provides a nice web framework and
continuable based io.  If you haven't seen continuables, they are a
cross between the node/luvit callback style and promises.  For
example, a contunuable based API for reading a file as a single chunk
would look like:

    fs.readFile(filename, encoding, otherOptions)(function (err, data)
      if err then return handleError(err) end
      -- Do something with data

Initially this looks just like the callback style, except there is an
extra call in there.  This makes it infinitely more flexible.  For
example, you could store the continuable in a variable and use that in
some control-flow library.

    )(function (err, data1, data2)
      -- both files are done, here is the data

Also using coroutines and a sugar library I wrote called fiber, you
can do faux blocking from within a coroutine.

    local fd = await(, "r"))
    local chunk = await(, 0, 1000))

Moonslice also has a web application interface that's built on top of
this model.  Apps are written in *sgi (jsgi psgi, ...) style.  A web
app is nothing more than a function that's given the request and
responds with a function call.

    local function app (request, respond)
      print(request.method, request.url.path)
      respond(200, { ["Content-Type"] = "text/plain" }, "Hello World\n")

Middleware modules are simply functions that accept an app function
and return a new one.  So stacking libraries is super simple and fast.
 The web module provides only one function that takes a web app
function and converts it to a tcp onConnection function that handles
all the HTTP protocol mess.  This way it's decoupled from the actual
server implementation.  So anyone wanting to interface with a "web"
app can either implement a wrapper around the wsgi style function or
provide a stream interface instance to the onConnection function.


Luv is minimal binding to libuv for lua.  Nothing more.  It exposes
libuv as a bunch of functions that work on uv_handle_t instances.  It
will be callback based since libuv is callback based.  Other
interfaces can easily be built on top.  Once done, I intend to pull
this back into luvit itself.  I'm hoping other projects can use it as
well.  It's the most minimal abstraction for libuv possible and many
platforms/frameworks can be built on top of it.


This is the http_parser bindings used in luvit today broken out into
it's own module.  In my moonslice-luv project I have a modified
version of web and continuable that uses LUV and LHTTP_PARSER to make
super fast http servers in stock lua.

*I know Richard Hundt beat me to the "luv" name, and one of us will
rename if it becomes a problem.  Personally I think his project is
more than just libuv bindings since it adds 0mq integration and a
fancy coroutine based interface on top.

-Tim Caswell