lua-users home
lua-l archive

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


On Tue, Feb 8, 2011 at 6:41 AM, steve donovan <steve.j.donovan@gmail.com> wrote:
On Mon, Feb 7, 2011 at 10:21 PM, Petite Abeille
<petite.abeille@gmail.com> wrote:
> While we are at it, here are my very own 500 lines worth of dinky HTTP server... and it doesn't even need LuaSocket :P

Man, that is such cool code that I don't understand how it actually
works ;)  In particular, how does it do the basic networking layer?

> HTTP[ '/' ] = function() return 'Hello world' end HTTP()

Nice notation..

In a similar vein, I knocked out a (quick and dirty) route-based [*] framework prototype last year. If you're interested, see http://0branch.com/project/lundu/lundu-0.0.1.tgz

The tarball includes a simple site as proof of concept. Here's an excerpt,

---8<---
get["/f"]   = function()
  return template("form.tmpl.html", {
    title = "Form"
  })
end

post["/p"]  = function(posted)
  return template("form_reply.tmpl.html", {
    query = posted.query,
    title = "Reply"
  })
end
---8<---

To test it out, just run "lua t1.lua" -- you'll need xavante installed.

The templating engine is trivial at present, though I envisage (as with Dancer) the ability to drop in a third party implementation.

Any feedback is welcome!

Best,
Marc

[*] See http://perldancer.org/ and http://www.sinatrarb.com/ for more info.