Skip to content

Commit

Permalink
refactor all
Browse files Browse the repository at this point in the history
  • Loading branch information
alacner committed May 7, 2011
1 parent 20d2d47 commit a326521
Show file tree
Hide file tree
Showing 9 changed files with 716 additions and 292 deletions.
15 changes: 5 additions & 10 deletions README
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,7 @@
-- exapmle: -- example:
location ~/test {
lua_file "/usr/local/nginx/conf/test.lua";
}


location ~/lua { lua_file "/usr/local/nginx/conf/test.lua";
lua_file "/usr/local/nginx/conf/lua.lua";
}



location ~/test {

lua_file "/usr/local/nginx/conf/test.lua";
Tue Apr 26 16:30:00 MST 2011 }
2 changes: 1 addition & 1 deletion config
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fi
ngx_addon_name=ngx_http_lua_module ngx_addon_name=ngx_http_lua_module
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_lua_module" HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_lua_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_lua_module.c $ngx_addon_dir/src/strtok_r.c" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_lua_module.c $ngx_addon_dir/src/strtok_r.c"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ddebug.h $ngx_addon_dir/src/strtok_r.h" NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/strtok_r.h"
CFLAGS="$CFLAGS -DNDK_SET_VAR" CFLAGS="$CFLAGS -DNDK_SET_VAR"


ngx_feature="export symbols by default" ngx_feature="export symbols by default"
Expand Down
44 changes: 44 additions & 0 deletions example/kit.lua
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,44 @@
--Copyright (c) 2011-2015 Zhihua Zhang (alacner@gmail.com)
module('kit', package.seeall)

function print_r(sth)
if type(sth) ~= "table" then
if type(sth) == "nil" then
sth = "nil"
end
print(sth)
return
end

local space, deep = string.rep(' ', 4), 0
local function _dump(t)
for k,v in pairs(t) do
local key = tostring(k)

if type(v) == "table" then
deep = deep + 2
print(string.format("%s[%s] => Table\r\n%s(\r\n",
string.rep(space, deep - 1),
key,
string.rep(space, deep)
)
) --print.
_dump(v)

print(string.format("%s)\r\n",string.rep(space, deep)))
deep = deep - 2
else
print(string.format("%s[%s] => %s\r\n",
string.rep(space, deep + 1),
key,
tostring(v)
)
) --print.
end
end
end

print(string.format("Table\r\n(\r\n"))
_dump(sth)
print(string.format(")\r\n"))
end
66 changes: 37 additions & 29 deletions example/t1.lua
Original file line number Original file line Diff line number Diff line change
@@ -1,57 +1,65 @@
--Copyright (c) 2011-2015 Zhihua Zhang (alacner@gmail.com) --Copyright (c) 2011-2015 Zhihua Zhang (alacner@gmail.com)
--ngx.set_header('Location', "http://www.google.com"); --ngx.set_header('Location', "http://www.google.com");
--do return end --ngx.set_cookie('love', '123456') -- name, value, expire, path, domain, secure
local log = print --ngx.set_cookie('aa', 'ssssss') -- name, value, expire, path, domain, secure
print = ngx.print print = ngx.print
local kit = require("kit") local kit = require("kit")
local print_r = kit.print_r local print_r = kit.print_r


ngx.set_header('Content-Type', "image/png"); --ngx.set_header('Content-Type', "image/png");
--ngx.set_header('Content-Type', "text/html"); ngx.set_header('Content-Type', "text/html");


--local f = io.open('/root/repos/nginx_lua_module/example/t1.lua', 'rb') --local f = io.open('/root/repos/nginx_lua_module/example/t1.lua', 'rb')
--local f = io.open('/root/test.jpg', 'rb') --local f = io.open('/root/test.jpg', 'rb')
--local t = f:read("*a")
--ngx.print(t)


local f = io.open('/root/480x480.png', 'rb') local f = io.open('/root/480x480.png', 'rb')
--local a = f:read("*a") --local t = f:read("*a")
--log(a) --log(a)
local t = f:read(8192) --local t = f:read(8192)
ngx.print(t) --ngx.print(t)
do return end --print_r(ngx)
print_r(ngx) --ngx.flush()
--ngx.print(t)
--print_r(ngx)
--ngx.flush()
--ngx.print(t)
--print_r(ngx)
--local f = io.open('/root/test.jpg', 'rb') --local f = io.open('/root/test.jpg', 'rb')
--local f = assert(io.open(arg[1], "rb")) --local f = assert(io.open(arg[1], "rb"))
--[[
local block = 10
while true do
local bytes = f:read(block)
if not bytes then break end
for b in string.gfind(bytes, ".") do
print_r(string.format("%02X ", string.byte(b)))
end
print_r(string.rep(" ", block - string.len(bytes) + 1))
print_r(string.gsub(bytes, "%c", "."), "\n")
end
--]]

f:close() f:close()
--ngx.print(ngx.set_cookie)
local t = os.time()
ngx.set_cookie('love1', "me") -- name, value, expire, path, domain, secure
--ngx.set_cookie('love2', "me", 100) -- name, value, expire, path, domain, secure
--ngx.set_cookie('love3', '123456') -- name, value, expire, path, domain, secure
--ngx.set_cookie('isopen', 'true', 1000, '/', '192.168.137.126') -- name, value, expire, path, domain, secure
ngx.set_header('X-Memc-Flags', "11111111111111");
ngx.set_header('X-Memc-Flags', "2222222222222222222222222");
ngx.set_header('X-Memc-Flags', "f1111122222222333333334444445");
print_r(ngx) print_r(ngx)
--print_r(t) ngx.eof()
do return end

local http = require("socket.http")
local r, e, h, l = http.request("http://www.6uu.com")
print_r(h)
print_r(l)
print_r(m)
ngx.eof()


do return end do return end
--ngx.print(ngx.set_cookie)
ngx.set_cookie('love', '123456') -- name, value, expire, path, domain, secure
ngx.set_cookie('isopen', 'true', 1000, '/', '192.168.137.126') -- name, value, expire, path, domain, secure
print_r(ngx)




local socket = require("socket") local socket = require("socket")
local tcp = socket.tcp() local tcp = socket.tcp()
tcp:settimeout(1) tcp:settimeout(1)
local n,e,h = tcp:connect("www.6uu.com","80") local n,e,h = tcp:connect("www.google.com","80")
print_r(n) print_r(n)
print_r(e) --print_r(e)
print_r(h) print_r(h)
ngx.eof()


do return end do return end


Expand Down
13 changes: 0 additions & 13 deletions src/ddebug.h

This file was deleted.

28 changes: 0 additions & 28 deletions src/ngx_http_lua_core.c

This file was deleted.

2 changes: 0 additions & 2 deletions src/ngx_http_lua_core.h

This file was deleted.

Loading

0 comments on commit a326521

Please sign in to comment.