packages1/mfs/lib/mfs.lua

49 lines
725 B
Lua
Raw Normal View History

2020-12-28 09:57:39 +00:00
local mfs={}
2020-12-29 09:45:24 +00:00
local cd=""
function mfs.setcd(x)
if fs.exists(x) and fs.isDir(x) then
cd=x
return true
else
return false,"No such directory "..x
end
end
function mfs.getcd()
return cd
end
2020-12-28 09:57:39 +00:00
function mfs.read(x)
2020-12-29 09:45:24 +00:00
local f=fs.open(cd.."/"..x,"r")
2020-12-28 09:57:39 +00:00
if not f then return nil end
local i=f.readAll()
f.close()
return i
end
function mfs.write(x,v)
2020-12-29 09:45:24 +00:00
local f=fs.open(cd.."/"..x,"w")
2020-12-28 09:57:39 +00:00
f.write(v)
f.close()
end
function mfs.mmkdir(x)
2020-12-29 09:45:24 +00:00
if not fs.exists(cd.."/"..x) then
fs.makeDir(cd.."/"..x)
2020-12-28 09:57:39 +00:00
end
end
2020-12-28 13:16:19 +00:00
function mfs.save(x,t)
2020-12-29 09:45:24 +00:00
mfs.write(cd.."/"..x,textutils.serialize(t))
2020-12-28 13:16:19 +00:00
end
function mfs.load(x)
2020-12-29 09:45:24 +00:00
return textutils.unserialize(mfs.read(cd.."/"..x) or "{}")
end
function mfs.rm(x)
fs.delete(cd.."/"..x)
2020-12-28 13:16:19 +00:00
end
2020-12-28 10:03:22 +00:00
return mfs