views:

687

answers:

8

I come from a Java and PHP background to build web applications.

Has anyone used Lua before to build a web applications?

Question: If so, what are the pro's & con's of using Lua versus PHP or Java for a web application? (e.g. web server support, performance, code maintenance, etc).

+3  A: 

There are quite a few projects using Lua for web development.

For example, Nanoki, an HTTP and wiki engine developed in pure Lua.

Or Sputnik, which is build on top of Kepler.

That said, Lua is very much a, hmmm, "do it yourself" kind of environment.

PA
+5  A: 

I am using Lua right now to build a web application! Whatever happened to software developers that "do it yourself" got a bad name - too lazy, weaned on bloated megabytes of support libraries, or what? In reality, as others have pointed out, there is decent support, just not on the scale of Python, say. Lua is by far the fastest scripting language (especially with www.luajit.org around), and much, much cleaner as a language design than any other in its league out there. This is vital for long-term maintenance.

For those using lighttpd as their webserver (me included), the added bonus is that the full power of Lua is available for mod_magnet scripts, useful for synchronous request handling/rewriting-on-steroids.

asmarino
There's nothing inherently wrong with "doing it yourself", but if you have to implement everything yourself, then you will have to spend a lot of time on those things, and as we all know, time is money. There's also the issue that you need to consider many security issues that the libraries handle for you - but in exchange, you are able to react immediately if there IS a bug, which isn't always the case with a library - you'd often have to wait for it to be updated.
Michael Madsen
Lua's design is cleaner? I gave up on Lua tutorial after I found out that it is similar to Python but the syntax is not as readable. Btw, Google is making a C++ implementation of Python which should run 5x as fast.
Hamish Grubijan
[Lua vs Python](http://stackoverflow.com/questions/356160/which-game-scripting-language-is-better-to-use-lua-or-python). Film at 11.
Norman Ramsey
+4  A: 

As others mentioned Lua is "do it yourself" kind of environment. Also it is very fast and quite memory efficient compared to Perl/PHP/Python/Ruby especially if you are using LuaJIT. And it is very easy to integrate with C/C++ code. Usually these points are irrelevant for a typical web application where performance is usually restricted by database. Also where you don't really care about C/C++ integration and where you don't really want to do things yourself but rather you want to build on top of existing frameworks. For this reason I don't think Lua is a good fit for a typical web applications. At the same time there are some niche applications where Lua shines. For example our company specializes at building high performance HTTP servers used for adserving. So what we are using is our own HTTP server written from scratch in C++ which integrates Lua as a scripting language for our business logic. This allows us to do customization of the business logic in Lua quickly compared to what we had to do if it was pure C++. At the same time we always have an option to do performance critical parts in C++. If we were using any other scripting language we are positive it would be slower, it would use more memory and generally would be harder to integrate with C++ code. At the same time we don't really care much about loss of extensive library support were we using other scripting languages as the domain we are working in is quite specialized so usually those libraries are irrelevant for it anyway.

Ilya Martynov
+2  A: 

For the record, "do it yourself" doesn't necessarily imply "write it yourself", even though one could.

The more common scenario is "choose it yourself", in other words, pick the exact libraries you need for the task at hand.

PA
+2  A: 

Pros: fast, small, elegant, easy to make your own binding to a C library.

Cons: sometimes you have to write your own libraries for things you would get for free in Python.

http://luanova.org/ has a number of good posts on web development in Lua.

qaramazov
+3  A: 

I have programmed a few websites with Lua. The first one was a raid planner for my World of Warcraft guild (that's often how you start programming in Lua...). I used mod_lua with an alpha version of Apache 2.4 for that. Two others were small contests sites for customers, developed with WSAPI, Nginx, Spawn-fcgi and Orbit. This setup is damn fast, faster than mod_lua and anything else I have seen. The pages would display instantly as if they were in cache ! The experience was very pleasant and Lua makes you quickly productive. But you better be well organized. Lua is missing a lot of batteries when it comes to web development, so you often have to implement your own and it can become messy. So I suggest you plan what you will need before you start. I used my own Lua "ORM" with MySQL and a forked version of Lua Pages for the templates. Have a look here if you want to give Lua+Wsapi+Nginx a try : http://mascarenhas.github.com/2009/10/24/wsapi-nginx-fcgi.html I think it is the best setup.

golgote
A: 

lighttpd and mod_magnet are really great platform, but I recommend that you first take a look at Kepler Project. It's a quite great beginning.

You can take your PHP/Java background useful.

Cacilhas
A: 

Haserl is a program that lets you embed lua code in your html, php style.

http://haserl.sourceforge.net/