Created
May 22, 2013 13:00
-
-
Save wendal/5627360 to your computer and use it in GitHub Desktop.
nginx lua模块下的 id转特殊路径
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function id2path(IN) | |
local B,K,OUT,I,D=16,"0123456789ABCDEF","",0 | |
local now = 0 | |
local len = 0 | |
while IN>0 do | |
if len > 0 and math.mod(len,2) == 0 then | |
OUT="/"..OUT | |
end | |
I=I+1 | |
IN,D=math.floor(IN/B),math.mod(IN,B)+1 | |
OUT=string.sub(K,D,D)..OUT | |
len = len + 1 | |
--print(OUT.." "..now..len) | |
end | |
while len < 14 do | |
if len > 0 and math.mod(len,2) == 0 then | |
OUT="/"..OUT | |
end | |
OUT="0"..OUT | |
len = len + 1 | |
end | |
return "/"..OUT | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment