You could do something like this, assuming all of the tables written to the file are written using writeLine instead of just write:
local h = fs.open(file,"r") --# getting the information from the file that contains the tables
local str = h.readAll()
h.close()
local function unserializeTables()
local returns = {} --# table to hold all the tables that will be returned
local tbl --# creating a local variable named tbl
while #str > 0 do
tbl,str = str:match("^(.-\n}\n)(.*)") --# will explain below
table.insert(returns,textutils.unserialize(tbl)) --# inserting the unserialized table into the returns table
end
return unpack(returns) --# returns the unserialized tables in order from the first found in the file
end
"^(.-\n}\n)(.*)"
– This is a lua pattern, which essentially looks for a closing curly brace "}" that is surrounded on both sides by a end line character \n. This only occurs at the last curly brace of a table, so you could unserialize nested tables using this.
A easier way to do this might be just to put all your tables into a single table before serializing it, say you wanted to save tables named tbl1, tbl2, and tbl3 to a file:
local saveTable = {tbl1,tbl2,tbl3}
local h = fs.open("saveFile","w")
h.write(textutils.serialize(saveTable))
h.close()
To read this file:
local h = fs.open("saveFile","r")
local tbl = textutils.unserialize(h.readAll())
h.close()
tbl1,tbl2,tbl3 = unpack(tbl)