Index: connection.c
===================================================================
--- connection.c	(revision 0)
+++ connection.c	(revision 0)
@@ -0,0 +1,55 @@
+#include "mod_wombat.h"
+
+static apr_pool_t *conn_pool = NULL;
+
+static apr_hash_t *conn_getters = NULL;
+
+static int remote_ip(lua_State *L, conn_rec *c) {
+    lua_pushstring(L, c->remote_ip);
+    return 1;
+}
+
+
+static int conn_notes(lua_State *L, conn_rec *c) {
+    /*there has to be a better way than pushing this everytime??*/
+    apr_lua_pushtable(L, c->notes);
+    return 1;
+}
+
+static int conn_index(lua_State* L) {
+    luaL_checkudata(L, 1, "Apache2.Connection");
+    conn_rec* c = lua_unboxpointer(L, 1);
+    const char* key = luaL_checkstring(L, 2);
+
+    apache2_lua_function *func = apr_hash_get(conn_getters, key, APR_HASH_KEY_STRING);
+    
+    if(NULL == func) {
+        lua_pushstring(L, "trying to get unknown Apache2.onnection property/method");
+        lua_error(L);
+    }
+
+    return func(L, c);
+}
+
+static const luaL_reg conn_methods[] = {
+    {"__index", conn_index},
+    {0, 0}
+};
+
+int luaopen_apache2_connection(lua_State *L) {
+    if (NULL == conn_pool) {
+	apr_pool_create(&conn_pool, NULL);
+	conn_getters = apr_hash_make(conn_pool);
+        apr_hash_set(conn_getters, "remote_ip", APR_HASH_KEY_STRING, remote_ip);
+	apr_hash_set(conn_getters, "notes", APR_HASH_KEY_STRING, conn_notes);
+    }
+    luaL_newmetatable(L, "Apache2.Connection");
+    luaL_register(L, NULL, conn_methods);
+    return 1;
+}
+
+void apw_push_connection(lua_State* L, conn_rec *c) {
+    lua_boxpointer(L, c);
+    luaL_getmetatable(L, "Apache2.Connection");
+    lua_setmetatable(L, -2);
+}
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 539017)
+++ Makefile.in	(working copy)
@@ -1,4 +1,4 @@
-APXS_CFLAGS = -Wc,-Wall -Wc,-Werror
+APXS_CFLAGS = -Wc,-Wall
 
 COMPILE_APACHE_MOD = @APXS@ -c -I`@APXS@ -q INCLUDEDIR`/apreq2 -I@APREQ2_DIR@/include/apreq2 -L@APREQ2_DIR@/lib -lapreq2 @LUA_LIBS@ @LUA_CFLAGS@ $(APXS_CFLAGS)
 
@@ -25,7 +25,7 @@
 dist-clean: maintainer-clean
 
 mod_wombat.la: mod_wombat.c
-	$(COMPILE_APACHE_MOD) mod_wombat.c request.c vmprep.c config.c apr_lua.c 
+	$(COMPILE_APACHE_MOD) mod_wombat.c request.c vmprep.c config.c apr_lua.c server.c connection.c
 
 install-mods: mod_wombat.la
 	$(INSTALL_MOD_SHARED) -n wombat mod_wombat.la
Index: connection.h
===================================================================
--- connection.h	(revision 0)
+++ connection.h	(revision 0)
@@ -0,0 +1,7 @@
+#ifndef __CONNECTION_H__
+#define __CONNECTION_H__
+
+int luaopen_apache2_connection(lua_State *L);
+void apw_push_connection(lua_State* L, conn_rec *c);
+
+#endif
Index: server.c
===================================================================
--- server.c	(revision 0)
+++ server.c	(revision 0)
@@ -0,0 +1,47 @@
+#include "mod_wombat.h"
+#include "server.h"
+
+static apr_pool_t *server_pool = NULL;
+
+static apr_hash_t *server_getters = NULL;
+
+static int server_hostname(lua_State *L, server_rec *s) {
+    lua_pushstring(L, s->server_hostname);
+    return 1;
+}
+
+static int server_index(lua_State* L) {
+    luaL_checkudata(L, 1, "Apache2.Server");
+    server_rec* s = lua_unboxpointer(L, 1);
+    const char* key = luaL_checkstring(L, 2);
+
+    apache2_lua_function *func = apr_hash_get(server_getters, key, APR_HASH_KEY_STRING);
+    
+    if(NULL == func) {
+        lua_pushstring(L, "trying to get unknown Apache2.Server property/method");
+        lua_error(L);
+    }
+    return func(L, s);
+}
+
+static const luaL_reg server_methods[] = {
+    {"__index", server_index},
+    {0, 0}
+};
+
+int luaopen_apache2_server(lua_State *L) {
+    if (NULL == server_pool) {
+	apr_pool_create(&server_pool, NULL);
+	server_getters = apr_hash_make(server_pool);
+        apr_hash_set(server_getters, "server_hostname", APR_HASH_KEY_STRING, server_hostname);
+    }
+    luaL_newmetatable(L, "Apache2.Server");
+    luaL_register(L, NULL, server_methods);
+    return 1;
+}
+
+void apw_push_server(lua_State* L, server_rec *s) {
+    lua_boxpointer(L, s);
+    luaL_getmetatable(L, "Apache2.Server");
+    lua_setmetatable(L, -2);
+}
Index: vmprep.c
===================================================================
--- vmprep.c	(revision 539017)
+++ vmprep.c	(working copy)
@@ -22,6 +22,10 @@
 #include "config.h"
 #include "apr_file_info.h"
 
+#include "apr_lua.h"
+#include "request.h"
+#include "server.h"
+
 // forward dec'l from this file
 static int load_file(apr_pool_t *working_pool, lua_State* L, const apw_code_cache* cfg, apw_vm_spec *spec);
 
Index: server.h
===================================================================
--- server.h	(revision 0)
+++ server.h	(revision 0)
@@ -0,0 +1,7 @@
+#ifndef __SERVER_H__
+#define __SERVER_H__
+
+int luaopen_apache2_server(lua_State *L);
+void apw_push_server(lua_State* L, server_rec *s);
+
+#endif
Index: apr_lua.c
===================================================================
--- apr_lua.c	(revision 539017)
+++ apr_lua.c	(working copy)
@@ -6,6 +6,7 @@
 #include "lualib.h"
 
 #define lua_unboxpointer(L,i)      (*(void **)(lua_touserdata(L, i)))
+#define lua_boxpointer(L,u) (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u))
 
 static apr_table_t* check_apr_table(lua_State* L, int index) {
     luaL_checkudata(L, index, "Apr.Table");
@@ -13,7 +14,7 @@
     return t;
 }
 
-static int lua_table_set(lua_State* L) {
+static int lua_apr_table_set(lua_State* L) {
     apr_table_t *t = check_apr_table(L, 1);
     const char* key = luaL_checkstring(L, 2);
     const char* val = luaL_checkstring(L, 3);
@@ -22,7 +23,7 @@
     return 0;
 }
 
-static int lua_table_get(lua_State* L) {
+static int lua_apr_table_get(lua_State* L) {
     apr_table_t *t = check_apr_table(L, 1);
     const char* key = luaL_checkstring(L, 2);
     const char *val = apr_table_get(t, key);
@@ -30,15 +31,19 @@
     return 1;
 }
 
-static const luaL_reg lua_table_methods[] = {
-    {"set", lua_table_set},
-    {"get", lua_table_get},
+static const luaL_reg lua_apr_table_methods[] = {
+    {"__newindex", lua_apr_table_set},
+    {"__index", lua_apr_table_get},
     {0, 0}
 };
 
 
-int apr_lua_init(lua_State *L, apr_pool_t *p) {
+int luaopen_apr_table(lua_State *L) {
     luaL_newmetatable(L, "Apr.Table");
+    luaL_register(L, NULL, lua_apr_table_methods);
+    return 1;
+     /*
+    luaL_newmetatable(L, "Apr.Table");
     luaL_openlib(L, "apr_table", lua_table_methods, 0);
     lua_pushstring(L, "__index");
     lua_pushstring(L, "get");
@@ -49,7 +54,12 @@
     lua_pushstring(L, "set");
     lua_gettable(L, 2);
     lua_settable(L, 1);
-    
     return 0;
+    */
 }
 
+void apr_lua_pushtable(lua_State* L, apr_table_t *t) {
+    lua_boxpointer(L, t);
+    luaL_getmetatable(L, "Apr.Table");
+    lua_setmetatable(L, -2);
+}
Index: request.c
===================================================================
--- request.c	(revision 539017)
+++ request.c	(working copy)
@@ -16,6 +16,8 @@
  */
 
 #include "mod_wombat.h"
+#include "apr_lua.h"
+#include "apr_hash.h"
 
 void rstack_dump(lua_State* L, request_rec* r, const char* msg) {
     ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "Lua Stack Dump: [%s]", msg);
@@ -267,23 +269,6 @@
 };
 
 
-static const struct luaL_Reg connection_methods[] = {
-    {NULL, NULL}
-};
-
-
-static const struct luaL_Reg server_methods[] = {
-    {NULL, NULL}
-};
-
-void apw_push_apr_table(lua_State* L, const char *name, apr_table_t *t) {
-    lua_boxpointer(L, t);    
-    luaL_getmetatable(L, "Apr.Table");
-    lua_setmetatable(L, -2);
-    lua_setfield(L, -2, name);
-}
-
-
 void apw_load_request_lmodule(lua_State *L) {
     luaL_newmetatable(L, "Apache2.Request"); // [metatable]
     lua_pushvalue(L, -1); 
@@ -292,52 +277,8 @@
     luaL_register(L, NULL, request_methods); // [metatable]
 
     lua_pop(L, 2);
-
-    luaL_newmetatable(L, "Apache2.Connection"); // [metatable]
-    lua_pushvalue(L, -1); 
-
-    lua_setfield(L, -2, "__index"); 
-    luaL_register(L, NULL, connection_methods); // [metatable]
-
-    lua_pop(L, 2);
-
-    luaL_newmetatable(L, "Apache2.Server"); // [metatable]
-    lua_pushvalue(L, -1); 
-
-    lua_setfield(L, -2, "__index"); 
-    luaL_register(L, NULL, server_methods); // [metatable]
-
-    lua_pop(L, 2);
-
 }
 
-void apw_push_connection(lua_State* L, conn_rec* c) {  
-    lua_boxpointer(L, c);
-    luaL_getmetatable(L, "Apache2.Connection");
-    lua_setmetatable(L, -2);
-    luaL_getmetatable(L, "Apache2.Connection");
-
-    apw_push_apr_table(L, "notes", c->notes);
-
-    lua_pushstring(L, c->remote_ip);
-    lua_setfield(L, -2, "remote_ip");    
-
-    lua_pop(L, 1);
-}
-
-
-void apw_push_server(lua_State* L, server_rec* s) {  
-    lua_boxpointer(L, s);
-    luaL_getmetatable(L, "Apache2.Server");
-    lua_setmetatable(L, -2);
-    luaL_getmetatable(L, "Apache2.Server");
-
-    lua_pushstring(L, s->server_hostname);
-    lua_setfield(L, -2, "server_hostname");    
-
-    lua_pop(L, 1);
-}
-
 void apw_push_request(lua_State* L, request_rec* r) {  
     lua_boxpointer(L, r);
     luaL_getmetatable(L, "Apache2.Request");
@@ -395,13 +336,18 @@
     lua_pushcfunction(L, &req_add_output_filter);
     lua_setfield(L, -2, "addoutputfilter");
 
-    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);
+    apr_lua_pushtable(L, r->headers_out);
+    lua_setfield(L, -2, "headers_out");
 
+    apr_lua_pushtable(L, r->headers_in);
+    lua_setfield(L, -2, "headers_in");
+
+    apr_lua_pushtable(L, r->notes);
+    lua_setfield(L, -2, "notes");
+    
     apw_push_connection(L, r->connection);
     lua_setfield(L, -2, "connection");
-
+    
     apw_push_server(L, r->server);
     lua_setfield(L, -2, "server");
 
@@ -410,4 +356,3 @@
     lua_setfield(L, -2, "__newindex");
     lua_pop(L, 1);
 }
-
Index: mod_wombat.c
===================================================================
--- mod_wombat.c	(revision 539017)
+++ mod_wombat.c	(working copy)
@@ -463,10 +463,12 @@
 }
 
 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_config_lmodule(L);
+    lua_cpcall(L, luaopen_apr_table, NULL);
+    lua_cpcall(L, luaopen_apache2_server, NULL);
+    lua_cpcall(L, luaopen_apache2_connection, NULL);
     return OK;
 }
 
Index: apr_lua.h
===================================================================
--- apr_lua.h	(revision 539017)
+++ apr_lua.h	(working copy)
@@ -1,6 +1,7 @@
 #ifndef _APR_LUA_H_
 #define _APR_LUA_H_
 
-int apr_lua_init(lua_State *L, apr_pool_t *p);
+int luaopen_apr_table(lua_State *L);
+void apr_lua_pushtable(lua_State* L, apr_table_t *t);
 
 #endif
Index: request.h
===================================================================
--- request.h	(revision 539017)
+++ request.h	(working copy)
@@ -21,5 +21,10 @@
 APR_DECLARE(void) apw_push_request(lua_State* L, request_rec* r);
 APR_DECLARE(void) apw_load_request_lmodule(lua_State *L);
 
+/*
+int luaopen_apache2_server(lua_State *L);
+void apache2_lua_pushserver(lua_State* L, server_rec *s);
+*/
+
 #endif
 
Index: mod_wombat.h
===================================================================
--- mod_wombat.h	(revision 539017)
+++ mod_wombat.h	(working copy)
@@ -49,9 +49,11 @@
 #include "lualib.h"
 
 #include "request.h"
+#include "server.h"
+#include "connection.h"
 #include "vmprep.h"
+#include "apr_lua.h"
 
-
 /**
  * make a userdata out of a C pointer, and vice versa
  * instead of using lightuserdata
@@ -136,5 +138,7 @@
 APR_DECLARE_EXTERNAL_HOOK(apw, WOMBAT, int, wombat_request,
                           (lua_State *L, request_rec *r));
 
+typedef int apache2_lua_function(lua_State *L, void *data);
+
 #endif /* !MOD_WOMBAT_H */
 
