DabDaddy6223

generic_api

Aug 2nd, 2026 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. function readFileToTable(path)
  2.     if not fs.exists(path) then
  3.         return nil, "File does not exist"
  4.     end
  5.  
  6.     local file = fs.open(path, "r")
  7.     if not file then
  8.         return nil, "Failed to open file"
  9.     end
  10.  
  11.     local lines = {}
  12.  
  13.     while true do
  14.         local line = file.readLine()
  15.         if line == nil then
  16.             break
  17.         end
  18.  
  19.         table.insert(lines, line)
  20.     end
  21.  
  22.     file.close()
  23.  
  24.     return lines
  25. end
  26.  
  27. function hasValue (tab, val)
  28.     for index, value in ipairs(tab) do
  29.         if value == val then
  30.             return true
  31.         end
  32.     end
  33.  
  34.     return false
  35. end
  36.  
  37. function printKeys(tab)
  38.     -- Source - https://stackoverflow.com/a/12674376
  39.     -- Posted by lhf
  40.     -- Retrieved 2026-06-11, License - CC BY-SA 3.0
  41.  
  42.     local keyset={}
  43.     local n=0
  44.  
  45.     for k,v in pairs(tab) do
  46.         n=n+1
  47.         keyset[n]=k
  48.     end
  49.  
  50.     print(textutils.serialise(keyset))
  51. end
Advertisement
Add Comment
Please, Sign In to add comment