Provides support functions in the cgilua
module for Hammerspoon Minimal Web Server Lua templates.
This file contains functions which attempt to mimic as closely as possible the functions available to lua template files in the CGILua module provided by the Kepler Project at http://keplerproject.github.io/cgilua/index.html
The goal of this file is to provide most of the same functionality that CGILua does for template files. Any differences in the results or errors are most likely due to this code and you should direct all error reports or code change suggestions to the Hammerspoon GitHub repository.
Do not include this file directly in your Lua templates. This library is provided automatically in the cgilua
table (module) in Lua template web server files. This submodule will only work from within that environment and should not be used in any other code.
Signature | hs.httpserver.hsminweb.cgilua.script_file |
---|---|
Type | Variable |
Description | The file name of the running script. Obtained from cgilua.script_path. Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.script_path |
---|---|
Type | Variable |
Description | The system path of the running script. Equivalent to the CGI environment variable SCRIPT_FILENAME. Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.script_pdir |
---|---|
Type | Variable |
Description | The directory of the running script. Obtained from cgilua.script_path. Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.script_vdir |
---|---|
Type | Variable |
Description | If PATH_INFO represents a directory (i.e. ends with "/"), then this is equal to Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.script_vpath |
---|---|
Type | Variable |
Description | Equivalent to the CGI environment variable PATH_INFO or "/", if no PATH_INFO is set. Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.tmp_path |
---|---|
Type | Variable |
Description | The directory used by This variable contains the location where temporary files should be created. Defaults to the user's temporary directory as returned by |
Signature | hs.httpserver.hsminweb.cgilua.urlpath |
---|---|
Type | Variable |
Description | The name of the script as requested in the URL. Equivalent to the CGI environment variable SCRIPT_NAME. Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.contentheader(maintype, subtype) -> none |
---|---|
Type | Function |
Description | Sets the HTTP response type for the content being generated to maintype/subtype. Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.doif(filename) -> results |
---|---|
Type | Function |
Description | Executes a lua file (given by filepath) if it exists. Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.doscript(filename) -> results |
---|---|
Type | Function |
Description | Executes a lua file (given by filepath). Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.errorlog(msg) -> nil |
---|---|
Type | Function |
Description | Sends the message to the Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.header(key, value) -> none |
---|---|
Type | Function |
Description | Sets the HTTP response header Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.htmlheader() -> none |
---|---|
Type | Function |
Description | Sets the HTTP response type to "text/html" Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.mkabsoluteurl(uri) -> string |
---|---|
Type | Function |
Description | Returns an absolute URL for the given URI by prepending the path with the scheme, hostname, and port of this web server. Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.mkurlpath(uri, [args]) -> string |
---|---|
Type | Function |
Description | Creates a full document URI from a partial URI, including query arguments if present. Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.print(...) -> nil |
---|---|
Type | Function |
Description | Appends the given arguments to the response body. Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.put(...) -> nil |
---|---|
Type | Function |
Description | Appends the given arguments to the response body. Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.redirect(url, [args]) -> none |
---|---|
Type | Function |
Description | Sends the headers to force a redirection to the given URL adding the parameters in table args to the new URL. Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.servervariable(varname) -> string |
---|---|
Type | Function |
Description | Returns a string with the value of the CGI environment variable correspoding to varname. Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.splitfirst(path) -> path component, path remainder |
---|---|
Type | Function |
Description | Returns two strings with the "first directory" and the "remaining paht" of the given path string splitted on the first separator ("/" or "\"). Parameters:
Returns:
|
Signature | hs.httpserver.hsminweb.cgilua.splitonlast(path) -> directory, file |
---|---|
Type | Function |
Description | Returns two strings with the "directory path" and "file" parts of the given path string splitted on the last separator ("/" or "\"). Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.tmpfile([dir], [namefunction]) -> file[, err] |
---|---|
Type | Function |
Description | Returns the file handle to a temporary file for writing, or nil and an error message if the file could not be created for any reason. Parameters:
Returns:
Notes:
|
Signature | hs.httpserver.hsminweb.cgilua.tmpname() -> string |
---|---|
Type | Function |
Description | Returns a temporary file name used by Parameters:
Returns:
Notes:
|