From 60d897e2298ca1033c79dca8895eaa3a20a63752 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 6 Apr 2015 16:54:24 +0200 Subject: [PATCH] attempt to fix lua 5.2 --- md5.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/md5.lua b/md5.lua index a68bbc3..bf57972 100644 --- a/md5.lua +++ b/md5.lua @@ -39,8 +39,20 @@ 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.bor, bit.band, bit.bnot, bit.bxor - bit_rshift, bit_lshift = bit.rshift, bit.lshift + + bit_not = bit.bnot + + local tobit = function(n) + return n <= 0x7fffffff and n or -(bit_not(n) + 1) + end + + local normalize = function(f) + return function(a,b) return tobit(f(tobit(a), tobit(b))) end + end + + bit_or, bit_and, bit_xor = normalize(bit.bor), normalize(bit.band), normalize(bit.bxor) + bit_rshift, bit_lshift = normailize(bit.rshift), normalize(bit.lshift) + else local function check_int(n) -- checking not float