· 5 months ago · Apr 26, 2025, 01:00 PM
1--[[
2 This library contains functions relating to data structures & stuff
3]]
4
5function 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
10end
11
12function 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
19end
20
21function 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
28end
29
30function 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()
36end
37
38function 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
43end