CGILua
CGILua 5.0
Reference guide

home · headers · contents · pre-processing · variables · error handling · behavior · auxiliar · encoding · index

Headers

cgilua.contentheader (type, subtype)

Sends a Content-type header with the given values of type and sub-type.
Both arguments are strings: type is the header type; subtype is the header sub-type.
Returns nothing.

cgilua.htmlheader ()

Sends the header of a HTML file (Content-type: text/html followed by two line-feeds).
Returns nothing.

cgilua.locationheader (url)

Sends the header to force a redirection to the given URL.
The argument must be a string.
Returns nothing.

cgilua.redirect (url, args)

Sends the header to force a redirection to the given URL adding the parameters in table args to the new URL.
The first argument (url) is the URL the browser should be redirected to; the second one (args) is an optional table which could have pairs name = value that will be encoded to form a valid URL (see function cgilua.urlcode.encodetable).
Returns nothing.

cgilua.header (header, value)

Sends a generic header. This function should not be used to generate a Content-type nor a Location header.
Both arguments are strings: header is the name of the header; value is its value.
Returns nothing.

Content generation

cgilua.mkabsoluteurl (path)

Creates an absolute URL containing the given URL path.
Returns nothing.

cgilua.mkurlpath (script [, args])

Creates an URL path to be used as a link to a CGILua script.
Returns nothing.

cgilua.put (string)

Sends the given string to the client.
Returns nothing.

Pre-processing

cgilua.includehtml (filename)

Pre-processes the given HTML file and sends the result to the client.
Returns nothing.

cgilua.preprocess (filename)

Equivalent to includehtml but sends the HTML header before the pre-processed file.
Returns nothing.

cgilua.prep.setcompatmode (boolean)

Turns on or off the compatibility mode. Turning it on will make the translator understands the old expression fields and code fields structures, now obsolete.
Returns nothing.

cgilua.prep.setoutfunc (outfuncname)

Defines the output function. The translator will write calls to the function with the given name.
Returns nothing.

cgilua.prep.translate (string)

Creates a string with Lua code that reproduces the given string executing the Lua chunks or expressions inside it.
Returns a string with the resulting code.

CGILua's variables

cgilua.script_file

The file name of the running script. Obtained from cgilua.script_path.

cgilua.script_path

The complete path of the running script. This variable is usually the same as the CGI environment variable PATH_TRANSLATED.

cgilua.script_pdir

The directory of the running script. Obtained from cgilua.script_path.

cgilua.script_vdir

The virtual directory of the running script. Obtained from cgilua.script_vpath.

cgilua.script_vpath

The complete virtual path of the running script. Equivalent to CGI environment variable PATH_INFO.

cgilua.servervariable (varname)

Returns a string with the value of a CGI environment variable whose name is indicated by the argument (varname).

cgilua.urlpath

The name of the script. Equivalent to CGI environment variable SCRIPT_NAME.

Error Handling

cgilua.errorlog (string)

Sends the given string to the error log file.
Returns nothing.

cgilua.seterrorhandler (func)

Sets errorhandler function. This function is called by Lua when an error occurs. It receives the error message generated by Lua and it is resposible for the final message which should be returned.
Returns nothing.

cgilua.seterroroutput (func)

Sets the erroroutput function. This function is called to generate the error output.
Returns nothing.

CGILua's behavior

cgilua.addscripthandler (ext, func)

Defines a function to pre-process a certain type of files. The default configuration uses cgilua.doscript to process Lua scripts (.lua files) and cgilua.preprocess to process HTML templates (.lp files).
Returns nothing.

cgilua.addclosefunction (func)

Defines a function to be called after the script execution.
Returns nothing.

cgilua.addopenfunction (func)

Defines a function to be called before the script execution.
Returns nothing.

cgilua.buildplainhandler (type, subtype)

Creates a script handler that sends the given header and the plain file requested. The Content-type header is formed by the two arguments; the created function will receive a filename as its only argument and will return the given filename untouched.
Returns a function.

cgilua.buildprocesshandler (type, subtype)

Creates a script handler that sends the given header and the processed file requested. The Content-type header is formed by the two arguments; the created function will receive a filename as its only argument and will return the given filename pre-processed by the function cgilua.includehtml.
Returns a function.

cgilua.setlibdir (dir)

Sets CGILua's default libraries directory. This value will be used to build the current LUA_PATH used by the redefined require function.
Returns nothing.

cgilua.setmaxfilesize (size)

Sets the maximum size for each "uploaded" file (in bytes). This value is bounded by the maximum "total" input size (see cgilua.setmaxinput). This function only takes efect if used before POST data is processed, therefore its use in scripts are useless.
Returns nothing.

cgilua.setmaxinput (size)

Sets the maximum "total" input size allowed (in bytes). This function only takes efect if used before POST data is processed, therefore its use in scripts are useless.
Returns nothing.

Auxiliar functions

cgilua.doscript (path)

Executes the given file. Raises an error if it occurs. In case of success, returns the values returned by the execution.

cgilua.pack (...)

Returns a new table with all its arguments stored in it.

cgilua.splitpath (path)

Returns two strings with the "directory" and "file" parts of the given path.

URL encoding functions

cgilua.urlcode.encodetable (table)

URL-encode the elements of a table creating a string to be used in a URL for passing data/parameters to another script.
Returns a string representing the argument table.

cgilua.urlcode.escape (string)

URL-encode a string.
Returns the encoded string.

cgilua.urlcode.insertfield (args, name, value)

Adds the given value to the field name in table args. If the field already has a value, it is transformed into a table with the previous (at index 1) and the new value (at index 2). Other values will be added at the end of the array-part of the table.
Returns nothing.

cgilua.urlcode.parsequery (query, args)

Parse URL-encoded request data. This could be the query part of the script URL or URL-encoded post data. Each decoded name = value pair is inserted into table args.
Returns nothing.

cgilua.urlcode.unescape (string)

URL-decodes a string.
Returns the decoded string.

Alphabetic Index

addclosefunction
addopenfunction
addscripthandler
buildplainhandler
buildprocesshandler
contentheader
doscript
encodetable (urlcode)
errorlog
escape (urlcode)
header
htmlheader
includehtml
insertfield (urlcode)
locationheader
mkabsoluteurl
mkurlpath
pack
parsequery (urlcode)
preprocess
prep
put
redirect
script_file
script_path
script_pdir
script_vdir
script_vpath
servervariable
setcompatmode (prep)
seterrorhandler
seterroroutput
setlibdir
setmaxfilesize
setmaxinput
setoutfunc (prep)
splitpath
urlcode
unescape (urlcode)
urlpath

$Id: reference.html,v 1.18 2004/12/15 15:11:48 tomas Exp $