1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 This file is generated from xml source: DO NOT EDIT
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8 <title>mod_lua - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
14 <div id="page-header">
15 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
16 <p class="apache">Apache HTTP Server Version 2.3</p>
17 <img alt="" src="../images/feather.gif" /></div>
18 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
20 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.3</a> > <a href="./">Modules</a></div>
21 <div id="page-content">
22 <div id="preamble"><h1>Apache Module mod_lua</h1>
24 <p><span>Available Languages: </span><a href="../en/mod/mod_lua.html" title="English"> en </a></p>
26 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides Lua hooks into various portions of the httpd
27 request processing</td></tr>
28 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
29 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>lua_module</td></tr>
30 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_lua.c</td></tr>
31 <tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>2.3 and later</td></tr></table>
34 <p>This module allows the server to be extended with scripts written in the
35 Lua programming language. The extension points (hooks) available with
36 <code class="module"><a href="../mod/mod_lua.html">mod_lua</a></code> include many of the hooks available to
37 natively compiled Apache HTTP Server modules, such as mapping requests to
38 files, generating dynamic responses, access control, authentication, and
41 <p>More information on the Lua programming language can be found at the
42 <a href="http://www.lua.org/">the Lua website</a>.</p>
44 <div class="note"><code>mod_lua</code> is still in experimental state.
45 Until it is declared stable, usage and behavior may change
49 <div id="quickview"><h3 class="directives">Directives</h3>
51 <li><img alt="" src="../images/down.gif" /> <a href="#luacodecache">LuaCodeCache</a></li>
52 <li><img alt="" src="../images/down.gif" /> <a href="#luahookaccesschecker">LuaHookAccessChecker</a></li>
53 <li><img alt="" src="../images/down.gif" /> <a href="#luahookauthchecker">LuaHookAuthChecker</a></li>
54 <li><img alt="" src="../images/down.gif" /> <a href="#luahookcheckuserid">LuaHookCheckUserID</a></li>
55 <li><img alt="" src="../images/down.gif" /> <a href="#luahookfixups">LuaHookFixups</a></li>
56 <li><img alt="" src="../images/down.gif" /> <a href="#luahookinsertfilter">LuaHookInsertFilter</a></li>
57 <li><img alt="" src="../images/down.gif" /> <a href="#luahookmaptostorage">LuaHookMapToStorage</a></li>
58 <li><img alt="" src="../images/down.gif" /> <a href="#luahooktranslatename">LuaHookTranslateName</a></li>
59 <li><img alt="" src="../images/down.gif" /> <a href="#luahooktypechecker">LuaHookTypeChecker</a></li>
60 <li><img alt="" src="../images/down.gif" /> <a href="#luamaphandler">LuaMapHandler</a></li>
61 <li><img alt="" src="../images/down.gif" /> <a href="#luapackagecpath">LuaPackageCPath</a></li>
62 <li><img alt="" src="../images/down.gif" /> <a href="#luapackagepath">LuaPackagePath</a></li>
63 <li><img alt="" src="../images/down.gif" /> <a href="#luaquickhandler">LuaQuickHandler</a></li>
64 <li><img alt="" src="../images/down.gif" /> <a href="#luaroot">LuaRoot</a></li>
65 <li><img alt="" src="../images/down.gif" /> <a href="#luascope">LuaScope</a></li>
69 <li><img alt="" src="../images/down.gif" /> <a href="#basicconf">Basic Configuration</a></li>
70 <li><img alt="" src="../images/down.gif" /> <a href="#writinghandlers">Writing Handlers</a></li>
71 <li><img alt="" src="../images/down.gif" /> <a href="#writinghooks">Writing Hooks</a></li>
72 <li><img alt="" src="../images/down.gif" /> <a href="#datastructures">Data Structures</a></li>
73 <li><img alt="" src="../images/down.gif" /> <a href="#logging">Logging Functions</a></li>
74 <li><img alt="" src="../images/down.gif" /> <a href="#apache2">apache2 Package</a></li>
76 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
78 <h2><a name="basicconf" id="basicconf">Basic Configuration</a></h2>
80 <p>The basic module loading directive is</p>
82 <div class="example"><p><code>
83 LoadModule lua_module modules/mod_lua.so
87 <code>mod_lua</code> provides a handler named <code>lua-script</code>,
88 which can be used with an <code>AddHandler</code> directive:</p>
90 <div class="example"><p><code>
91 AddHandler lua-script .lua
95 This will cause <code>mod_lua</code> to handle requests for files
96 ending in <code>.lua</code> by invoking that file's
97 <code>handle</code> function.
100 <p>For more flexibility, see <code class="directive">LuaMapHandler</code>.
103 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
104 <div class="section">
105 <h2><a name="writinghandlers" id="writinghandlers">Writing Handlers</a></h2>
106 <p> In the Apache HTTP Server API, the handler is a specific kind of hook
107 responsible for generating the response. Examples of modules that include a
108 handler are <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code>, <code class="module"><a href="../mod/mod_cgi.html">mod_cgi</a></code>,
109 and <code class="module"><a href="../mod/mod_status.html">mod_status</a></code>.</p>
111 <p><code>mod_lua</code> always looks to invoke a Lua function for the handler, rather than
112 just evaluating a script body CGI style. A handler function looks
113 something like this:</p>
115 <div class="example"><h3>example.lua</h3><pre>
121 This is the default method name for Lua handlers, see the optional
122 function-name in the LuaMapHandler directive to choose a different
126 r.content_type = "text/plain"
127 r:puts("Hello Lua World!\n")
129 if r.method == 'GET' then
130 for k, v in pairs( r:parseargs() ) do
131 r:puts( string.format("%s: %s", k, v) )
133 elseif r.method == 'POST' then
134 for k, v in pairs( r:parsebody() ) do
135 r:puts( string.format("%s: %s", k, v) )
138 r:puts("unknown HTTP method " .. r.method)
144 This handler function just prints out the uri or form encoded
145 arguments to a plaintext page.
149 This means (and in fact encourages) that you can have multiple
150 handlers (or hooks, or filters) in the same script.
153 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
154 <div class="section">
155 <h2><a name="writinghooks" id="writinghooks">Writing Hooks</a></h2>
157 <p>Hook functions are how modules (and Lua scripts) participate in the
158 processing of requests. Each type of hook exposed by the server exists for
159 a specific purposes such as mapping requests to the filesystem,
160 performing access control, or setting mimetypes. General purpose hooks
161 that simply run at handy times in the request lifecycle exist as well.</p>
163 <p>Hook functions are passed the request object as their only argument.
164 They can return any value, depending on the hook, but most commonly
165 they'll return OK, DONE, or DECLINED, which you can write in lua as
166 <code>apache2.OK</code>, <code>apache2.DONE</code>, or
167 <code>apache2.DECLINED</code>, or else an HTTP status code.</p>
169 <div class="example"><h3>translate_name.lua</h3><pre>
170 -- example hook that rewrites the URI to a filesystem path.
174 function translate_name(r)
175 if r.uri == "/translate-name" then
176 r.filename = r.document_root .. "/find_me.txt"
179 -- we don't care about this URL, give another module a chance
180 return apache2.DECLINED
184 <div class="example"><h3>translate_name2.lua</h3><pre>
185 --[[ example hook that rewrites one URI to another URI. It returns a
186 apache2.DECLINED to give other URL mappers a chance to work on the
187 substitution, including the core translate_name hook which maps based
190 Note: It is currently undefined as to whether this runs before or after
196 function translate_name(r)
197 if r.uri == "/translate-name" then
198 r.uri = "/find_me.txt"
199 return apache2.DECLINED
201 return apache2.DECLINED
204 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
205 <div class="section">
206 <h2><a name="datastructures" id="datastructures">Data Structures</a></h2>
211 <p>The request_rec is mapped in as a userdata. It has a metatable
212 which lets you do useful things with it. For the most part it
213 has the same fields as the request_rec struct (see httpd.h
214 until we get better docs here) many of which are writeable as
215 well as readable. (The table fields' content can be changed, but the
216 fields themselves cannot be set to different tables.)</p>
218 <table class="bordered">
221 <th><strong>Name</strong></th>
222 <th><strong>Lua type</strong></th>
223 <th><strong>Writable</strong></th>
226 <td><code>ap_auth_type</code></td>
231 <td><code>args</code></td>
236 <td><code>assbackwards</code></td>
242 <td><code>canonical_filename</code></td>
247 <td><code>content_encoding</code></td>
252 <td><code>content_type</code></td>
258 <td><code>document_root</code></td>
263 <td><code>err_headers_out</code></td>
268 <td><code>filename</code></td>
273 <td><code>headers_in</code></td>
278 <td><code>headers_out</code></td>
283 <td><code>hostname</code></td>
288 <td><code>method</code></td>
293 <td><code>notes</code></td>
298 <td><code>path_info</code></td>
303 <td><code>protocol</code></td>
308 <td><code>range</code></td>
313 <td><code>subprocess_env</code></td>
318 <td><code>status</code></td>
323 <td><code>the_request</code></td>
328 <td><code>unparsed_uri</code></td>
333 <td><code>uri</code></td>
338 <td><code>user</code></td>
344 <p>The request_rec has (at least) the following methods:</p>
346 <div class="example"><p><code>
347 r:addoutputfilter(name|function) -- add an output filter
350 <div class="example"><p><code>
351 r:parseargs() -- returns a lua table containing the request's
352 query string arguments
355 <div class="example"><p><code>
356 r:parsebody() -- parse the request body as a POST and return
360 <div class="example"><p><code>
361 r:puts("hello", " world", "!") -- print to response body
364 <div class="example"><p><code>
365 r:write("a single string") -- print to response body
370 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
371 <div class="section">
372 <h2><a name="logging" id="logging">Logging Functions</a></h2>
374 <div class="example"><p><code>
375 -- examples of logging messages<br />
376 r:trace1("This is a trace log message") -- trace1 through trace8 can be used <br />
377 r:debug("This is a debug log message")<br />
378 r:info("This is an info log message")<br />
379 r:notice("This is an notice log message")<br />
380 r:warn("This is an warn log message")<br />
381 r:err("This is an err log message")<br />
382 r:alert("This is an alert log message")<br />
383 r:crit("This is an crit log message")<br />
384 r:emerg("This is an emerg log message")<br />
387 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
388 <div class="section">
389 <h2><a name="apache2" id="apache2">apache2 Package</a></h2>
390 <p>A package named <code>apache2</code> is available with (at least) the following contents.</p>
393 <dd>internal constant OK. Handlers should return this if they've
394 handled the request.</dd>
395 <dt>apache2.DECLINED</dt>
396 <dd>internal constant DECLINED. Handlers should return this if
397 they are not going to handle the request.</dd>
398 <dt>apache2.DONE</dt>
399 <dd>internal constant DONE.</dd>
400 <dt>apache2.version</dt>
401 <dd>Apache HTTP server version string</dd>
402 <dt>apache2.HTTP_MOVED_TEMPORARILY</dt>
403 <dd>HTTP status code</dd>
405 <p>(Other HTTP status codes are not yet implemented.)</p>
407 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
408 <div class="directive-section"><h2><a name="LuaCodeCache" id="LuaCodeCache">LuaCodeCache</a> <a name="luacodecache" id="luacodecache">Directive</a></h2>
409 <table class="directive">
410 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Configure the compiled code cache.</td></tr>
411 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaCodeCache stat|forever|never</code></td></tr>
412 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaCodeCache stat</code></td></tr>
413 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
414 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
415 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
416 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
418 Specify the behavior of the in-memory code cache. The default
419 is stat, which stats the top level script (not any included
420 ones) each time that file is needed, and reloads it if the
421 modified time indicates it is newer than the one it has
422 already loaded. The other values cause it to keep the file
423 cached forever (don't stat and replace) or to never cache the
426 <p>In general stat or forever is good for production, and stat or never
429 <div class="example"><h3>Examples:</h3><p><code>
430 LuaCodeCache stat<br />
431 LuaCodeCache forever<br />
432 LuaCodeCache never<br />
437 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
438 <div class="directive-section"><h2><a name="LuaHookAccessChecker" id="LuaHookAccessChecker">LuaHookAccessChecker</a> <a name="luahookaccesschecker" id="luahookaccesschecker">Directive</a></h2>
439 <table class="directive">
440 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the access_checker phase of request processing</td></tr>
441 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookAccessChecker /path/to/lua/script.lua hook_function_name</code></td></tr>
442 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
443 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
444 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
445 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
447 <p>Add your hook to the access_checker phase. An access checker
448 hook function usually returns OK, DECLINED, or HTTP_FORBIDDEN.</p>
451 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
452 <div class="directive-section"><h2><a name="LuaHookAuthChecker" id="LuaHookAuthChecker">LuaHookAuthChecker</a> <a name="luahookauthchecker" id="luahookauthchecker">Directive</a></h2>
453 <table class="directive">
454 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the auth_checker phase of request processing</td></tr>
455 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookAuthChecker /path/to/lua/script.lua hook_function_name</code></td></tr>
456 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
457 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
458 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
459 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
461 <p>Invoke a lua function in the auth_checker phase of processing
462 a request. This can be used to implement arbitrary authentication
463 and authorization checking. A very simple example:
465 <div class="example"><pre>
468 -- fake authcheck hook
469 -- If request has no auth info, set the response header and
470 -- return a 401 to ask the browser for basic auth info.
471 -- If request has auth info, don't actually look at it, just
472 -- pretend we got userid 'foo' and validated it.
473 -- Then check if the userid is 'foo' and accept the request.
474 function authcheck_hook(r)
476 -- look for auth info
477 auth = r.headers_in['Authorization']
483 if r.user == nil then
484 r:debug("authcheck: user is nil, returning 401")
485 r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
487 elseif r.user == "foo" then
488 r:debug('user foo: OK')
490 r:debug("authcheck: user='" .. r.user .. "'")
491 r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
499 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
500 <div class="directive-section"><h2><a name="LuaHookCheckUserID" id="LuaHookCheckUserID">LuaHookCheckUserID</a> <a name="luahookcheckuserid" id="luahookcheckuserid">Directive</a></h2>
501 <table class="directive">
502 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the check_user_id phase of request processing</td></tr>
503 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookCheckUserID /path/to/lua/script.lua hook_function_name</code></td></tr>
504 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
505 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
506 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
507 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
510 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
511 <div class="directive-section"><h2><a name="LuaHookFixups" id="LuaHookFixups">LuaHookFixups</a> <a name="luahookfixups" id="luahookfixups">Directive</a></h2>
512 <table class="directive">
513 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the fixups phase of request
515 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookFixups /path/to/lua/script.lua hook_function_name</code></td></tr>
516 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
517 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
518 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
519 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
522 Just like LuaHookTranslateName, but executed at the fixups phase
526 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
527 <div class="directive-section"><h2><a name="LuaHookInsertFilter" id="LuaHookInsertFilter">LuaHookInsertFilter</a> <a name="luahookinsertfilter" id="luahookinsertfilter">Directive</a></h2>
528 <table class="directive">
529 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the insert_filter phase of request processing</td></tr>
530 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookInsertFilter /path/to/lua/script.lua hook_function_name</code></td></tr>
531 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
532 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
533 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
534 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
535 </table><p>Not Yet Implemented</p>
537 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
538 <div class="directive-section"><h2><a name="LuaHookMapToStorage" id="LuaHookMapToStorage">LuaHookMapToStorage</a> <a name="luahookmaptostorage" id="luahookmaptostorage">Directive</a></h2>
539 <table class="directive">
540 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the map_to_storage phase of request processing</td></tr>
541 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookMapToStorage /path/to/lua/script.lua hook_function_name</code></td></tr>
542 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
543 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
544 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
545 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
548 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
549 <div class="directive-section"><h2><a name="LuaHookTranslateName" id="LuaHookTranslateName">LuaHookTranslateName</a> <a name="luahooktranslatename" id="luahooktranslatename">Directive</a></h2>
550 <table class="directive">
551 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the translate name phase of request processing</td></tr>
552 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookTranslateName /path/to/lua/script.lua hook_function_name</code></td></tr>
553 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
554 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
555 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
556 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
558 Add a hook (at APR_HOOK_MIDDLE) to the translate name phase of
559 request processing. The hook function receives a single
560 argument, the request_rec, and should return a status code,
561 which is either an HTTP error code, or the constants defined
562 in the apache2 module: apache2.OK, apache2.DECLINED, or
565 <p>For those new to hooks, basically each hook will be invoked
566 until one of them returns apache2.OK. If your hook doesn't
567 want to do the translation it should just return
568 apache2.DECLINED. If the request should stop processing, then
569 return apache2.DONE.</p>
573 <div class="example"><pre>
575 LuaHookTranslateName /scripts/conf/hooks.lua silly_mapper
577 -- /scripts/conf/hooks.lua --
579 function silly_mapper(r)
581 r.filename = "/var/www/home.lua"
584 return apache2.DECLINED
590 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
591 <div class="directive-section"><h2><a name="LuaHookTypeChecker" id="LuaHookTypeChecker">LuaHookTypeChecker</a> <a name="luahooktypechecker" id="luahooktypechecker">Directive</a></h2>
592 <table class="directive">
593 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the type_checker phase of request processing</td></tr>
594 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookTypeChecker /path/to/lua/script.lua hook_function_name</code></td></tr>
595 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
596 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
597 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
598 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
601 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
602 <div class="directive-section"><h2><a name="LuaMapHandler" id="LuaMapHandler">LuaMapHandler</a> <a name="luamaphandler" id="luamaphandler">Directive</a></h2>
603 <table class="directive">
604 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Map a path to a lua handler</td></tr>
605 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaMapHandler uri-pattern /path/to/lua/script.lua [function-name]</code></td></tr>
606 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
607 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
608 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
609 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
611 <p>This directive matches a uri pattern to invoke a specific
612 handler function in a specific file. It uses PCRE regular
613 expressions to match the uri, and supports interpolating
614 match groups into both the file path and the function name
615 be careful writing your regular expressions to avoid security
617 <div class="example"><h3>Examples:</h3><p><code>
618 LuaMapHandler /(\w+)/(/w+) /scripts/$1.lua handle_$2
620 <p>This would match uri's such as /photos/show?id=9
621 to the file /scripts/photos.lua and invoke the
622 handler function handle_show on the lua vm after
623 loading that file.</p>
625 <div class="example"><p><code>
626 LuaMapHandler /bingo /scripts/wombat.lua
628 <p>This would invoke the "handle" function, which
629 is the default if no specific function name is
633 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
634 <div class="directive-section"><h2><a name="LuaPackageCPath" id="LuaPackageCPath">LuaPackageCPath</a> <a name="luapackagecpath" id="luapackagecpath">Directive</a></h2>
635 <table class="directive">
636 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.cpath</td></tr>
637 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackageCPath /path/to/include/?.soa</code></td></tr>
638 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
639 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
640 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
641 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
643 <p>Add a path to lua's shared library search path. Follows the same
644 conventions as lua. This just munges the package.cpath in the
649 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
650 <div class="directive-section"><h2><a name="LuaPackagePath" id="LuaPackagePath">LuaPackagePath</a> <a name="luapackagepath" id="luapackagepath">Directive</a></h2>
651 <table class="directive">
652 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.path</td></tr>
653 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackagePath /path/to/include/?.lua</code></td></tr>
654 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
655 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
656 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
657 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
658 </table><p>Add a path to lua's module search path. Follows the same
659 conventions as lua. This just munges the package.path in the
662 <div class="example"><h3>Examples:</h3><p><code>
663 LuaPackagePath /scripts/lib/?.lua<br />
664 LuaPackagePath /scripts/lib/?/init.lua
668 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
669 <div class="directive-section"><h2><a name="LuaQuickHandler" id="LuaQuickHandler">LuaQuickHandler</a> <a name="luaquickhandler" id="luaquickhandler">Directive</a></h2>
670 <table class="directive">
671 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the quick handler of request processing</td></tr>
672 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code /></td></tr>
673 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
674 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
675 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
676 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
679 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
680 <div class="directive-section"><h2><a name="LuaRoot" id="LuaRoot">LuaRoot</a> <a name="luaroot" id="luaroot">Directive</a></h2>
681 <table class="directive">
682 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Specify the base path for resolving relative paths for mod_lua directives</td></tr>
683 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaRoot /path/to/a/directory</code></td></tr>
684 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
685 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
686 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
687 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
689 <p>Specify the base path which will be used to evaluate all
690 relative paths within mod_lua. If not specified they
691 will be resolved relative to the current working directory,
692 which may not always work well for a server.</p>
695 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
696 <div class="directive-section"><h2><a name="LuaScope" id="LuaScope">LuaScope</a> <a name="luascope" id="luascope">Directive</a></h2>
697 <table class="directive">
698 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>One of once, request, conn, server -- default is once</td></tr>
699 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaScope once|request|conn|server [max|min max]</code></td></tr>
700 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaScope once</code></td></tr>
701 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
702 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
703 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
704 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
706 <p>Specify the lifecycle scope of the Lua interpreter which will
707 be used by handlers in this "Directory." The default is "once"</p>
710 <dt>once:</dt> <dd>use the interpreter once and throw it away.</dd>
712 <dt>request:</dt> <dd>use the interpreter to handle anything based on
713 the same file within this request, which is also
716 <dt>conn:</dt> <dd>Same as request but attached to the connection_rec</dd>
718 <dt>server:</dt> <dd>This one is different than others because the
719 server scope is quite long lived, and multiple threads
720 will have the same server_rec. To accommodate this
721 server scoped interpreter are stored in an apr
722 resource list. The min and max arguments are intended
723 to specify the pool size, but are unused at this time.</dd>
728 <div class="bottomlang">
729 <p><span>Available Languages: </span><a href="../en/mod/mod_lua.html" title="English"> en </a></p>
730 </div><div id="footer">
731 <p class="apache">Copyright 2011 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
732 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>