Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --require( "string" )
- local file = arg[1] or 'd.dat'
- print( file )
- -- http://stackoverflow.com/questions/11201262/how-to-read-data-from-a-file-in-lua
- function lines_from(file)
- --if not file_exists(file) then return {} end
- lines = {}
- for line in io.lines(file) do
- lines[#lines + 1] = line
- end
- return lines
- end
- -- https://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/
- function print_r ( t )
- local print_r_cache={}
- local function sub_print_r(t,indent)
- if (print_r_cache[tostring(t)]) then
- print(indent.."*"..tostring(t))
- else
- print_r_cache[tostring(t)]=true
- if (type(t)=="table") then
- for pos,val in pairs(t) do
- if (type(val)=="table") then
- print(indent.."["..pos.."] => "..tostring(t).." {")
- sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
- print(indent..string.rep(" ",string.len(pos)+6).."}")
- elseif (type(val)=="string") then
- print(indent.."["..pos..'] => "'..val..'"')
- else
- print(indent.."["..pos.."] => "..tostring(val))
- end
- end
- else
- print(indent..tostring(t))
- end
- end
- end
- if (type(t)=="table") then
- print(tostring(t).." {")
- sub_print_r(t," ")
- print("}")
- else
- sub_print_r(t," ")
- end
- print()
- end
- local lines = lines_from(file)
- --print ( lines , "Összesen ",#lines," sor." )
- local header = ''
- local dat_object = ''
- local dat_object_index = {}
- local id = ''
- --local one = {}
- --for i,line in pairs(lines) do
- for i,line in ipairs(lines) do
- --string.gsub(line,"%*","")
- id = string.sub(line,1,string.find(line,"%*")-1)
- if i == 1 then
- dat_object_index['header'] = line
- end
- --elseif string.starts(line,"T_") then
- if string.find(id,"T_") == 1 then
- dat_object = id
- else -- string.match(id,"%d") then
- --elseif string.find(id,"%d") then
- --local one = { id = i }
- --dat_object_index[dat_object] = one
- dat_object_index[dat_object] = { id = i }
- --dat_object_index[dat_object][id] = i
- --dat_object.insert(dat_object_index[dat_object],one]
- end
- --print ( i, dat_object, id)
- end
- --for i, o in pairs(dat_object_index) do
- --for j, oo in pairs(o) do
- --print ( i, j, oo)
- --end
- --end
- print_r(dat_object_index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement