Overview
CGILua includes a set of external libraries that allows the handling
of Cookies, Serialized Data and Sessions. To use these libraries just
require
them in your CGILua config.lua
file.
Cookies
cgilua.cookies.get (name)
- Gets the value of the cookie with the given
name
.
Returns a string with the value of the cookie. cgilua.cookies.set (name, value[, options])
- Sets the
value
of the cookie with a givenname
. The optional tableoptions
is used togive the values of the cookies attributes: expires, path, domain, secure. This function should be called before the HTTP headers are sent and before any output is generated, so it must not be used inside a Lua Page.
This function sends a cookie with the response. If you need to create a cookie inside the generated response or if the cookie needs to be set inside the client, usecgilua.cookies.sethtml
instead.
Returns nothing. cgilua.cookies.sethtml (name, value[, options])
- Sets the
value
of the cookie with a givenname
. The optional tableoptions
is used to give the values of the cookies attributes: expires, path, domain, secure.
This function generates a<meta>
HTML element so it should be called after the<head>
HTML tag and before the corresponding</head>
.
This function creates a cookie in the client, if you need to send the cookie with the response usecgilua.cookies.set
instead.
Returns nothing. cgilua.cookies.delete (name[, options])
- Deletes a cookie with a given
name
(setting its value toxxx
). This function should be called before the HTTP headers are sent and before any output is generated.
Returns nothing.
Serialize
cgilua.serialize (table, outfunc[, indent[, prefix]])
- Serializes a
table
usingoutfunc
as the function to be used to generate the output;indent
as an optional string with the indentation pattern;prefix
as an optional string with the indentation prefix (it is used to store the actual indentation between the recursion calls).
Some restrictions must be noted: values of types function and userdata are not serialized; tables with cycles are not serialized.
Returns nothing.
Session
cgilua.session.close ()
- Closes the user session. Saves all data in
cgilua.session.data
to the storage system being used (usually the filesystem). This function should be called after the end of the script execution. A recommended way to ensure that is to use addclosefunction in the configuration file.
Returns nothing. cgilua.session.data
- Table which holds the user session data.
cgilua.session.delete (id)
- Deletes a session. The argument
id
is the session identifier.
Returns nothing. cgilua.session.load (id)
- Loads data from a session. The argument
id
is the session identifier.
Returns a table with session data ornil
followed by an error message. cgilua.session.new ()
- Creates a new session identifier.
Returns the new session identifier. cgilua.session.open ()
- Opens the user session. Creates the table
cgilua.session.data
. This function should be called just before the execution of the script, but after the processing of the request's headers. A recommended way to ensure that is to use addopenfunction in the configuration file.
Returns nothing. cgilua.session.save (id, data)
- Saves
data
to a session with anid
.
Returns nothing. cgilua.session.setsessiondir (path)
- Defines the session temporary directory.
Argument
path
is a string with the new directory.
Returns nothing.