lua-users home
lua-l archive

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


On Jan 25, 2008, at 6:01 AM, Eric Tetz wrote:

I need to write a web interface to a database, and was considering Lua
('cause it's fun ^_^). A quick Google turns up Kepler, which judging by
the website alone seems to be fairly mature.

The web part of Kepler is very much in flux at the moment...

Kepler's LuaSQL[1] will help with database connectivity though:

Here is an example using DB.lua[2], a wrapper around LuaSQL:

local DB = require( 'DB' )
local aDB = DB( 'mysql://localhost/test' )

for aContact in aDB( 'select * from contact where email like %s order by 1', 'maria%' ) do
    print(, )

Are there any other mature ones? How robust/complete/usable are these compared to something like PHP?

Never used PHP, so cannot comment on that, but... there are quiet a few Web libraries around.

For example, HTTP.lua [3] is very similar in spirit to[4].

Canonical 'HelloWorld.lua' example:

local HTTP = require( 'HTTP' )

HTTP[ '/hello(%a*)' ] = function( aName ) return 'Hello ' .. ( aName or 'world' ) end


Run 'HelloWorld.lua' under tcpserver [5] or such:

% tcpserver 0 1080 lua HelloWorld.lua

% telnet localhost 1080
Connected to localhost.
Escape character is '^]'.
GET /hello HTTP/1.0

HTTP/1.1 200 OK
Date: Fri, 25 Jan 2008 12:25:26 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 11
Connection: close

Hello world

That said... Lua is very much a 'bring your own' kind of place... in other words... not many batteries are included out-of-the-box... usually your best bet is to assemble the different parts you need by yourself and get going...

"Lua gives you the power; you build the mechanisms."
-- Roberto Ierusalimschy, Programming in Lua, December 2003