Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Implicit indexes of tuples (number<->string conversion)
- do
- local function t2i(s)
- local i = 0
- for k = 1, #s do
- i = i * 256 + s:byte(k)
- end
- return i
- end
- local function i2t(i)
- local a = {0}
- if i < 256 then
- return string.char(i)
- elseif i > 1 then
- local k = math.ceil(math.log(i+.5)/math.log(256))
- while i > 0 do
- a[k] = i % 256
- i = math.floor(i / 256)
- k = k - 1
- end
- end
- return string.char(unpack(a))
- end
- return {
- t2i = t2i,
- i2t = i2t
- }
- end
Add Comment
Please, Sign In to add comment