Advertisement
montana_1

lstToTable

Nov 4th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1. function split(s)
  2.     if(s == nil or s == "") then
  3.         return nil
  4.     end
  5.     local t = {}
  6.     for w in string.gmatch(s, "%w+") do
  7.         table.insert(t,w)
  8.     end
  9.     return t
  10. end
  11.  
  12. function addList(name,mine,flag,drop,vein)
  13.     if(fs.exists("listed")) then
  14.         xlist = fs.open("listed","r")
  15.         local x = split(xlist.readLine())
  16.        
  17.         while(x[1] ~= nil) do
  18.             if(name == x[1]) then
  19.                 return false
  20.             end
  21.             s = xlist.readLine()
  22.             if(s ~= nil) then
  23.                 x = split(s)
  24.             else
  25.                 break
  26.             end
  27.         end
  28.        
  29.         xlist.close()
  30.         xlist = fs.open("listed","a")
  31.     else
  32.         xlist = fs.open("listed","w")
  33.     end
  34.     xlist.writeLine(name..","..mine..","..flag..","..drop..","..vein)
  35.     xlist.close()
  36.     return true
  37. end
  38.  
  39. function lstToTable()
  40.     if(fs.exists("listed")) then
  41.         ifile = fs.open("listed","r")
  42.         xlist = {}
  43.         x = split(ifile.readLine())
  44.         while(x ~= nil and x ~= "") do
  45.             table.insert(xlist, x)
  46.             x = split(ifile.readLine())
  47.         end
  48.     else
  49.         --      name,mine,flag,drop,vein
  50.         xlist = {
  51.             {'iron_ore','1','0','0','1'},
  52.             {'coal_ore','1','0','0','1'},
  53.             {'gold_ore','1','0','0','1'},
  54.             {'lapis_ore','1','0','0','1'},
  55.             {'redstone_ore','1','0','0','1'},
  56.             {'diamond_ore','1','0','0','1'},
  57.             {'quartz_ore','1','0','0','1'},
  58.             {'emerald_ore','1','0','0','1'}
  59.             }
  60.         for k,v in pairs(xlist) do
  61.             addList(v[1],v[2],v[3],v[4],v[5])
  62.         end
  63.     end
  64.     return xlist
  65. end
  66.  
  67.  
  68. lstToTable()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement