Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 31111 invoked from network); 22 Apr 2010 11:17:33 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 22 Apr 2010 11:17:33 -0000 Received: (qmail 53892 invoked by uid 500); 22 Apr 2010 11:17:32 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 53705 invoked by uid 500); 22 Apr 2010 11:17:31 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 53698 invoked by uid 99); 22 Apr 2010 11:17:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Apr 2010 11:17:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Apr 2010 11:17:23 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C94A123889B2; Thu, 22 Apr 2010 11:16:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r936782 - in /httpd/httpd/trunk/docs/manual/mod: mod_lua.html.en mod_lua.xml Date: Thu, 22 Apr 2010 11:16:40 -0000 To: cvs@httpd.apache.org From: rbowen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100422111640.C94A123889B2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rbowen Date: Thu Apr 22 11:16:40 2010 New Revision: 936782 URL: http://svn.apache.org/viewvc?rev=936782&view=rev Log: 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. Modified: httpd/httpd/trunk/docs/manual/mod/mod_lua.html.en httpd/httpd/trunk/docs/manual/mod/mod_lua.xml Modified: httpd/httpd/trunk/docs/manual/mod/mod_lua.html.en URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_lua.html.en?rev=936782&r1=936781&r2=936782&view=diff ============================================================================== --- httpd/httpd/trunk/docs/manual/mod/mod_lua.html.en (original) +++ httpd/httpd/trunk/docs/manual/mod/mod_lua.html.en Thu Apr 22 11:16:40 2010 @@ -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

Modified: httpd/httpd/trunk/docs/manual/mod/mod_lua.xml URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_lua.xml?rev=936782&r1=936781&r2=936782&view=diff ============================================================================== --- httpd/httpd/trunk/docs/manual/mod/mod_lua.xml (original) +++ httpd/httpd/trunk/docs/manual/mod/mod_lua.xml Thu Apr 22 11:16:40 2010 @@ -59,6 +59,79 @@ This will cause any .lua fi

+
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