Advertisement
Kodos

[OC] [Lib] kodos.lua

Jul 7th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.69 KB | None | 0 0
  1. local kodos = {}
  2.  
  3. function kodos.str2hex(a)
  4.   return a:gsub(".",function(a)
  5.   return string.format("%02x",a:byte())
  6.   end)
  7.  end
  8.  
  9. function kodos.inc(a,b)
  10.   local c = a + (b or 1)
  11.   return c
  12. end
  13.  
  14. function kodos.dec(a,b)
  15.   local c = a - (b or 1)
  16.   return c
  17. end
  18.  
  19.  function kodos.hex2str(a)
  20.   return a:gsub("..",function(a)
  21.   return string.char(tonumber(a,16))
  22.   end)
  23.  end
  24.  
  25. function kodos.round(num, idp)
  26. lcoal mult = 10^(idp or 0)
  27. return math.floor(num * mult + 0.5) / mult
  28. end
  29.  
  30. function kodos.readFile(filename)
  31.     local file, err = io.open(filename,"rb")
  32.     if not file then
  33.         return nil, err
  34.     end
  35.     local data = file:read("*a")
  36.     file:close()
  37.     return data
  38. end
  39.  
  40. return kodos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement