Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------
- --DATA FUNCTIONS--
- ------------------
- data = {}
- function data.dir(fn)
- local path = debug.getinfo(debug.getinfo(2).func).short_src
- if not fn then
- path = path:reverse()
- path = path:sub(path:find("/",1),-1):reverse()
- end
- return path
- end
- function data.serializeint(int,little)
- int = math.floor(math.abs(int))
- local size = math.ceil(math.logx(int+1,256))
- if size == 0 then size = 1 end
- local t = {}
- for i=1,size-1,1 do
- local value = math.floor(int/math.pow(256,size-i))
- t[i] = string.char(value)
- int = int-value*math.pow(256,size-i)
- end
- table.insert(t,string.char(math.floor(int%256)))
- return (little and table.concat(t):reverse() or table.concat(t))
- end
- function data.deserializeint(int, little)
- local size = string.len(int)
- local value = 0
- for i=1, size do
- local ex = math.pow(256,little and (i-1) or size-i )
- value = value + string.byte(string.sub(int,i,i))*ex
- end
- return value
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement