Module cgilua.main
CGILua library.
Info:
- Release: $Id: cgilua.lua,v 1.85 2009/06/28 22:42:34 tomas Exp $
Functions
| servervariable (name) | gets an enviroment variable |
| setstatus (st) | set response status |
| addopenfunction (f) | Adds a function to be executed before the script. |
| addclosefunction (f) | Adds a function to be executed after the script. |
| addscripthandler (file_extension, func) | Add a script handler. |
| getscripthandler (path) | Obtains the handler corresponding to the given script path. |
| handle (path) | Execute the given path with the corresponding handler. |
| seterrorhandler (f) | Sets "errorhandler" function This function is called by Lua when an error occurs. |
| seterroroutput (f) | Defines the "erroroutput" function This function is called to generate the error output. |
| tmpfile (dir, namefunction) | Returns a temporary file in a directory using a name generator |
| handlelp (filename, env) | Preprocess the content of a mixed HTML file and output a complete HTML document ( a 'Content-type' header is inserted before the preprocessed HTML ) |
| buildplainhandler (type, subtype) | Builds a handler that sends a header and the contents of the given file. |
| buildprocesshandler (type, subtype) | Builds a handler that sends a header and the processed file. |
| mkurlpath (script, args) | Create an URL path to be used as a link to a CGILua script |
| mkabsoluteurl (path, protocol) | Create an absolute URL containing the given URL path |
| splitonlast (path) | Extract the "directory" and "file" parts of a path |
| splitonfirst (path) | Extracts the first and remaining parts of a path |
| doscript (filename) | Execute a script If an error is found, Lua's error handler is called and this function does not return |
| doif (filename) | Execute the file if there is no "file error". |
| setmaxinput (nbytes) | Set the maximum "total" input size allowed (in bytes) |
| setmaxfilesize (nbytes) | Set the maximum size for an "uploaded" file (in bytes) Might be less or equal than L.maxinput. |
| tmpname () | Default function for temporary names |
| header (header, value) | Sends a header. |
| contentheader (type, subtype) | Sends a Content-type header. |
| htmlheader () | Sends the HTTP header "text/html". |
| redirect (url, args) | Sends an HTTP header redirecting the browser to another URL |
| errorlog (msg, level) | Primitive error output function |
| print (...) | Converts all its arguments to strings before sending them to the server. |
| put (s) | Function 'put' sends its arguments (basically strings of HTML text) to the server Its basic implementation is to use Lua function 'write', which writes each of its arguments (strings or numbers) to file _OUTPUT (a file handle initialized with the file descriptor for stdout) |
| _geterrorhandler (msg) | Returns the current errorhandler |
| pcall (f) | Executes a function using the CGILua error handler. |
| L.getparams () | Define variables and build the cgilua.POST and cgilua.GET tables. |
| L.buildhandlers () | Builds the default handler table from cgilua.mime |
| L.default_handler (filename) | Default handler. |
| L.close () | Close function. |
| L.open () | Open function. |
| L.reset () | Resets CGILua's state. |
| cgilua.main (enviroment, response) | Request processing. |
Tables
| Response | Build Response table |
| L._script_handlers | Stores all script handlers and the file extensions used to identify them. |
| L._close_functions | Stores all close functions in order they are set. |
| L._open_functions | Stores all open functions in order they are set. |
Fields
| tmp_path | Default path for temporary files |
| L.default_errorhandler | Internal state variables. |
Functions
- servervariable (name)
-
gets an enviroment variable
Parameters:
- name
- setstatus (st)
-
set response status
Parameters:
- st
- addopenfunction (f)
-
Adds a function to be executed before the script.
Parameters:
- f Function to be registered.
- addclosefunction (f)
-
Adds a function to be executed after the script.
Parameters:
- f Function to be registered.
- addscripthandler (file_extension, func)
-
Add a script handler.
Parameters:
- file_extension String with the lower-case extension of the script.
- func Function to handle this kind of scripts.
- getscripthandler (path)
-
Obtains the handler corresponding to the given script path.
Parameters:
- path String with a script path.
Returns:
-
Function that handles it or nil.
- handle (path)
-
Execute the given path with the corresponding handler.
Parameters:
- path String with a script path.
Returns:
-
The returned values from the script.
- seterrorhandler (f)
-
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.
Parameters:
- f Function.
- seterroroutput (f)
-
Defines the "erroroutput" function
This function is called to generate the error output.
Parameters:
- f Function.
- tmpfile (dir, namefunction)
-
Returns a temporary file in a directory using a name generator
Parameters:
- dir Base directory for the temporary file
- namefunction Name generator function
- handlelp (filename, env)
-
Preprocess the content of a mixed HTML file and output a complete
HTML document ( a 'Content-type' header is inserted before the
preprocessed HTML )
Parameters:
- filename String with the name of the file to be processed.
- env Optional environment
- buildplainhandler (type, subtype)
-
Builds a handler that sends a header and the contents of the given file.
Sends the contents of the file to the output without processing it.
Parameters:
- type String with the type of the header.
- subtype String with the subtype of the header.
Returns:
-
Function (which receives a filename as argument) that produces
the header and copies the content of the given file.
- buildprocesshandler (type, subtype)
-
Builds a handler that sends a header and the processed file.
Processes the file as a Lua Page.
Parameters:
- type String with the type of the header.
- subtype String with the subtype of the header.
Returns:
-
Function (which receives a filename as argument) that produces
the header and processes the given file.
- mkurlpath (script, args)
-
Create an URL path to be used as a link to a CGILua script
Parameters:
- script String with the name of the script.
- args Table with arguments to script (optional).
Returns:
-
String in URL format.
- mkabsoluteurl (path, protocol)
-
Create an absolute URL containing the given URL path
Parameters:
- path String with the path.
- protocol String with the name of the protocol (default = "http").
Returns:
-
String in URL format.
- splitonlast (path)
-
Extract the "directory" and "file" parts of a path
Parameters:
- path String with a path.
Returns:
- String with the directory part.
- String with the file part.
- splitonfirst (path)
-
Extracts the first and remaining parts of a path
Parameters:
- path
Returns:
- String with the extracted part.
- String with the remaining path.
- doscript (filename)
-
Execute a script
If an error is found, Lua's error handler is called and this function
does not return
Parameters:
- filename String with the name of the file to be processed.
Returns:
-
The result of the execution of the file.
- doif (filename)
-
Execute the file if there is no "file error".
If an error is found, and it is not a "file error", Lua 'error'
is called and this function does not return
Parameters:
- filename String with the name of the file to be processed.
Returns:
- The result of the execution of the file or nil (in case the file does not exists or if it cannot be opened).
- It could return an error message if the file cannot be opened.
- setmaxinput (nbytes)
-
Set the maximum "total" input size allowed (in bytes)
Parameters:
- nbytes Number of the maximum size (in bytes) of the whole POST data.
- setmaxfilesize (nbytes)
-
Set the maximum size for an "uploaded" file (in bytes)
Might be less or equal than L.maxinput.
Parameters:
- nbytes Number of the maximum size (in bytes) of a file.
- tmpname ()
-
Default function for temporary names
Returns:
-
a temporay name using os.tmpname
- header (header, value)
-
Sends a header.
Parameters:
- header String with the header.
- value String with the corresponding value.
- contentheader (type, subtype)
-
Sends a Content-type header.
Parameters:
- type String with the type of the header.
- subtype String with the subtype of the header.
- htmlheader ()
- Sends the HTTP header "text/html".
- redirect (url, args)
-
Sends an HTTP header redirecting the browser to another URL
Parameters:
- url String with the URL.
- args Table with the arguments (optional).
- errorlog (msg, level)
-
Primitive error output function
Parameters:
- msg String (or number) with the message.
- level String with the error level (optional).
- print (...)
-
Converts all its arguments to strings before sending them to the server.
Parameters:
- ...
- put (s)
-
Function 'put' sends its arguments (basically strings of HTML text)
to the server
Its basic implementation is to use Lua function 'write', which writes
each of its arguments (strings or numbers) to file _OUTPUT (a file
handle initialized with the file descriptor for stdout)
Parameters:
- s String (or number) with output.
- _geterrorhandler (msg)
-
Returns the current errorhandler
Parameters:
- msg
- pcall (f)
-
Executes a function using the CGILua error handler.
Parameters:
- f Function to be called.
- L.getparams ()
- Define variables and build the cgilua.POST and cgilua.GET tables.
- L.buildhandlers ()
- Builds the default handler table from cgilua.mime
- L.default_handler (filename)
-
Default handler.
Sends the contents of the file to the output without processing it.
This relies in the browser being able to discover the content type
which is not reliable.
Parameters:
- filename String with the name of the file.
- L.close ()
- Close function.
- L.open ()
- Open function. Call all defined open-functions in the order they were created.
- L.reset ()
- Resets CGILua's state.
- cgilua.main (enviroment, response)
-
Request processing.
env: enviroment variables
response: the response object
Parameters:
- enviroment
- response validade response parameter
Tables
- Response
-
Build Response table
Fields:
- contenttype
- errorlog
- header
- value
- L._script_handlers
- Stores all script handlers and the file extensions used to identify them. Loads the default
- L._close_functions
- Stores all close functions in order they are set.
- L._open_functions
- Stores all open functions in order they are set.