Save table to file

This commit is contained in:
Particle_G
2020-11-26 14:59:10 +08:00
committed by MrZ626
parent 1eba821522
commit 9e6e170e49
3 changed files with 36 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ local fs=love.filesystem
local files={
data= fs.newFile("data.dat"),
setting=fs.newFile("settings.dat"),
network=fs.newFile("network.dat"),
VK= fs.newFile("virtualkey.dat"),
keyMap= fs.newFile("key.dat"),
unlock= fs.newFile("unlock.dat"),
@@ -109,6 +110,28 @@ function FILE.saveSetting()
end
end
function FILE.loadNetwork()
local F=files.setting
if F:open("r")then
local s=F:read()
if s:sub(1,6)~="return"then
s="return{"..s:gsub("\n",",").."}"
end
s=loadstring(s)
F:close()
if s then
setfenv(s,{})
addToTable(s(),NETWORK)
end
end
end
function FILE.saveNetwork()
local F=files.setting
F:open("w")
F:write(dumpTable(NETWORK))
F:flush()F:close()
end
function FILE.loadKeyMap()
local F=files.keyMap
if F:open("r")then