Advertisement
MiaMyLove

My_Little_Lua_Helpers.lua SunShineSilver.mdA

Mar 15th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. --[[ ** *** *** *** ** *** *** *** ** ]]
  2. --[[ ** SunShineSilver.mdA 2019-03 ** ]]
  3. --[[ ** *** *** *** ** *** *** *** ** ]]
  4. --[[         mdA_LuaPlugin.lua        ]]
  5. --[[ Print Function]]
  6. function _p(rint) print(rint) end
  7. --[[ String _Functions() #short ]]
  8. --function _nil(s) if s == nil or s == '' then _p("..got no value(nil)") return true else return false end
  9. function _find(s) return string.find(s) end
  10. function _sub(s,v1,v2)if v2~=nil then return string.sub(s,v1,v2) else return string.sub(s,v1) end end
  11. function _len(s) return string.len(s) end
  12. function _gsub(s,pat,rep) return string.gsub(s,pat,rep) end
  13. function _char(i1, i2,...) return string.char(i1, i2,...) end
  14. function _match(s,pat,inlen_) return string.match(s,pat,inlen_) end
  15. function _byte(s,i,j) return string.gmatch(s,pat) end
  16. function _dump(_function) return string.dump(_function) end
  17. function _replay(s,replay) return string.rep(s,replay) end
  18. function _format(s,e1,e2,...) return string.format(s,e1,e2,...) end
  19. function _reverse(s,replay) return string.reverse(s) end
  20. function _low(s) return string.lower(s) end
  21. function _upp(s) return string.upper(s) end
  22. --[[subfunc]]function ___Title(first,rest) return first:upper()..rest:lower()end--[[subfunc]]
  23. function _title(s) return _gsub(s,"(%a)([%w']*)",___Title) end;
  24. function ToTitle(s) return _title(s)end
  25. --      >> "(%a)([%w_']*)"  <<-with "_" = Array_data_verify and not Data_Verify_Event
  26. -- string.find(s, pattern [, index [, plain]])
  27. -- string.format(s, e1, e2, ...)
  28. -- string.gmatch(s, pattern)
  29. -- string.gsub(s, pattern, replace [, n])
  30. -- string.len(s)
  31. -- string.lower(s)
  32. -- string.upper(s)
  33. -- string.match (s, pattern [, index])
  34. -- string.rep(s, n)
  35. -- string.reverse(s)
  36. -- string.sub(s, i [, j])
  37. -- string.char(i1, i2, ...)
  38. -- string.byte(s [, i [, j]])
  39. -- string.dump(function)
  40. function DecToHex(decimalIN) -- convert decimal to hex value
  41.     local decimalDO = decimalIN
  42.     local hexValue = string.format("%X", decimalDO)
  43.     local hexOUT = tostring('0x'..hexValue)
  44.     return hexOUT
  45. end
  46. function HexToDec(hexIN) -- convert hex to decimal value
  47.     local decOUT = tonumber("0x"..hexIN)
  48.     decOUT = string.format("%X", decOUT)
  49.     return decOUT
  50. end
  51. function string.fromhex(str)
  52.     return (str:gsub('..', function (cc)
  53.         return string.char(tonumber(cc, 16))
  54.     end))
  55. end
  56. function convert(inp)
  57.    if (not inp) then
  58.       return false;
  59.    end
  60.    local a,b = tonumber(inp),tonumber('0x'..inp) -- decimal/hex
  61.    if (a) then
  62.       return a;
  63.    elseif(b) then
  64.       return b;
  65.    end
  66. end
  67. function string.tohex(str) return (str:gsub('.', function (c) return string.format('%02X', string.byte(c)) end)) end
  68. function string.trimstart(s, c) if (not c) then c = ' '; end  s = string.reverse(s); s = string.trimend(s, c); return string.reverse(s); end
  69. -- desc: Trims the end of a string for whitespace.
  70. function string.trimend(s, c)
  71.     if (not c) then c = ' '; end if (string.sub(s, -1) == c) then  
  72.       s = string.sub(s, 0, -2); s = string.trimend(s, c);
  73.     end return s;
  74. end
  75. -- desc: Trims a string of whitespace.
  76. function string.trim(s, c) if (not c) then c = ' '; end
  77.     s = string.trimstart(s, c); s = string.trimend(s, c);
  78.     return s;
  79. end -- desc: Converts the given string to a hex array string.
  80. function str2hexstr(str)
  81.     local ret = ''; for x = 1, #str do
  82.         local val = str:sub(x, x);
  83.         local c = string.byte(val);
  84.         ret = ret..'0x' .. string.format('%02X ', c);
  85.     end
  86.     return ret:trim();
  87. end
  88. function _dec2hex(dec)  local b,k,r,i,d=16,"0123456789ABCDEF","",0
  89.   while dec>0 do i=i+1 dec,d=math.floor(dec/b),math.mod(dec,b)+1 r=string.sub(k,d,d)..r end
  90.   return r
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement