resty: added -I dir for adding dir to Lua module search paths.

This commit is contained in:
Yichun Zhang (agentzh) 2014-08-20 21:45:38 -07:00
parent af058d15db
commit bb71a30a68
1 changed files with 16 additions and 3 deletions

View File

@ -15,7 +15,7 @@ use File::Temp qw( tempdir );
use POSIX qw( WNOHANG ); use POSIX qw( WNOHANG );
my %opts; my %opts;
getopts("he:c:V", \%opts) getopts("he:c:VI:", \%opts)
or usage(1); or usage(1);
if ($opts{h}) { if ($opts{h}) {
@ -32,6 +32,18 @@ if ($opts{V}) {
exec "$nginx_path -V"; exec "$nginx_path -V";
} }
my $lua_package_path_config = '';
if ($opts{I}) {
my $dir = $opts{I};
if (!-d $dir) {
die "Search directory $dir is not found.\n";
}
$lua_package_path_config = <<_EOC_;
lua_package_path "$dir/?.lua;;";
lua_package_cpath "$dir/?.so;;";
_EOC_
}
my $luafile; my $luafile;
if (!defined $opts{e}) { if (!defined $opts{e}) {
$luafile = shift $luafile = shift
@ -124,7 +136,7 @@ http {
access_log off; access_log off;
lua_socket_log_errors off; lua_socket_log_errors off;
resolver @nameservers; resolver @nameservers;
$lua_package_path_config
init_by_lua ' init_by_lua '
local stdout = io.stdout local stdout = io.stdout
local ngx_null = ngx.null local ngx_null = ngx.null
@ -250,12 +262,13 @@ if ($pid == 0) { # child process
sub usage { sub usage {
my $rc = shift; my $rc = shift;
my $msg = <<_EOC_; my $msg = <<_EOC_;
resty [-h] [-c num] [-e prog] [-V] [lua-file] resty [-I dir] [-h] [-c num] [-e prog] [-V] [lua-file]
Options: Options:
-c num set maximal connection count (default: 64). -c num set maximal connection count (default: 64).
-e prog run the inlined Lua code in "prog". -e prog run the inlined Lua code in "prog".
-h print this help. -h print this help.
-I dir Add dir to the search paths for Lua libraries.
-V print the underlying nginx version and configurations. -V print the underlying nginx version and configurations.
For bug reporting instructions, please see: For bug reporting instructions, please see: