Support functions for the CGILua compatibility module for including and translating Lua template pages into Lua code for execution within the Hammerspoon environment to provide dynamic content for http requests.
The most commonly used function is likely to be cgilua.lp.include, which allows including a template driven file during rendering so that common code can be reused more easily. While passing in your own environment table for upvalues is possible, this is not recommended for general use because the default environment passed to each included file ensures that all server variables and the CGILua compatibility functions are available with the same names, and any new non-local (i.e. "global") variable defined are shared with the calling environment and not shared with the Hammerspoon global environment.
If your template file requires the ability to create variables in the Hammerspoon global environment, access the global environment directly through _G
.
Note that the above considerations only apply to creating new "global" variables. Any currently defined global variables (for example, the hs
table where Hammerspoon module functions are stored) are available within the template file as long as no local or CGILua environment variable shares the same name (e.g. _G["hs"]
and hs
refer to the same table.
See the documentation for the cgilua.lp.include for more information.
Signature | hs.httpserver.hsminweb.cgilua.lp.compile(source, name, [env]) -> function |
---|---|
Type | Function |
Description | Converts the specified Lua template source into a Lua function. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 612 |
Signature | hs.httpserver.hsminweb.cgilua.lp.include(file, [env]) -> none |
---|---|
Type | Function |
Description | Includes the template specified by the |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 638 |
Signature | hs.httpserver.hsminweb.cgilua.lp.translate(source) -> luaCode |
---|---|
Type | Function |
Description | Converts the specified Lua template source into Lua code executable within the Hammerspoon environment. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/httpserver/cgilua_compatibility_functions.lua line 565 |