Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --by 1Ridav
- ---http://computercraft.ru
- --PWD set full path /mnt/1a2/
- --local PWD = "" --uncomment this if use dofile()
- local PWD = os.getenv("PWD") --comment this if use dofile()
- local pref = {}
- function pref.create(path)
- local table = {}
- table["_FullPreferencesPath"] = PWD..path
- return table
- end
- function pref.load(path)
- path = PWD..path
- local table = {}
- local key, value, delimeter
- local len = 0
- local f = io.open(path, "r")
- if not f then return nil end
- for line in f:lines() do
- len = len + 1
- delimeter = string.find(line, "=")
- key = string.sub(line, 1, delimeter-1)
- value = string.sub(line, delimeter+1, #line)
- table[key] = value
- end
- f:close()
- if len == 0 then return nil end
- table["_FullPreferencesPath"] = path
- return table
- end
- function pref.save(table)
- local f = io.open(table["_FullPreferencesPath"], "w")
- if not f then return false end
- for k, v in pairs(table) do
- f:write(k.."="..v.."\n")
- end
- f:close()
- return true
- end
- return pref
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement