This site is a reference to the version 3.2 of CGILua.
The current version (5.0) is maintained by the Kepler Project.
For the reference of previous versions, please refer to the old homepage.



What is CGILua?

CGILua is a tool for developing dynamic HTML pages and manipulating input data from forms. It uses the interpreted language Lua for codifying the commands which will be executed at the time the page is viewed.

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

Technically, CGILua is a CGI program which runs on the server and receives files to be interpreted. CGILua acts as intermediary for scripts being submitted to the HTTP server, doing all the basic processing, like decoding input data. It also offers additional resources, such as automatic handling of uploaded files, cryptography functions, state-keeping facilities, and database access.

Characteristics

The chief characteristics are:

Please refer to the published articles described in More information for a deeper presentation of CGILua's characteristics and its differences to other similar tools.

CGILua scripts

Documents can be created in CGILua in two ways: one is by writing pure Lua scripts, in which the contents are entirely made up of valid sentences in the Lua language; the other is by writing HTML template files, in which Lua instructions and CGILua directives are inserted into conventional HTML documents.

Deciding which type of script to use is really a matter of taste, but a good guideline is to choose according to the type of page which is to be generated. The two ways are equally easy to write, but one or the other can be more convenient depending on what functionality is desired. If the page is to be graphically sophisticated, with intensive use of HTML tags, it is probably better to use an HTML template. It is thus possible to disassociate the development of the graphic layout from the code to be written, so that the structure of the page can be made with the help of an HTML editor. If the page is simple in terms of its HTML structure but requires a substantial amount of internal processing, it can be more convenient to write the commands directly, making a Lua script. The advantage here lies in the clarity of the script's purposes. If the generation of HTML tags is just a secondary objective in the processing of the script, then it is reasonable that the Lua code should be the content of the script itself instead of being dispersed as comments in HTML.

In fact, these two script types can be used together: separate pure Lua files can be written to carry out specific tasks, and these modules can be called by mixed HTML files. These HTML files centralize the processing and are responsible for the layout of the pages.

CGILua recognizes the kind of usage by the extension name of the file which is submitted. For pure Lua scripts the extension to be used is .lua, and for HTML template files the extension .html or .htm should be used. The section Usage contains a detailed description of each of these types.

Where to start

To build websites using CGILua it is necessary to have a minimal knowledge of HTML, CGI, and Lua. However, the potential user can be encouraged by knowing that this minimal amount is really very little. Those who already know HTML should be able to learn CGI and Lua in a very short time. After a few examples are studied, simple scripts can be written - for instance those which generate pages using data taken from input forms.

This manual is a reference to the tool CGILua. For those who want to develop websites using this tool, the first step is to read sections Usage and CGILua Reference. When more sophisticated needs arise, sections Lua Reference and Libraries should be consulted, since they describe useful resources used in development.

The following references provide further information on HTML, CGI, and Lua:

HTML http://www.w3.org/pub/WWW/MarkUp/Wilbur/
http://www2.wvitcoe.wvnet.edu/~sbolt/html3/
CGI http://www.w3.org/pub/WWW/CGI/
Lua http://www.tecgraf.puc-rio.br/lua

More information

There is a mailing list at cgilua-l. Questions and suggestions can be posted there. To subscribe to this list, send a mail to listproc@tecgraf.puc-rio.br with "subscribe cgilua-l YOUR-NAME" in the body of the message (not in the subject). To unsubscribe, send "unsubscribe cgilua-l" to listproc@tecgraf.puc-rio.br.

Other documentation is avaliable:

Papers:

Anna Hester, Renato Borges and Roberto Ierusalimschy.
Building flexible and extensible Web applications with Lua.
Journal of Universal Computer Science, 4(9):748-762, 1998.
(also in Webnet '98 World Conference of the WWW, Internet, & Intranet, pages 427-432, Orlando, FL, USA, Nov. 1998. Top paper.)
Anna Hester, Renato Borges and Roberto Ierusalimschy.
CGILua: A multi-paradigmatic tool for creating dynamic WWW pages.
in XI Simpósio Brasileiro de Engenharia de Software, páginas 347-360, Fortaleza, CE, 1997.

Contributors

CGILua has been developed completely at Tecgraf/PUC-Rio and some libraries were developed with sponsorship of PETROBRAS.

We would like to thank the following groups or companies for their continuous feedback and contribution:

We would also like to thank Martin Hester for the original version of this manual in english.

Copyright

Copyright © 1995-1999 TeCGraf/PUC-Rio

Created and implemented by Anna Magdalena Hester, Renato Ferreira Borges and Roberto Ierusalimschy. All rights reserved.

Permission is granted, without written agreement, license, or royalties, to use, copy, and distribute the CGILua software and accompanying documentation for any purpose, subject to the following conditions:

The above copyright and this permission must appear in all copies of the software or in substantial extracts of the software or its documentation.

The names CGILua and HTML-Lua cannot be used to designate any modified form of the software which is not generated by the authors hereon. However, such modified versions must indicate clearly that they are based on the use of this CGILua software, as stated in the preceding item.

The authors do not provide any guarantees whatsoever including, but not restricted to, guarantees implied by commercial use and adaptation to personal use. The software hereby distributed is in its original form without modifications, and the authors are not obliged to supply maintenance, support, upgrades, improvements, or modifications. TeCGraf/PUC-Rio or the authors cannot be held responsible by any person for any damage whether direct, indirect, special, incidental, consequential, or accidental arising from the use of the software or its documentation.

Download

Latest version: 3.2
Available CGILua versions:
Binaries for the platform:

Install

Step 0

You need a Web server! CGILua is a server-side tool and as such it needs a Web server (HTTP server) to run. Many servers are available in the market, and they are not hard to install and configure. All the HTTP servers support CGI scripts, so the choice of which server to use to construct a WWW site using CGILua is a question of preference. Evidently, it is recommended that producing sites (open to visitors) be backed by high-performance servers, such as
Apache (UNIXs) Microsoft Internet Information Service (Windows NT), and Netscape FastTrack (UNIXs), For those who intend to use CGILua in stand-alone computers, we recommend that the server is as "light" as possible, because performance is not critical, and a large-scale server may consume an exaggerated amount of machine resources. For Windows 95, a good choice is the Personal Web Server, included with the Microsoft Front Page package. For the UNIX environment, especially Linux, a good choice is the Apache server.

Unix

CGILua needs to be installed in a directory which is identified in the server as being a directory with permission to execute CGI scripts. This identification varies a lot from server to server. For the servers NCSA/Apache, for example, this means adding the following line to the file srm.conf:

  
  ScriptAlias /scripts/   /home/anna/cgilua/  

This line associates the directory /home/anna/cgilua/ with a virtual directory with permission to execute scripts with the name /scripts/.

The following UNIX command opens the gzipped package TAR for CGILua distribution:

  
  gunzip -c <pacote-cgilua> | tar -xvf -  

Once the distribution package has been expanded and installed in a directory with permission to execute CGI scripts, the tool is ready for use.

If CGILua is to be used by more than one user (multi-user installation), it is advisable to activate the tool's capacity to "change user" according to the owner of the script being run. This is one of the security mechanisms offered by CGILua, and we recommend using it in environments where it is desirable to alter the privileges of script execution according to the user who has written it.

To activate this mechanism it is necessary that the owner of the executable file cgilua is the root user, and also that the executable has permission to "set userid".

  
  [/home/anna/cgilua]> su  
  Password: ****  
    
  [/home/anna/cgilua]> chown root cgilua cgilua.conf/cgilua.lua  
  [/home/anna/cgilua]> chmod u+s cgilua  

Note that the file cgilua.conf/cgilua.lua has also had its owner changed. This is necessary because, as a security measure, the tool checks internally to see whether the executable code and the main configuration file have the same owner.

Even though the executable code has owner root, a CGILua script will never be executed with the privileges of this user, unless the owner of the script being executed is the root user.

If this "change user" mechanism is not activated, any CGILua script will be executed with the user rights with which the HTTP server is executed, usually corresponding to the user nobody or www.

Windows 9x/NT

CGILua needs to be installed in a directory which is identified in the server as being a directory with permission to execute CGI scripts. On the Microsoft servers IIS and Personal Web Server, this means installing the tool in a virtual directory with permission to "EXECUTE" (the "READ" permission should not be enabled). In the standard installation of these two servers, a virtual directory is already created with the name "scripts" and exactly the right permissions. Thus to install CGILua it is only necessary to expand the CGILua zip directly into the physical directory which corresponds to /scripts/ (for example C:\InetPub\scripts).

Other servers use a different terminology to denote directories with permission to execute CGI scripts. In Website, for example, the term "Standard CGI" is used to denote virtual directories with such permission.

The installation procedure consists simply in opening the zip file (preserving information in subdirectories) in a directory with permission to execute CGI scripts. Once this is done, the tool is ready to be used.

Testing

Without any script

The most basic method for testing the installation is to execute CGILua without specifying any script to be interpreted. For example, if the tool is installed in the virtual directory /scripts/, the URL to be used would be:

In UNIX environments:

  
  http://wwwserver/scripts/cgilua   

In Windows 95/NT environments:

  
  http://wwwserver/scripts/cgilua.exe   

The result should be a CGILua message "No CGILua script specified in url.", or else something like "Unable to start file /usr/local/etc/httpd/htdocs/index.html". If, instead, a "Server Error" type of message is generated, then the installation was not successful. Probably the server configuration is incorrect.

With the script test.html

This script can be used to test the functioning of CGILua. It can be copied to a directory served by the Web server (normally C:\InetPub\wwwroot\ or ~/public_html), and a browser can be used to execute it via CGILua.

The URL to be used should be something like:

In UNIX environments:
  
  Physical path:  /home/anna/public_html/test.html   
  URL:            http://servidor/scripts/cgilua/~anna/test.html   

In Windows 95/NT environments:
  
  Physical path:  C:\InetPub\wwwroot\test.html   
  URL:          http://servidor/scripts/cgilua.exe/test.html   

The correct functioning of the script can be checked by the link: test


Last update in 28/05/1999