httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject svn commit: r711479 - in /httpd/mod_wombat/trunk: mod_wombat.c request.c request.h test/htdocs/simple.lua
Date Wed, 05 Nov 2008 00:30:08 GMT
Author: brianm
Date: Tue Nov  4 16:30:07 2008
New Revision: 711479

URL: http://svn.apache.org/viewvc?rev=711479&view=rev
Log:
changing how dispatch works to be far less sucky, tests fail at the moment, but I am checking
in anyway as I don't want to lose work

Modified:
    httpd/mod_wombat/trunk/mod_wombat.c
    httpd/mod_wombat/trunk/request.c
    httpd/mod_wombat/trunk/request.h
    httpd/mod_wombat/trunk/test/htdocs/simple.lua

Modified: httpd/mod_wombat/trunk/mod_wombat.c
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/mod_wombat.c?rev=711479&r1=711478&r2=711479&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/mod_wombat.c (original)
+++ httpd/mod_wombat/trunk/mod_wombat.c Tue Nov  4 16:30:07 2008
@@ -514,7 +514,7 @@
 static int wombat_open_hook(lua_State *L, apr_pool_t *p) {
     apr_lua_init(L, p);
     apw_load_apache2_lmodule(L);
-    apw_load_request_lmodule(L);
+    apw_load_request_lmodule(L, p);
     apw_load_config_lmodule(L);
     return OK;
 }

Modified: httpd/mod_wombat/trunk/request.c
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/request.c?rev=711479&r1=711478&r2=711479&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/request.c (original)
+++ httpd/mod_wombat/trunk/request.c Tue Nov  4 16:30:07 2008
@@ -193,6 +193,25 @@
   return 1;
 }
 
+static int req_dispatch(lua_State* L) {
+  request_rec* r = check_request_rec(L, 1);
+  const char *name = luaL_checkstring(L, 2);
+  ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "dispatching %s", name);
+  lua_pop(L, 2);
+ 
+  lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
+  apr_hash_t* dispatch = lua_touserdata(L, 1);
+  lua_pop(L, 1);
+  lua_CFunction* func = (lua_CFunction*) apr_hash_get(dispatch, name, APR_HASH_KEY_STRING);
+  if (!func) {
+      ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "no function for %s", name);
+      
+      return 0;
+  }
+  lua_pushcfunction(L, func);
+  return 1;
+}
+
 // helper function for the logging functions below
 static int req_log_at(lua_State* L, int level) {
     request_rec* r = check_request_rec(L, 1);
@@ -267,22 +286,8 @@
 }
 
 static const struct luaL_Reg request_methods[] = {
-    {"puts", req_puts},
-    {"write", req_write},
-    {"document_root", req_document_root},
-    {"parseargs", req_parseargs},
-    {"parsebody", req_parsebody},
-    
-    // Log methods
-    {"debug", req_debug},
-    {"info", req_info},
-    {"notice", req_notice},
-    {"warn", req_warn},
-    {"err", req_err},
-    {"crit", req_crit},
-    {"alert", req_alert},
-    {"emerg", req_emerg},
-    
+    {"__index", req_dispatch},
+    //   {"__newindex", req_set_field},    
     {NULL, NULL}
 };
 
@@ -296,7 +301,28 @@
     {NULL, NULL}
 };
 
-void apw_load_request_lmodule(lua_State *L) {
+void apw_load_request_lmodule(lua_State *L, apr_pool_t *p) {
+    
+    apr_hash_t* dispatch = apr_hash_make(p);
+    apr_hash_set(dispatch, "puts", APR_HASH_KEY_STRING, &req_puts);
+    apr_hash_set(dispatch, "write", APR_HASH_KEY_STRING, &req_write);
+    apr_hash_set(dispatch, "document_root", APR_HASH_KEY_STRING, &req_document_root);
+    apr_hash_set(dispatch, "parseargs", APR_HASH_KEY_STRING, &req_parseargs);
+    apr_hash_set(dispatch, "parsebody", APR_HASH_KEY_STRING, &req_parsebody);
+    
+    
+    apr_hash_set(dispatch, "debug", APR_HASH_KEY_STRING, &req_debug);
+    apr_hash_set(dispatch, "info", APR_HASH_KEY_STRING, &req_info);
+    apr_hash_set(dispatch, "notice", APR_HASH_KEY_STRING, &req_notice);
+    apr_hash_set(dispatch, "warn", APR_HASH_KEY_STRING, &req_warn);
+    apr_hash_set(dispatch, "err", APR_HASH_KEY_STRING, &req_err);
+    apr_hash_set(dispatch, "crit", APR_HASH_KEY_STRING, &req_crit);
+    apr_hash_set(dispatch, "alert", APR_HASH_KEY_STRING, &req_alert);
+    apr_hash_set(dispatch, "emerg", APR_HASH_KEY_STRING, &req_emerg);
+    
+    lua_pushlightuserdata(L, dispatch);
+    lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
+    
     luaL_newmetatable(L, "Apache2.Request"); // [metatable]
     lua_pushvalue(L, -1); 
 
@@ -355,75 +381,77 @@
     luaL_getmetatable(L, "Apache2.Request");
     lua_setmetatable(L, -2);
     luaL_getmetatable(L, "Apache2.Request");
-
-    lua_pushinteger(L, r->status);
-    lua_setfield(L, -2, "status");
+    rstack_dump(L, r, "apw_push_request pre pop");
+    lua_pop(L, 1);
+    rstack_dump(L, r, "apw_push_request post pop");
+    // lua_pushinteger(L, r->status);
+    // lua_setfield(L, -2, "status");
         
-    lua_pushstring(L, r->method);
-    lua_setfield(L, -2, "method");
-
-    lua_pushstring(L, r->the_request);
-    lua_setfield(L, -2, "the_request");
+    // lua_pushstring(L, r->method);
+    // lua_setfield(L, -2, "method");
 
-    lua_pushstring(L, r->protocol);
-    lua_setfield(L, -2, "protocol");
-    
-    lua_pushstring(L, r->range);
-    lua_setfield(L, -2, "range");
-    
-    lua_pushstring(L, r->content_type);
-    lua_setfield(L, -2, "content_type");
-    
-    lua_pushstring(L, r->content_encoding);
-    lua_setfield(L, -2, "content_encoding");
-    
-    lua_pushstring(L, r->user);
-    lua_setfield(L, -2, "user");
-    
-    lua_pushstring(L, r->ap_auth_type);
-    lua_setfield(L, -2, "ap_auth_type");
-    
-    lua_pushstring(L, r->unparsed_uri);
-    lua_setfield(L, -2, "unparsed_uri");
-    
-    lua_pushstring(L, r->uri);
-    lua_setfield(L, -2, "uri");
-    
-    lua_pushstring(L, r->filename);
-    lua_setfield(L, -2, "filename");
-
-    lua_pushstring(L, r->canonical_filename);
-    lua_setfield(L, -2, "canonical_filename");
-
-    lua_pushstring(L, r->path_info);
-    lua_setfield(L, -2, "path_info");
-    
-    lua_pushstring(L, r->args);
-    lua_setfield(L, -2, "args");
-    
-    lua_pushstring(L, r->hostname);
-    lua_setfield(L, -2, "hostname");
-
-    lua_pushboolean(L, r->assbackwards);
-    lua_setfield(L, -2, "assbackwards");
-
-    lua_pushcfunction(L, &req_add_output_filter);
-    lua_setfield(L, -2, "addoutputfilter");
-
-    apw_push_apr_table(L, "subprocess_env", r->subprocess_env);
-    apw_push_apr_table(L, "headers_out", r->headers_out);
-    apw_push_apr_table(L, "headers_in", r->headers_in);
-    apw_push_apr_table(L, "notes", r->notes);
-
-    apw_push_connection(L, r->connection);
-    lua_setfield(L, -2, "connection");
-
-    apw_push_server(L, r->server);
-    lua_setfield(L, -2, "server");
-
-    lua_pushlightuserdata(L, r);
-    lua_pushcclosure(L, &req_newindex, 1);
-    lua_setfield(L, -2, "__newindex");
-    lua_pop(L, 1);
+    // lua_pushstring(L, r->the_request);
+    //     lua_setfield(L, -2, "the_request");
+    // 
+    //     lua_pushstring(L, r->protocol);
+    //     lua_setfield(L, -2, "protocol");
+    //     
+    //     lua_pushstring(L, r->range);
+    //     lua_setfield(L, -2, "range");
+    //     
+    //     lua_pushstring(L, r->content_type);
+    //     lua_setfield(L, -2, "content_type");
+    //     
+    //     lua_pushstring(L, r->content_encoding);
+    //     lua_setfield(L, -2, "content_encoding");
+    //     
+    //     lua_pushstring(L, r->user);
+    //     lua_setfield(L, -2, "user");
+    //     
+    //     lua_pushstring(L, r->ap_auth_type);
+    //     lua_setfield(L, -2, "ap_auth_type");
+    //     
+    //     lua_pushstring(L, r->unparsed_uri);
+    //     lua_setfield(L, -2, "unparsed_uri");
+    //     
+    //     lua_pushstring(L, r->uri);
+    //     lua_setfield(L, -2, "uri");
+    //     
+    //     lua_pushstring(L, r->filename);
+    //     lua_setfield(L, -2, "filename");
+    // 
+    //     lua_pushstring(L, r->canonical_filename);
+    //     lua_setfield(L, -2, "canonical_filename");
+    // 
+    //     lua_pushstring(L, r->path_info);
+    //     lua_setfield(L, -2, "path_info");
+    //     
+    //     lua_pushstring(L, r->args);
+    //     lua_setfield(L, -2, "args");
+    //     
+    //     lua_pushstring(L, r->hostname);
+    //     lua_setfield(L, -2, "hostname");
+    // 
+    //     lua_pushboolean(L, r->assbackwards);
+    //     lua_setfield(L, -2, "assbackwards");
+    // 
+    //     lua_pushcfunction(L, &req_add_output_filter);
+    //     lua_setfield(L, -2, "addoutputfilter");
+    // 
+    //     apw_push_apr_table(L, "subprocess_env", r->subprocess_env);
+    //     apw_push_apr_table(L, "headers_out", r->headers_out);
+    //     apw_push_apr_table(L, "headers_in", r->headers_in);
+    //     apw_push_apr_table(L, "notes", r->notes);
+    // 
+    //     apw_push_connection(L, r->connection);
+    //     lua_setfield(L, -2, "connection");
+    // 
+    //     apw_push_server(L, r->server);
+    //     lua_setfield(L, -2, "server");
+    // 
+    //     lua_pushlightuserdata(L, r);
+    //     lua_pushcclosure(L, &req_newindex, 1);
+    //     lua_setfield(L, -2, "__newindex");
+    //     lua_pop(L, 1);
 }
 

Modified: httpd/mod_wombat/trunk/request.h
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/request.h?rev=711479&r1=711478&r2=711479&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/request.h (original)
+++ httpd/mod_wombat/trunk/request.h Tue Nov  4 16:30:07 2008
@@ -19,7 +19,7 @@
 #define REQUEST_H
 
 APR_DECLARE(void) apw_push_request(lua_State* L, request_rec* r);
-APR_DECLARE(void) apw_load_request_lmodule(lua_State *L);
+APR_DECLARE(void) apw_load_request_lmodule(lua_State *L, apr_pool_t *p);
 
 #endif
 

Modified: httpd/mod_wombat/trunk/test/htdocs/simple.lua
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/test/htdocs/simple.lua?rev=711479&r1=711478&r2=711479&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/test/htdocs/simple.lua (original)
+++ httpd/mod_wombat/trunk/test/htdocs/simple.lua Tue Nov  4 16:30:07 2008
@@ -1,3 +1,3 @@
 function handle(r)
-    r:puts("Hi!")
+   r:puts("Hi!")
 end



Mime
View raw message