Advertisement
karelvysinka

Citac radku 1

Jul 21st, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. function lines_from(file)
  2.   if not file_exists(file) then return {} end
  3.   lines = {}
  4.   for line in io.lines(file) do
  5.     lines[#lines + 1] = line
  6.   end
  7.   return lines
  8. end
  9.  
  10. -- see if the file exists
  11. function file_exists(file)
  12.   local f = io.open(file, "rb")
  13.   if f then f:close() end
  14.   return f ~= nil
  15. end
  16.  
  17.  
  18. cyklu=1
  19. while true do
  20.     local data
  21.     data = fs.open("aaa","r")
  22.  
  23.     --zjistime pocet radku ze souboru
  24.     local file = 'aaa'
  25.     local lines = lines_from(file)
  26.     print(lines)
  27.    
  28.  
  29.     citac_radku = data.readLine() -- nacti radek
  30.     if citac_radku == nil then break end
  31.  
  32.     result = {};
  33.     for match in string.gmatch(citac_radku, "[^%s]+") do
  34.         table.insert(result, match);
  35.     end
  36.     print(result[1]) -- souradnice X
  37.     print(result[2]) -- souradnice Y
  38.     print(result[3]) -- souradnice Z
  39.     print(result[4]) -- item
  40.  
  41.     x = (result[1])
  42.     y = (result[2])
  43.     z = (result[3])
  44.     item = (result[4])
  45.  
  46. cyklu = cyklu + 1
  47. end
  48.  
  49.  
  50.  
  51. print("Konec")
  52. -----------------------------------------------
  53. local open = io.open
  54.  
  55. local function read_file(path)
  56.     local file = open(path, "r") -- r read mode and b binary mode
  57.     if not file then return nil end
  58.     local content = file:read "*a" -- *a or *all reads the whole file
  59.     file:close()
  60.     return content
  61.  
  62. end
  63.  
  64. local fileContent = read_file("aaa");
  65. print (fileContent);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement