You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by pq...@apache.org on 2008/12/22 22:15:32 UTC

svn commit: r728779 - in /httpd/httpd/trunk/modules/lua: config.m4 lua_vmprep.c

Author: pquerna
Date: Mon Dec 22 13:15:32 2008
New Revision: 728779

URL: http://svn.apache.org/viewvc?rev=728779&view=rev
Log:
Hack to add basic support for LuaJIT.

Modified:
    httpd/httpd/trunk/modules/lua/config.m4
    httpd/httpd/trunk/modules/lua/lua_vmprep.c

Modified: httpd/httpd/trunk/modules/lua/config.m4
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/config.m4?rev=728779&r1=728778&r2=728779&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/config.m4 (original)
+++ httpd/httpd/trunk/modules/lua/config.m4 Mon Dec 22 13:15:32 2008
@@ -88,6 +88,7 @@
   ifelse([$2], , AC_MSG_ERROR([Lua 5.1 library is required]), $2)
 else
   AC_MSG_NOTICE([using '${LUA_LIBS}' for Lua Library])
+  AC_ARG_ENABLE(luajit, [--enable-luajit  Enable LuaJit Support], APR_ADDTO(CPPFLAGS, ["-DAP_ENABLE_LUAJIT"]))
   ifelse([$1], , , $1) 
 fi 
 ])

Modified: httpd/httpd/trunk/modules/lua/lua_vmprep.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_vmprep.c?rev=728779&r1=728778&r2=728779&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_vmprep.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_vmprep.c Mon Dec 22 13:15:32 2008
@@ -266,6 +266,25 @@
     lua_pop(L, 1);              /* pop "package" off the stack     */
 }
 
+#ifdef AP_ENABLE_LUAJIT
+static int loadjitmodule(lua_State *L, apr_pool_t *lifecycle_pool) {
+    lua_getglobal(L, "require");
+    lua_pushliteral(L, "jit.");
+    lua_pushvalue(L, -3);
+    lua_concat(L, 2);
+    if (lua_pcall(L, 1, 1, 0)) {
+        const char *msg = lua_tostring(L, -1);
+        ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool,
+                      "Failed to init LuaJIT: %s", msg);
+        return 1;
+    }
+    lua_getfield(L, -1, "start");
+    lua_remove(L, -2);  /* drop module table */
+    return 0;
+}
+
+#endif
+
 lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
                              apl_vm_spec *spec,
                              apr_array_header_t *package_paths,
@@ -280,6 +299,9 @@
                       "creating lua_State with file %s", spec->file);
         /* not available, so create */
         L = luaL_newstate();
+#ifdef AP_ENABLE_LUAJIT
+        luaopen_jit(L);
+#endif
         luaL_openlibs(L);
         if (package_paths) {
             munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool,
@@ -305,6 +327,9 @@
             lua_pcall(L, 0, LUA_MULTRET, 0);
         }
 
+#ifdef AP_ENABLE_LUAJIT
+        loadjitmodule(L, lifecycle_pool);
+#endif
         lua_pushlightuserdata(L, lifecycle_pool);
         lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Wombat.pool");
     }