From: Paul Querna Date: Mon, 22 Dec 2008 21:15:32 +0000 (+0000) Subject: Hack to add basic support for LuaJIT. X-Git-Tag: 2.3.1~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4fbf0b5ff3ae09357c2538ecd21f0c584dca2739;p=apache Hack to add basic support for LuaJIT. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@728779 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/lua/config.m4 b/modules/lua/config.m4 index 5d123948b7..0e263e447a 100644 --- a/modules/lua/config.m4 +++ b/modules/lua/config.m4 @@ -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 ]) diff --git a/modules/lua/lua_vmprep.c b/modules/lua/lua_vmprep.c index b57e34c91e..870f41a346 100644 --- a/modules/lua/lua_vmprep.c +++ b/modules/lua/lua_vmprep.c @@ -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"); }