Advertisement
DEv0on

util

May 13th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. function ver()
  2.   return 0.35
  3. end
  4.  
  5. function explode(str, sep)
  6.   local function trim(str)
  7.     return (string.gsub(str, "^%s*(.-)%s*$", "%1"))
  8.   end
  9.  
  10.   local pos, t = 1, {}
  11.   if #sep == 0 or #str == 0 then return end
  12.   for s, e in function() return string.find(str, sep, pos) end do
  13.     table.insert(t, trim(string.sub(str, pos, s-1)))
  14.     pos = e+1
  15.   end
  16.   table.insert(t, trim(string.sub(str, pos)))
  17.   return t
  18. end
  19.  
  20. function isNumeric(inpNum)
  21.   if tonumber(inpNum) ~= nil then
  22.     return true
  23.   else
  24.     return false
  25.   end
  26. end
  27.  
  28. function tableExists(inp_table, inp_string)
  29.   tableExistsPos = {}
  30.   tableExistsReturns = false
  31.   for i=1, table.getn(inp_table) do
  32.     if inp_table[i] == inp_string then
  33.       tableExistsReturns = true
  34.       table.insert(tableExistsPos, i)
  35.     end
  36.   end
  37.   return tableExistsReturns, tableExistsPos
  38. end
  39.  
  40. function tableLongest(_tTable)
  41.   local c = 0
  42.   local pos = nil
  43.   for i=1, #_tTable do
  44.     if string.len(_tTable[i]) > c then
  45.       c = string.len(_tTable[i])
  46.       pos = i
  47.     end
  48.   end
  49.  
  50.   return c, pos
  51. end
  52.  
  53. function makeLn(_iLen, _sSymbol)
  54.   local base = ""
  55.   _iLen = _iLen or 1
  56.   _sSymbol = _sSymbol or "-"
  57.   for i=1, _iLen do
  58.     base = base.._sSymbol
  59.   end
  60.  
  61.   return base
  62.  
  63. end
  64.  
  65. function checkAPI(inp_api, inp_ver)
  66.   if type(inp_api) == "table" then
  67.     if type(inp_api.ver) == "function" then
  68.       if inp_api.ver() >= inp_ver then
  69.         return true
  70.       else
  71.         print("This program cannot run - too old API")
  72.       end
  73.     else
  74.       print("This program cannot run - missing API")
  75.     end
  76.   else
  77.     print("This program cannot run - incompatible API")
  78.   end
  79. end
  80.  
  81. function cls()
  82.   term.clear()
  83.   term.setCursorPos(1, 1)
  84.   return true
  85. end
  86.  
  87. function bitLine(_tLine)
  88.   tmp = {}
  89.   for i=1, math.max(unpack(_tLine)) do
  90.     tmp[i] = 0
  91.     if util.tableExists(_tLine, i) then
  92.       tmp[i] = 1
  93.     end
  94.   end
  95.   return tmp
  96. end
  97.  
  98. function isAdvancedComputer()
  99.   if term.isColor and term.isColor() then
  100.     return true
  101.   else
  102.     return false
  103.   end
  104. end
  105.  
  106. function osVersion()
  107.   return tonumber(string.sub(os.version(), 9))
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement