Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 72514 invoked from network); 3 Jan 2008 18:29:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jan 2008 18:29:37 -0000 Received: (qmail 17853 invoked by uid 500); 3 Jan 2008 18:29:25 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 17818 invoked by uid 500); 3 Jan 2008 18:29:25 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 17807 invoked by uid 99); 3 Jan 2008 18:29:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jan 2008 10:29:25 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jan 2008 18:29:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6068F1A9832; Thu, 3 Jan 2008 10:29:12 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r608588 - in /httpd/mod_wombat/trunk: docs/basic-configuration.txt mod_wombat.c mod_wombat.h vmprep.c vmprep.h Date: Thu, 03 Jan 2008 18:29:11 -0000 To: cvs@httpd.apache.org From: brianm@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080103182912.6068F1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: brianm Date: Thu Jan 3 10:29:06 2008 New Revision: 608588 URL: http://svn.apache.org/viewvc?rev=608588&view=rev Log: Patch from Matthew Burke to add a LuaPackageCPath directive to allow loading lua modules written in C Modified: httpd/mod_wombat/trunk/docs/basic-configuration.txt httpd/mod_wombat/trunk/mod_wombat.c httpd/mod_wombat/trunk/mod_wombat.h httpd/mod_wombat/trunk/vmprep.c httpd/mod_wombat/trunk/vmprep.h Modified: httpd/mod_wombat/trunk/docs/basic-configuration.txt URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/docs/basic-configuration.txt?rev=608588&r1=608587&r2=608588&view=diff ============================================================================== --- httpd/mod_wombat/trunk/docs/basic-configuration.txt (original) +++ httpd/mod_wombat/trunk/docs/basic-configuration.txt Thu Jan 3 10:29:06 2008 @@ -47,12 +47,19 @@ LuaPackagePath /path/to/include/?.lua Add a path to lua's module search path. Follows the same - conventions as lua (ie, can do shared libraries, etc). - This just munges the package.path in the lua vms. + conventions as lua. This just munges the package.path in the + lua vms. Examples: LuaPackagePath /scripts/lib/?.lua LuaPackagePath /scripts/lib/?/init.lua + + LuaPackageCPath /path/to/include/?.soa + Add a path to lua's shared library search path. Follows the same + conventions as lua. This just munges the package.cpath in the + lua vms. + + Examples: LuaPackagePath /scripts/lib/?.so LuaCodeCache stat|forever|never Modified: httpd/mod_wombat/trunk/mod_wombat.c URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/mod_wombat.c?rev=608588&r1=608587&r2=608588&view=diff ============================================================================== --- httpd/mod_wombat/trunk/mod_wombat.c (original) +++ httpd/mod_wombat/trunk/mod_wombat.c Thu Jan 3 10:29:06 2008 @@ -110,7 +110,7 @@ ap_rputs("Unable to compile VM, see logs", r); } lua_getglobal(L, d->function_name); - apw_run_wombat_request(L, r); + apw_run_wombat_request(L, r); if (lua_pcall(L, 1, 0, 0)) { report_lua_error(L, r); } @@ -179,7 +179,7 @@ lua_State* L = apw_rgetvm(r, spec); lua_getglobal(L, hook_spec->function_name); - apw_run_wombat_request(L, r); + apw_run_wombat_request(L, r); if (lua_pcall(L, 1, 1, 0)) { report_lua_error(L, r); return 500; @@ -299,13 +299,10 @@ return register_named_file_function_hook("quick", cmd, _cfg, file, function); } -/** - * Called for config directive which looks like - * LuaPackagePath /lua/package/path/mapped/thing/like/this/?.lua - */ -const char* register_package_dir(cmd_parms *cmd, void *_cfg, const char *arg) { + + +static const char* register_package_helper(cmd_parms *cmd, const char *arg, apr_array_header_t *dir_array) { apr_status_t rv; - apw_dir_cfg* cfg = (apw_dir_cfg*)_cfg; apw_server_cfg *server_cfg = ap_get_module_config(cmd->server->module_config, &wombat_module); char *fixed_filename; @@ -314,10 +311,31 @@ return apr_psprintf(cmd->pool, "Unable to build full path to file, %s", arg); } - *(const char**)apr_array_push(cfg->package_paths) = fixed_filename; + *(const char**)apr_array_push(dir_array) = fixed_filename; return NULL; } + +/** + * Called for config directive which looks like + * LuaPackagePath /lua/package/path/mapped/thing/like/this/?.lua + */ +const char* register_package_dir(cmd_parms *cmd, void *_cfg, const char *arg) { + apw_dir_cfg* cfg = (apw_dir_cfg*)_cfg; + + return register_package_helper(cmd, arg, cfg->package_paths); +} + +/** + * Called for config directive which looks like + * LuaPackageCPath /lua/package/path/mapped/thing/like/this/?.so + */ +const char* register_package_cdir(cmd_parms *cmd, void *_cfg, const char *arg) { + apw_dir_cfg* cfg = (apw_dir_cfg*)_cfg; + + return register_package_helper(cmd, arg, cfg->package_cpaths); +} + /** * Called for config directive which looks like * LuaCodeCache @@ -386,6 +404,9 @@ AP_INIT_TAKE1("LuaPackagePath", register_package_dir, NULL, OR_ALL, "Add a directory to lua's package.path"), + AP_INIT_TAKE1("LuaPackageCPath", register_package_cdir, NULL, OR_ALL, + "Add a directory to lua's package.cpath"), + AP_INIT_TAKE23("MapLuaHandler", map_lua_handler, NULL, OR_ALL, "Map a path to a lua handler"), @@ -432,6 +453,7 @@ static void* create_dir_config(apr_pool_t *p, char *dir) { apw_dir_cfg* cfg = apr_palloc(p, sizeof(apw_dir_cfg)); cfg->package_paths = apr_array_make(p, 2, sizeof(char*)); + cfg->package_cpaths = apr_array_make(p, 2, sizeof(char*)); cfg->mapped_handlers = apr_array_make(p, 1, sizeof(apw_mapped_handler_spec*)); cfg->code_cache_style = APW_CODE_CACHE_STAT; cfg->pool = p; Modified: httpd/mod_wombat/trunk/mod_wombat.h URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/mod_wombat.h?rev=608588&r1=608587&r2=608588&view=diff ============================================================================== --- httpd/mod_wombat/trunk/mod_wombat.h (original) +++ httpd/mod_wombat/trunk/mod_wombat.h Thu Jan 3 10:29:06 2008 @@ -65,6 +65,7 @@ typedef struct { apr_array_header_t* package_paths; + apr_array_header_t* package_cpaths; /** * mapped handlers Modified: httpd/mod_wombat/trunk/vmprep.c URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/vmprep.c?rev=608588&r1=608587&r2=608588&view=diff ============================================================================== --- httpd/mod_wombat/trunk/vmprep.c (original) +++ httpd/mod_wombat/trunk/vmprep.c Thu Jan 3 10:29:06 2008 @@ -238,6 +238,38 @@ return APR_SUCCESS; } + + + + +static void munge_path(lua_State *L, const char *field, + const char *sub_pat, const char *rep_pat, + apr_pool_t *pool, apr_array_header_t *paths, + const char *file) { + lua_getglobal(L, "package"); + lua_getfield(L, -1, field); + const char* current = lua_tostring(L, -1); + const char* parent_dir = ap_make_dirstr_parent(pool, file); + const char* pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL); + luaL_gsub(L, current, rep_pat, pattern); + lua_setfield(L, -3, field); + lua_getfield(L, -2, field); + const char* modified = lua_tostring(L, -1); + lua_pop(L, 2); + + char * part = apr_pstrdup(pool, modified); + int i; + for (i = 0; i < paths->nelts; i++) { + const char *new_path = ((const char**)paths->elts)[i]; + part = apr_pstrcat(pool, part, ";", new_path, NULL); + } + lua_pushstring(L, part); + lua_setfield(L, -2, field); + lua_pop(L, 1); // pop "package" off the stack +} + + + /** * pool is a working pool or lifecycle pool? */ @@ -247,27 +279,10 @@ lua_State* L = luaL_newstate(); open_lualibs(L); apw_run_wombat_open(L, pool); - lua_getglobal(L, "package"); - lua_getfield(L, -1, "path"); - const char* current = lua_tostring(L, -1); - const char* parent_dir = ap_make_dirstr_parent(pool, spec->file); - const char* pattern = apr_pstrcat(pool, parent_dir, "?.lua", NULL); - luaL_gsub(L, current, "./?.lua", pattern); - lua_setfield(L, -3, "path"); - lua_getfield(L, -2, "path"); - const char* modified = lua_tostring(L, -1); - lua_pop(L, 2); - - - char * part = apr_pstrdup(pool, modified); - int i; - for (i = 0; i < spec->package_paths->nelts; i++) { - const char *new_path = ((const char**)spec->package_paths->elts)[i]; - part = apr_pstrcat(pool, part, ";", new_path, NULL); - } - lua_pushstring(L, part); - lua_setfield(L, -2, "path"); - lua_pop(L, 1); // pop "package" off the stack + + munge_path(L, "path", "?.lua", "./?.lua", pool, spec->package_paths, spec->file); + munge_path(L, "cpath", "?.so", "./?.so", pool, spec->package_cpaths, spec->file); + if (load_file(pool, L, cache, spec)) { ap_log_perror(APLOG_MARK, APLOG_ERR, 0, pool, @@ -387,6 +402,7 @@ switch (spec->scope) { case APW_SCOPE_REQUEST: spec->package_paths = cfg->package_paths; + spec->package_cpaths = cfg->package_cpaths; spec->pool = r->pool; L = get_request_vm(r, spec); return L; @@ -398,6 +414,7 @@ case APW_SCOPE_SERVER: spec->package_paths = cfg->package_paths; + spec->package_cpaths = cfg->package_cpaths; spec->pool = r->pool; L = get_server_vm(r->server, spec); return L; @@ -407,6 +424,7 @@ // fall through on purpose case APW_SCOPE_ONCE: spec->package_paths = cfg->package_paths; + spec->package_cpaths = cfg->package_cpaths; L = create_vm(spec, server_cfg->code_cache, r->pool); if (spec->pool == NULL) { apr_pool_cleanup_register(r->pool, L, cleanup_lua, apr_pool_cleanup_null); Modified: httpd/mod_wombat/trunk/vmprep.h URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/vmprep.h?rev=608588&r1=608587&r2=608588&view=diff ============================================================================== --- httpd/mod_wombat/trunk/vmprep.h (original) +++ httpd/mod_wombat/trunk/vmprep.h Thu Jan 3 10:29:06 2008 @@ -50,6 +50,7 @@ // NEED TO ADD ADDITIONAL PACKAGE PATHS AS PART OF SPEC INSTEAD OF DIR CONFIG apr_array_header_t* package_paths; + apr_array_header_t* package_cpaths; // name of base file to load in the vm const char *file;