Advertisement
kijato

lua_dat_teszt

Apr 30th, 2020
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. --require( "string" )
  2.  
  3. local file = arg[1] or 'd.dat'
  4. print( file )
  5.  
  6. -- http://stackoverflow.com/questions/11201262/how-to-read-data-from-a-file-in-lua
  7. function lines_from(file)
  8.   --if not file_exists(file) then return {} end
  9.   lines = {}
  10.   for line in io.lines(file) do
  11.     lines[#lines + 1] = line
  12.   end
  13.   return lines
  14. end
  15.  
  16. -- https://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/
  17. function print_r ( t )  
  18.     local print_r_cache={}
  19.     local function sub_print_r(t,indent)
  20.         if (print_r_cache[tostring(t)]) then
  21.             print(indent.."*"..tostring(t))
  22.         else
  23.             print_r_cache[tostring(t)]=true
  24.             if (type(t)=="table") then
  25.                 for pos,val in pairs(t) do
  26.                     if (type(val)=="table") then
  27.                         print(indent.."["..pos.."] => "..tostring(t).." {")
  28.                         sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
  29.                         print(indent..string.rep(" ",string.len(pos)+6).."}")
  30.                     elseif (type(val)=="string") then
  31.                         print(indent.."["..pos..'] => "'..val..'"')
  32.                     else
  33.                         print(indent.."["..pos.."] => "..tostring(val))
  34.                     end
  35.                 end
  36.             else
  37.                 print(indent..tostring(t))
  38.             end
  39.         end
  40.     end
  41.     if (type(t)=="table") then
  42.         print(tostring(t).." {")
  43.         sub_print_r(t,"  ")
  44.         print("}")
  45.     else
  46.         sub_print_r(t,"  ")
  47.     end
  48.     print()
  49. end
  50.  
  51. local lines = lines_from(file)
  52. --print ( lines , "Összesen ",#lines," sor." )
  53.  
  54. local header = ''
  55. local dat_object = ''
  56. local dat_object_index = {}
  57. local id = ''
  58. --local one = {}
  59.  
  60. --for i,line in pairs(lines) do
  61. for i,line in ipairs(lines) do
  62.   --string.gsub(line,"%*","")
  63.   id = string.sub(line,1,string.find(line,"%*")-1)
  64.   if i == 1 then
  65.     dat_object_index['header'] = line
  66.   end
  67.   --elseif string.starts(line,"T_") then
  68.   if string.find(id,"T_") == 1 then
  69.     dat_object = id
  70.   else -- string.match(id,"%d") then
  71.   --elseif string.find(id,"%d") then
  72.     --local one = { id = i }
  73.     --dat_object_index[dat_object] = one
  74.     dat_object_index[dat_object] = { id = i }
  75.     --dat_object_index[dat_object][id] = i
  76.     --dat_object.insert(dat_object_index[dat_object],one]
  77.   end
  78.   --print ( i, dat_object, id)
  79. end
  80.  
  81. --for i, o in pairs(dat_object_index) do
  82.   --for j, oo in pairs(o) do
  83.     --print ( i, j, oo)
  84.   --end
  85. --end
  86.  
  87. print_r(dat_object_index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement