Jump to content




save table , fast load table...


  • You cannot reply to this topic
4 replies to this topic

#1 etopsirhc

  • Members
  • 122 posts

Posted 13 September 2012 - 11:16 PM

currently i have a program that will read a builders mod text file to a 3d table but any time i log out i have to re-read that entire file into the table. and being the size it is ... it will probably take a day rl time

so that said , is there an easy way to write a table to file so all i have to do to load it back up is
file = io.open("file","r")
table = file:read("*all")
file:close()

and for those wondering , its a 6.6MB text file containing 120 layers , each layer is a set of 257 lines , each 113 used charicters long ( space delimited )

so yeah , huge file faster read time would be much appricated

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 13 September 2012 - 11:21 PM

6.6MB? What are you storing there?
You can read the whole file using file.readAll(), but it will return it as a string, not a table.

#3 etopsirhc

  • Members
  • 122 posts

Posted 13 September 2012 - 11:25 PM

yeah , i'm actualy using line by line cause some lines have only semi useful info on them

https://dl.dropbox.c...442169/ragnarok
^
__ thats what's stored

#4 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 13 September 2012 - 11:37 PM

Well, if all the layers have the same size, you can store it in the first line/s and then read that many lines:
local layers = tonumber(file.readLine()) -- first line contains the number of layers
local size = tonumber(file.readLine()) -- second line contains number of lines per layer
local t = {}
for i = 1, layers do
  local layer = {}
  for j = 1, size do
    local sLine = file.readLine()
    local line = {}
    for n in string.gmatch(sLine, "%d+") do
	  table.insert(line, tonumber(n))
    end
    table.insert(layer, line)
  end
  table.insert(t, layer)
end
That should make it a little faster.

#5 etopsirhc

  • Members
  • 122 posts

Posted 13 September 2012 - 11:40 PM

ok , i'll have to see how that works out , be back after i implement it





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users