What is mod_lua?

mod_lua is a Apache module for developing dynamic HTML pages in Lua language. It uses the interpreted language Lua for codifying the commands which will be executed at the time the Apache events ocurr, e.g. get a page.

mod_lua is simple but powerful, and it enables complex tasks to be carried out with minimum effort. The most frequent type of applications built with mod_lua are WWW information systems based on external data (such as databases) and WWW gateways to existing systems.

In addition, mod_lua facilitates the development of other Apache modules in Lua. The CGI enviroment for Lua scripts is only an use for this.

Why use mod_lua?

Security. The other scripts languages (e.g. PHP, Perl) have many protections, buts fail on critics points, for example PHP and Perl use the C stack for interpret the script, and enable a stack overflow attack. Security is a point stressed in mod_lua, however yet is not perfect! See weaknesses topic from sandbox project.

Speed. Lua language is fast, and mod_lua implementation try to be efficient.

Nice language. Lua language has very simple syntax and constructs. Even non-programmers can learn enough to write Lua scripts in short time.

Documentation

mod_lua diretives for Apache
Handler enviroment
Official packages
FAQ
TODO

History

The first version of mod_lua was developed by Roman Vanicek under GPL license. It was a simple and functional module for Apache 1.3.

The current project is mantained by Michel Machado and has the intent... Rio De Janeiro, 6 of March of 2003.

There are already implementations to integrate Lua to web. However, good ideas present in mod_php (http://www.php.net/) and mod_perl (http://perl.apache.org/) were ignored. Those implementations are inadequate for an expressive production environment.

The first stage of the project consisted of allowing mod_lua to work in any stage of Apache request chain to increase its functionality. This was the best idea inspired by mod_perl.

mod_lua 1,1 integrates Apache 1.3.x and Lua 5.0.

It's possible to make lots of application with mod_lua. It lacks a module analogous to Apache:PerlRun to emulate the CGI environment for Lua scripts. It's addressed by ...

The following features remain to be implemented:

- Session.
- Integration with Regular Expressions, data base etc. libs

Project's structure

The module is coded in C and fits all Apache's hooks. Then a Lua State is instanced to take care of all Lua handlers.

It's the Lua handles that create more flexible and productive environments for all scripts.

C Language Style

The C code follows the coding style recommended by Apache HTTP Server Project (http://httpd.apache.org/dev/styleguide.html).

To compile Lua

Modify config file:

LOADLIB= -DUSE_DLOPEN=1
DLLIB= -ldl
MYLDFLAGS= -Wl,-E
INSTALL_ROOT= /usr
#INSTALL_EXEC= cp
#INSTALL_DATA= cp
INSTALL_EXEC= install -m 0755
INSTALL_DATA= install -m 0644

Author

Michel Machado

mod_lua copyright and license

mod_lua is licensed under the GNU General Public License (GPL).

Copyright (c) 2001 XTG Systems.
Copyright (c) 2003 Digirati.

Download

click here

References

Books

Writing Apache Modules with Perl and C. Lincoln & Doug MacEachern. O'Reilly. ISBN: 1-56592-567-X.

Web sites

Apache HTTP server
The Lua programming language