do not normalize luajit functions

This commit is contained in:
kikito 2015-04-06 20:44:11 +02:00
parent 686c18c49e
commit 9fcb45d9f2
1 changed files with 146 additions and 142 deletions

22
md5.lua
View File

@ -35,9 +35,12 @@ local char, byte, format, rep, sub =
local bit_or, bit_and, bit_not, bit_xor, bit_rshift, bit_lshift
local ok, bit = pcall(require, 'bit')
if not ok then ok, bit = pcall(require, 'bit32') end
if ok then
bit_or, bit_and, bit_not, bit_xor, bit_rshift, bit_lshift = bit.bor, bit.band, bit.bnot, bit.xor, bit.rshift, bit.lshift
else
ok, bit = pcall(require, 'bit32')
if ok then
bit_not = bit.bnot
@ -52,7 +55,7 @@ if ok then
bit_or, bit_and, bit_xor = normalize(bit.bor), normalize(bit.band), normalize(bit.bxor)
bit_rshift, bit_lshift = normalize(bit.rshift), normalize(bit.lshift)
else
else
local function tbl2number(tbl)
local result = 0
@ -189,21 +192,22 @@ else
end
return bit_and(n, 0xFFFFFFFF)
end
end
end
-- convert little-endian 32-bit int to a 4-char string
local function lei2str(i)
-- convert little-endian 32-bit int to a 4-char string
local function lei2str(i)
local f=function (s) return char( bit_and( bit_rshift(i, s), 255)) end
return f(0)..f(8)..f(16)..f(24)
end
end
-- convert raw string to big-endian int
local function str2bei(s)
-- convert raw string to big-endian int
local function str2bei(s)
local v=0
for i=1, #s do
v = v * 256 + byte(s, i)
end
return v
end
end
-- convert raw string to little-endian int