]> granicus.if.org Git - apache/commitdiff
Hack to add basic support for LuaJIT.
authorPaul Querna <pquerna@apache.org>
Mon, 22 Dec 2008 21:15:32 +0000 (21:15 +0000)
committerPaul Querna <pquerna@apache.org>
Mon, 22 Dec 2008 21:15:32 +0000 (21:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@728779 13f79535-47bb-0310-9956-ffa450edef68

modules/lua/config.m4
modules/lua/lua_vmprep.c

index 5d123948b7029260b74159cc85a76725644d0574..0e263e447a805c41223eaad0a938586a46a3d92e 100644 (file)
@@ -88,6 +88,7 @@ if test -z "${LUA_LIBS}"; then
   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 
 ])
index b57e34c91e62561aaa6ef113274665aac1e9d716..870f41a3461767b99613741d81b58d2118ddb62f 100644 (file)
@@ -266,6 +266,25 @@ static void munge_path(lua_State *L,
     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 @@ lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
                       "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_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
             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");
     }