Skip to content

Commit 83f2300

Browse files
committed
add lua-relang, change luajit version
1 parent 2647011 commit 83f2300

File tree

6 files changed

+128
-7
lines changed

6 files changed

+128
-7
lines changed

conf/dyn.conf.1002

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ events {
1212

1313
http {
1414
lua_code_cache off;
15-
lua_package_path '/home/github/tengcdn/lualib/cdn/?.lua;/home/github/tengcdn/lualib/?.lua;;';
15+
lua_package_path '/home/github/tengcdn/lualib/?.lua;;';
1616
lua_package_cpath '/home/github/tengcdn/lualib/?.so;;';
1717
lua_shared_dict itesty_limit 100k;
1818
lua_shared_dict blocked_iplist 10m;

conf/dyn.conf.1003

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ http {
3737
}
3838
}
3939

40+
location /test {
41+
content_by_lua_block {
42+
local test = require "cdn.test"
43+
test.version()
44+
ngx.say("done")
45+
}
46+
}
47+
4048
location /limit {
4149
access_by_lua_block {
4250
local limits = require("resty.iresty_limits")

lualib/cdn/access.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local cjson = require "cjson"
2-
local cookie = require "cookie"
2+
local cookie = require "cdn.cookie"
33

44
local tostring, ipairs, pairs, type, tonumber, next, unpack =
55
tostring, ipairs, pairs, type, tonumber, next, unpack

lualib/cdn/test.lua

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local ngx_say = ngx.say
2+
local _M = {
3+
_VERSION = '0.01',
4+
}
5+
local mt = { __index = _M }
6+
7+
function _M.version()
8+
if jit then
9+
ngx_say(jit.version)
10+
else
11+
ngx_say("Not LuaJIT!")
12+
end
13+
end
14+
15+
return _M

script/build.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ make
5757
buildReleaseNgx()
5858
{
5959
cd $NGINX
60-
export LUAJIT_INC=/usr/local/luajit-2.0.1/include/luajit-2.0/
61-
export LUAJIT_LIB=/usr/local/luajit-2.0.1/lib/
60+
export LUAJIT_INC=/usr/local/include/luajit-2.1/
61+
export LUAJIT_LIB=/usr/local/lib
6262
./configure --prefix=/nginx \
6363
--with-http_ssl_module \
6464
--without-http_fastcgi_module \
@@ -81,7 +81,7 @@ buildReleaseNgx()
8181
--add-module=../headers-more-nginx-module \
8282
--with-ld-opt="-ltcmalloc_minimal -L/home/github/tengcdn/lualib -Wl,--whole-archive -lcdn -Wl,--no-whole-archive" \
8383
--with-cc-opt="-O2"
84-
sed -i 's#-L/usr/local/luajit-2.0.1/lib/ -lluajit-5.1#/usr/local/lib/libluajit-5.1.a#' objs/Makefile #静态编译
84+
sed -i 's#-L/usr/local/lib -lluajit-5.1#/usr/local/lib/libluajit-5.1.a#' objs/Makefile #静态编译
8585
sed -i 's#HTTP_AUX_FILTER_MODULES#HTTP_MODULES#' ../lua-upstream-cache-nginx-module/config #fix config
8686
make
8787

@@ -123,11 +123,11 @@ for f in $lualib/cdn/*.lua; do
123123
r2="${BASH_REMATCH[2]}"
124124
\cp $f $temp_dir/${r1}_${r2}.lua
125125
echo $r1/$r2.lua;
126-
luajit -bg $temp_dir/${r1}_${r2}.lua $temp_dir/${r1}_${r2}.o
126+
luajit-2.1.0-beta1 -b $temp_dir/${r1}_${r2}.lua $temp_dir/${r1}_${r2}.o
127127
done
128128
rm -f $lualib/libcdn.a
129129
ar rcus $lualib/libcdn.a $temp_dir/*.o
130-
#rm -rf $temp_dir
130+
rm -rf $temp_dir
131131
}
132132
resetNgx()
133133
{

script/lua-releng

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env perl
2+
3+
use strict;
4+
use warnings;
5+
6+
use Getopt::Std;
7+
8+
my (@luas, @tests);
9+
10+
my %opts;
11+
getopts('Lse', \%opts) or die "Usage: lua-releng [-L] [-s] [-e] [files]\n";
12+
13+
my $silent = $opts{s};
14+
my $stop_on_error = $opts{e};
15+
my $no_long_line_check = $opts{L};
16+
17+
if ($#ARGV != -1) {
18+
@luas = @ARGV;
19+
20+
} else {
21+
@luas = map glob, qw{ *.lua lib/*.lua lib/*/*.lua lib/*/*/*.lua lib/*/*/*/*.lua lib/*/*/*/*/*.lua };
22+
if (-d 't') {
23+
@tests = map glob, qw{ t/*.t t/*/*.t t/*/*/*.t };
24+
}
25+
}
26+
27+
for my $f (sort @luas) {
28+
process_file($f);
29+
}
30+
31+
for my $t (@tests) {
32+
blank(qq{grep -H -n --color -E '\\--- ?(ONLY|LAST)' $t});
33+
}
34+
# p: prints a string to STDOUT appending \n
35+
# w: prints a string to STDERR appending \n
36+
# Both respect the $silent value
37+
sub p { print "$_[0]\n" if (!$silent) }
38+
sub w { warn "$_[0]\n" if (!$silent) }
39+
40+
# blank: runs a command and looks at the output. If the output is not
41+
# blank it is printed (and the program dies if stop_on_error is 1)
42+
sub blank {
43+
my ($command) = @_;
44+
if ($stop_on_error) {
45+
my $output = `$command`;
46+
if ($output ne '') {
47+
die $output;
48+
}
49+
} else {
50+
system($command);
51+
}
52+
}
53+
54+
my $version;
55+
sub process_file {
56+
my $file = shift;
57+
# Check the sanity of each .lua file
58+
open my $in, $file or
59+
die "ERROR: Can't open $file for reading: $!\n";
60+
my $found_ver;
61+
while (<$in>) {
62+
my ($ver, $skipping);
63+
if (/(?x) (?:_VERSION|version) \s* = .*? ([\d\.]*\d+) (.*? SKIP)?/) {
64+
my $orig_ver = $ver = $1;
65+
$found_ver = 1;
66+
$skipping = $2;
67+
$ver =~ s{^(\d+)\.(\d{3})(\d{3})$}{join '.', int($1), int($2), int($3)}e;
68+
w("$file: $orig_ver ($ver)");
69+
last;
70+
71+
} elsif (/(?x) (?:_VERSION|version) \s* = \s* ([a-zA-Z_]\S*)/) {
72+
w("$file: $1");
73+
$found_ver = 1;
74+
last;
75+
}
76+
77+
if ($ver and $version and !$skipping) {
78+
if ($version ne $ver) {
79+
die "$file: $ver != $version\n";
80+
}
81+
} elsif ($ver and !$version) {
82+
$version = $ver;
83+
}
84+
}
85+
if (!$found_ver) {
86+
w("WARNING: No \"_VERSION\" or \"version\" field found in `$file`.");
87+
}
88+
close $in;
89+
90+
p("Checking use of Lua global variables in file $file...");
91+
p("\top no.\tline\tinstruction\targs\t; code");
92+
blank("luac -p -l $file | grep -E '[GS]ETGLOBAL' | grep -vE '\\<(require|type|tostring|error|ngx|ndk|jit|setmetatable|getmetatable|string|table|io|os|print|tonumber|math|pcall|xpcall|unpack|pairs|ipairs|assert|module|package|coroutine|[gs]etfenv|next|rawget|rawset|rawlen)\\>'");
93+
unless ($no_long_line_check) {
94+
p("Checking line length exceeding 80...");
95+
blank("grep -H -n -E --color '.{81}' $file");
96+
}
97+
}
98+

0 commit comments

Comments
 (0)