Cakejoke

[CC] COS-CJE property API

Dec 22nd, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. function getAll(path)
  2.     local properties = {}
  3.     local propertiesFile = fs.open(path, "r")
  4.     local line
  5.     local posOfSeperator
  6.     while true do
  7.         line = propertiesFile.readLine()
  8.         if line == nil then
  9.             break
  10.         end
  11.         posOfSeperator = line:find("=")
  12.         if posOfSeperator ~= nil then
  13.             properties[line:sub(1, posOfSeperator - 1)] =
  14.                     line:sub(posOfSeperator + 1, line:len())
  15.         end
  16.     end
  17.     propertiesFile.close()
  18.     return properties
  19. end
  20.  
  21. function get(path, property)
  22.     local propertiesFile = fs.open(path, "r")
  23.     local line
  24.     local posOfSeperator
  25.     while true do
  26.         line = propertiesFile.readLine()
  27.         if line == nil then
  28.             break
  29.         end
  30.         posOfSeperator = line:find("=")
  31.         if posOfSeperator ~= nil then
  32.             if line:sub(1, posOfSeperator - 1) == property then
  33.                 propertiesFile.close()
  34.                 return line:sub(posOfSeperator + 1, line:len())
  35.             end
  36.         end
  37.     end
  38.     propertiesFile.close()
  39.     return nil
  40. end
Advertisement
Add Comment
Please, Sign In to add comment