mod_pLua is first and foremost a preprocessor. It processes a hypertext markup file with embedded Lua into pure Lua code by chopping up the file into small segments; HTML/XML code and Lua code:
(This is a very simplified example of how the preprocessing works. In reality, it's a lot more complex)
Line numbers are preserved, so any Lua error will respond to the exact same line as in the original script file.
Once preprocessed, the file is compiled using the Lua interpreter available on the system. If no compiler errors were found, the script is stored as compiled bytecode in the mod_pLua cache for the given domain pool, for any later use.
After the processed script has been compiled, standard libraries and functions are loaded into a Lua state (if not present already), and the script is called from the cache.
mod_pLua and mod_lua are two separate modules for Apache, and although they share the same love for Lua, they have different approaches to using Lua for web development.
mod_pLua
is for:
mod_lua
is for:
Notable differences in design:
mod_lua
uses a per-thread created state for execution while mod_pLua
uses a per-host pool of states that threads share.mod_lua
requires opening of any library needed for operations (including string
, table
etc) while mod_pLua
comes batteries-included (unless specifically told otherwise with the pLuaIgnoreLibrary
directive).As written above, you can sum the differences up like so: mod_pLua is the mod_php of Lua, while mod_lua is the mod_perl of Lua (although they are not as bloated).