#
hs.httpserver.hsminweb.cgilua
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.
#
Submodules
#
API Overview
Variables - Configurable values
script_file script_path script_pdir script_vdir script_vpath tmp_path urlpath
Functions - API calls offered directly by the extension
contentheader doif doscript errorlog header htmlheader mkabsoluteurl mkurlpath print put redirect servervariable splitfirst splitonlast tmpfile tmpname
#
API Documentation
#
Variables
#
script_file
Signature | hs.httpserver.hsminweb.cgilua.script_file |
Type | Variable |
Description | The file name of the running script. Obtained from cgilua.script_path. |
Notes |
|
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 211 |
#
script_path
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 |
|
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 204 |
#
script_pdir
Signature | hs.httpserver.hsminweb.cgilua.script_pdir |
Type | Variable |
Description | The directory of the running script. Obtained from cgilua.script_path. |
Notes |
|
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 218 |
#
script_vdir
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 cgilua.script_vpath . Otherwise, this contains the directory portion of cgilua.script_vpath . |
Notes |
|
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 232 |
#
script_vpath
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 |
|
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 225 |
#
tmp_path
Signature | hs.httpserver.hsminweb.cgilua.tmp_path |
Type | Variable |
Description | The directory used by cgilua.tmpfile |
Notes | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 84 |
#
urlpath
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 |
|
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 239 |
#
Functions
#
contentheader
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 |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 297 |
#
doif
Signature | hs.httpserver.hsminweb.cgilua.doif(filename) -> results |
Type | Function |
Description | Executes a lua file (given by filepath) if it exists. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 276 |
#
doscript
Signature | hs.httpserver.hsminweb.cgilua.doscript(filename) -> results |
Type | Function |
Description | Executes a lua file (given by filepath). |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 247 |
#
errorlog
Signature | hs.httpserver.hsminweb.cgilua.errorlog(msg) -> nil |
Type | Function |
Description | Sends the message to the hs.httpserver.hsminweb log, tagged as an error. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 68 |
#
header
Signature | hs.httpserver.hsminweb.cgilua.header(key, value) -> none |
Type | Function |
Description | Sets the HTTP response header key to value |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 330 |
#
htmlheader
Signature | hs.httpserver.hsminweb.cgilua.htmlheader() -> none |
Type | Function |
Description | Sets the HTTP response type to "text/html" |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 314 |
#
mkabsoluteurl
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 |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 376 |
#
mkurlpath
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 |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 399 |
#
print
Signature | hs.httpserver.hsminweb.cgilua.print(...) -> nil |
Type | Function |
Description | Appends the given arguments to the response body. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 24 |
#
put
Signature | hs.httpserver.hsminweb.cgilua.put(...) -> nil |
Type | Function |
Description | Appends the given arguments to the response body. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 45 |
#
redirect
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 |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 347 |
#
servervariable
Signature | hs.httpserver.hsminweb.cgilua.servervariable(varname) -> string |
Type | Function |
Description | Returns a string with the value of the CGI environment variable corresponding to varname. |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 134 |
#
splitfirst
Signature | hs.httpserver.hsminweb.cgilua.splitfirst(path) -> path component, path remainder |
Type | Function |
Description | Returns two strings with the "first directory" and the "remaining path" of the given path string splitted on the first separator ("/" or ""). |
Parameters |
|
Returns |
|
Notes | None |
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 193 |
#
splitonlast
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 |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 178 |
#
tmpfile
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 |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 108 |
#
tmpname
Signature | hs.httpserver.hsminweb.cgilua.tmpname() -> string |
Type | Function |
Description | Returns a temporary file name used by cgilua.tmpfile . |
Parameters |
|
Returns |
|
Notes |
|
Examples | None |
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 91 |