Advertisement
Jameelo

systemLib

Apr 26th, 2025
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | Gaming | 0 0
  1. --[[
  2.     This library contains functions relating to data structures & stuff
  3. ]]
  4.  
  5. function apiExists(path) -- Check if an API is real or not
  6.     if os.loadAPI(path) ~= false then
  7.         return true
  8.     end
  9.     return false
  10. end
  11.  
  12. function dictLookup(dict,item) -- Checks to see if item is a key in dict, and return its value
  13.     for k,v in pairs(dict) do
  14.         if k == item then
  15.             return v
  16.         end
  17.     end
  18.     return false
  19. end
  20.  
  21. function contains(table,element) -- Check to see if element is in table
  22.     for _, value in pairs(table) do
  23.         if value == element then
  24.           return true
  25.         end
  26.     end
  27.     return false
  28. end
  29.  
  30. function saveFile(table,saveFileID)
  31.     local tableString = textutils.serialize(table)
  32.     --save tableString to file
  33.     local tFile = fs.open(saveFileID, "w")
  34.     tFile.write(tableString)
  35.     tFile.close()
  36. end
  37.  
  38. function loadFile(fileID) -- read table from file
  39.     local tFile = fs.open(fileID, "r")
  40.     local fileContents = tFile.readAll()
  41.     local readTable = textutils.unserialize(fileContents)
  42.     return readTable
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement