Common subdirectories: mod_lua_build/docs and mod_lua_err/docs
diff -u mod_lua_build/lua_vmprep.c mod_lua_err/lua_vmprep.c
--- mod_lua_build/lua_vmprep.c	2009-03-21 15:17:11.000000000 +0100
+++ mod_lua_err/lua_vmprep.c	2009-03-21 15:44:54.000000000 +0100
@@ -319,15 +319,6 @@
 
         apr_pool_userdata_set(L, spec->file, &cleanup_lua, lifecycle_pool);
 
-        if (spec->bytecode && spec->bytecode_len > 0) {
-            luaL_loadbuffer(L, spec->bytecode, spec->bytecode_len, spec->file);
-            lua_pcall(L, 0, LUA_MULTRET, 0);
-        }
-        else {
-            luaL_loadfile(L, spec->file);
-            lua_pcall(L, 0, LUA_MULTRET, 0);
-        }
-
 #ifdef AP_ENABLE_LUAJIT
         loadjitmodule(L, lifecycle_pool);
 #endif
diff -u mod_lua_build/mod_lua.c mod_lua_err/mod_lua.c
--- mod_lua_build/mod_lua.c	2009-03-21 15:29:34.000000000 +0100
+++ mod_lua_err/mod_lua.c	2009-03-21 15:44:54.000000000 +0100
@@ -45,6 +45,7 @@
 
     ap_rputs("<b>Error!</b>\n", r);
     ap_rputs("<p>", r);
+    
     lua_response = lua_tostring(L, -1);
     ap_rputs(lua_response, r);
     ap_rputs("</p>\n", r);
@@ -100,6 +101,8 @@
 static int lua_handler(request_rec *r)
 {
     apl_dir_cfg *dcfg;
+    int status = 0;
+
     if (strcmp(r->handler, "lua-script")) {
         return DECLINED;
     }
@@ -137,14 +140,36 @@
                               cfg->package_cpaths,
                               &lua_open_callback, NULL);
 
-        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got a vm!");
         if (!L) {
             /* TODO annotate spec with failure reason */
             r->status = HTTP_INTERNAL_SERVER_ERROR;
             ap_rputs("Unable to compile VM, see logs", r);
         }
+
+        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got a vm!");
+
+        if (spec->bytecode && spec->bytecode_len > 0) {
+            status = luaL_loadbuffer(L, spec->bytecode, spec->bytecode_len, spec->file);
+            if (status == 0) {
+                status = lua_pcall(L, 0, LUA_MULTRET, 0);
+            }
+        }
+        else {
+            status = luaL_dofile(L, spec->file);
+        }
+
+        if (status != 0) {
+            report_lua_error(L, r);
+            lua_gc(L, LUA_GCCOLLECT, 0);
+            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                              "lua: Could not compile %s",
+                              spec->file);
+            return OK;
+        }
+
         lua_getglobal(L, d->function_name);
         apl_run_lua_request(L, r);
+
         if (lua_pcall(L, 1, 0, 0)) {
             report_lua_error(L, r);
         }
@@ -221,8 +246,11 @@
                                              &lua_module);
     apr_array_header_t *hook_specs =
         apr_hash_get(cfg->hooks, name, APR_HASH_KEY_STRING);
+
     if (hook_specs) {
         int i;
+        int status = 0;
+
         for (i = 0; i < hook_specs->nelts; i++) {
             apl_mapped_handler_spec *hook_spec =
                 ((apl_mapped_handler_spec **) hook_specs->elts)[i];
@@ -247,8 +275,6 @@
                                   cfg->package_cpaths,
                                   &lua_open_callback, NULL);
 
-
-
             if (!L) {
                 ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r,
                               "lua: Failed to obtain lua interpreter for %s %s",
@@ -256,6 +282,23 @@
                 return HTTP_INTERNAL_SERVER_ERROR;
             }
 
+            if (spec->bytecode && spec->bytecode_len > 0) {
+                status = luaL_loadbuffer(L, spec->bytecode, spec->bytecode_len, spec->file);
+                if (status == 0) {
+                    status = lua_pcall(L, 0, LUA_MULTRET, 0);
+                }
+            }
+            else {
+                status = luaL_dofile(L, hook_spec->file_name);
+            }
+            if (status != 0) {
+                ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r,
+                                  "lua: Could not compile %s",
+                                  hook_spec->file_name);
+                lua_gc(L, LUA_GCCOLLECT, 0);
+                return HTTP_INTERNAL_SERVER_ERROR;
+            }
+
             if (hook_spec->function_name != NULL) {
                 lua_getglobal(L, hook_spec->function_name);
                 if (!lua_isfunction(L, -1)) {
@@ -534,6 +577,7 @@
 
     apr_array_header_t *hook_specs =
         apr_hash_get(cfg->hooks, name, APR_HASH_KEY_STRING);
+
     if (!hook_specs) {
         hook_specs =
             apr_array_make(cmd->pool, 2, sizeof(apl_mapped_handler_spec *));
Common subdirectories: mod_lua_build/test and mod_lua_err/test
