From b4087e08e537f1841427f8af54c28843395c356d Mon Sep 17 00:00:00 2001 From: Rich Bowen Date: Thu, 22 Apr 2010 11:16:40 +0000 Subject: [PATCH] Doesn't flow very well, but here's the info that was squirreled away in txt files in svn. From here I'll probably need some help to flesh this out, or perhaps I'll steal some of Paul's blog articles. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@936782 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/mod/mod_lua.html.en | 76 +++++++++++++++++++++++++++++++++ docs/manual/mod/mod_lua.xml | 73 +++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) diff --git a/docs/manual/mod/mod_lua.html.en b/docs/manual/mod/mod_lua.html.en index e842ab19d8..3975f56b9c 100644 --- a/docs/manual/mod/mod_lua.html.en +++ b/docs/manual/mod/mod_lua.html.en @@ -55,6 +55,9 @@ request processing

Topics

top
@@ -79,6 +82,79 @@ AddHandler lua-script .lua This will cause any .lua file to be evaluated by mod_lua.

+
top
+
+

Writing Handlers

+ +

mod_lua always looks to invoke a function for the handler, rather than +just evaluating a script body CGI style. A handler function looks +something like this:

+ +

example.lua

+    require "string"
+
+    function handle_something(r)
+        r.content_type = "text/plain"
+        r:puts("Hello Lua World!\n")
+    
+        if r.method == 'GET' then
+            for k, v in pairs( r:parseargs() ) do
+                r:puts( string.format("%s: %s", k, v) )
+            end
+        elseif r.method == 'POST' then
+            for k, v in pairs( r:parsebody() ) do
+                r:puts( string.format("%s: %s", k, v) )
+            end
+        else
+            r:puts("unknown HTTP method " .. r.method)
+        end 
+    end
+
+ +

+This handler function just prints out the uri or form encoded +arguments to a plaintext page. +

+ +

+This means (and in fact encourages) that you can have multiple +handlers (or hooks, or filters) in the same script. +

+ +
top
+
+

Data Structures

+ +
+
request_rec
+
+

The request_rec is mapped in as a userdata. It has a metatable + which lets you do useful things with it. For the most part it + has the same fields as the request_rec struct (see httpd.h + until we get better docs here) many of which are writeable as + well as readable, and has (at least) the following methods:

+ +

+ r:puts("hello", " world", "!") -- print to response body +

+
+
+ +
top
+
+

Logging Functions

+ +

+ r:debug("This is a debug log message")
+ r:info("This is an info log message")
+ r:notice("This is an notice log message")
+ r:warn("This is an warn log message")
+ r:err("This is an err log message")
+ r:alert("This is an alert log message")
+ r:crit("This is an crit log message")
+ r:emerg("This is an emerg log message")
+

+
top

Directive

diff --git a/docs/manual/mod/mod_lua.xml b/docs/manual/mod/mod_lua.xml index 56c31c1191..14eea66f48 100644 --- a/docs/manual/mod/mod_lua.xml +++ b/docs/manual/mod/mod_lua.xml @@ -59,6 +59,79 @@ This will cause any .lua file to be evaluated by

+
Writing Handlers + +

mod_lua always looks to invoke a function for the handler, rather than +just evaluating a script body CGI style. A handler function looks +something like this:

+ +example.lua
+    require "string"
+
+    function handle_something(r)
+        r.content_type = "text/plain"
+        r:puts("Hello Lua World!\n")
+    
+        if r.method == 'GET' then
+            for k, v in pairs( r:parseargs() ) do
+                r:puts( string.format("%s: %s", k, v) )
+            end
+        elseif r.method == 'POST' then
+            for k, v in pairs( r:parsebody() ) do
+                r:puts( string.format("%s: %s", k, v) )
+            end
+        else
+            r:puts("unknown HTTP method " .. r.method)
+        end 
+    end
+
+ +

+This handler function just prints out the uri or form encoded +arguments to a plaintext page. +

+ +

+This means (and in fact encourages) that you can have multiple +handlers (or hooks, or filters) in the same script. +

+ +
+ +
Data Structures + +
+
request_rec
+
+

The request_rec is mapped in as a userdata. It has a metatable + which lets you do useful things with it. For the most part it + has the same fields as the request_rec struct (see httpd.h + until we get better docs here) many of which are writeable as + well as readable, and has (at least) the following methods:

+ + + r:puts("hello", " world", "!") -- print to response body + +
+
+ +
+ +
Logging Functions + + + r:debug("This is a debug log message")
+ r:info("This is an info log message")
+ r:notice("This is an notice log message")
+ r:warn("This is an warn log message")
+ r:err("This is an err log message")
+ r:alert("This is an alert log message")
+ r:crit("This is an crit log message")
+ r:emerg("This is an emerg log message")
+
+ +
+ LuaRoot Specify the base path -- 2.40.0