lua-users home
lua-l archive

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


On Sat, Apr 30, 2011 at 10:27 AM, Dirk Laurie <dpl@sun.ac.za> wrote:
> Or I could finally start reading the Kepler project documentation.
> If someone can speak glowingly of how useful that turned out to be
> after the initial learning curve, I may well do just that.

Something more specialized than the full Kepler stack is Orbiter [1].
It's designed specifically to write little Lua servers that run on the
same machine as the browser, or within a _trusted_ intranet.  It looks
and feels very much like Orbit, except that it generates (X)HTML using
a LOM representation.

Or you can use it just as a way to intercept HTTP requests and
directly output the response as text:

-- hello.lua
local orbiter = require 'orbiter'

local hello = orbiter.new()

function hello:index(web)
    return ([[
        <html><body>
        <h2>Hello, Lua!</h2>
        <img src='/images/logo.gif'/>
        Lua memory used is %5.0f kB
        </body></html>
    ]]):format(collectgarbage 'count')
end

hello:dispatch_get(hello.index,'/','/index.html')
hello:dispatch_static '/resources/images/.+'

hello:run(...)

It also has useful HTML-generating functions that can relieve some of the pain:

> = html.table {{'A','B'},{'C','D'}}
<table>
  <tr>
    <td>A</td>
    <td>B</td>
  </tr>
  <tr>
    <td>C</td>
    <td>D</td>
  </tr>
</table>

It only depends on LuaSocket, so it's relatively easy to get working.

steve d.

[1] https://github.com/stevedonovan/Orbiter