Permalink
Browse files

feature: special nginx variable $prefix is now available in the lua_p…

…ackage_path and lua_package_cpath, which evaluates to the server prefix string (as specified by the -p PREFIX command-line option of the "nginx" executable). thanks Matthieu Tourne for the patch.
  • Loading branch information...
1 parent efb33ad commit 087694f4a277e55d104c932ec4f9ad86e93c0acd @agentzh agentzh committed May 22, 2012
Showing with 76 additions and 1 deletion.
  1. +8 −1 src/ngx_http_lua_util.c
  2. +68 −0 t/074-prefix-var.t
View
@@ -63,12 +63,19 @@ static void
ngx_http_lua_set_path(ngx_conf_t *cf, lua_State *L, int tab_idx,
const char *fieldname, const char *path, const char *default_path)
{
- const char *tmp_path;
+ const char *tmp_path;
+ const char *prefix;
/* XXX here we use some hack to simplify string manipulation */
tmp_path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
LUA_PATH_SEP AUX_MARK LUA_PATH_SEP);
+ lua_pushlstring(L, (char *) cf->cycle->prefix.data, cf->cycle->prefix.len);
+ prefix = lua_tostring(L, -1);
+ tmp_path = luaL_gsub(L, tmp_path, "$prefix", prefix);
+ tmp_path = luaL_gsub(L, tmp_path, "${prefix}", prefix);
+ lua_pop(L, 3);
+
dd("tmp_path path: %s", tmp_path);
tmp_path = luaL_gsub(L, tmp_path, AUX_MARK, default_path);
View
@@ -0,0 +1,68 @@
+# vim:set ft= ts=4 sw=4 et fdm=marker:
+use lib 'lib';
+use Test::Nginx::Socket;
+
+#worker_connections(1014);
+#master_on();
+#workers(2);
+#log_level('warn');
+
+repeat_each(2);
+#repeat_each(1);
+
+plan tests => repeat_each() * (blocks() * 3);
+
+#no_diff();
+#no_long_string();
+run_tests();
+
+__DATA__
+
+=== TEST 1: $prefix
+--- http_config: lua_package_path "$prefix/html/?.lua;;";
+--- config
+ location /t {
+ content_by_lua '
+ local foo = require "foo"
+ foo.go()
+ ';
+ }
+--- user_files
+>>> foo.lua
+module("foo", package.seeall)
+
+function go()
+ ngx.say("Greetings from module foo.")
+end
+--- request
+GET /t
+--- response_body
+Greetings from module foo.
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: ${prefix}
+--- http_config: lua_package_path "${prefix}html/?.lua;;";
+--- config
+ location /t {
+ content_by_lua '
+ local foo = require "foo"
+ foo.go()
+ ';
+ }
+--- user_files
+>>> foo.lua
+module("foo", package.seeall)
+
+function go()
+ ngx.say("Greetings from module foo.")
+end
+--- request
+GET /t
+--- response_body
+Greetings from module foo.
+--- no_error_log
+[error]
+

0 comments on commit 087694f

Please sign in to comment.