Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tab2file = function(tab,path) -- using: tab2file(t, "file") where t is a table with values, "file" is file name
- local f = fs.open(path,"w")
- for k,v in pairs(tab) do
- f.writeLine(k.." = "..v)
- end
- f.close()
- end
- file2tab = function(path) -- using: t = file2tab("file") where t is a table to store all values, "file" is file name
- tab = {}
- local f = fs.open(path,"r")
- local s, k, v
- while true do
- s = f.readLine()
- if s == nil then break end
- _,_,k,v = string.find(s,"^%s*([_%w]+)%s*=%s*([_%w]+)")
- -- ^ is a "start of the line" character
- -- (if there are any other characters like # in target string, it won't work. Use it for comments.
- -- %s* is any amount (or zero) of space characters
- -- [_%w]+ is any amount or alphanumeric characters and/or "_"
- -- () represent a capture of this
- if k ~= nil then -- if it isn't a blank string, or comment, or something else
- tab[k] = v
- end
- end
- f.close()
- return tab
- end
Advertisement
Add Comment
Please, Sign In to add comment