daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Dec 12th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Implicit indexes of tuples (number<->string conversion)
  2. do
  3.   local function t2i(s)
  4.     local i = 0
  5.     for k = 1, #s do
  6.       i = i * 256 + s:byte(k)
  7.     end
  8.     return i
  9.   end
  10.  
  11.   local function i2t(i)
  12.     local a = {0}
  13.     if i < 256 then
  14.       return string.char(i)
  15.     elseif i > 1 then
  16.       local k = math.ceil(math.log(i+.5)/math.log(256))
  17.       while i > 0 do
  18.         a[k] = i % 256
  19.         i = math.floor(i / 256)
  20.         k = k - 1
  21.       end
  22.     end
  23.     return string.char(unpack(a))
  24.   end
  25.  
  26.   return {
  27.     t2i = t2i,
  28.     i2t = i2t
  29.   }
  30. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top