fixed a fucking bug that made me angry for 2 days

This commit is contained in:
Ale32bit 2016-11-04 19:37:41 +01:00 committed by GitHub
parent 811a4779ff
commit 3d331de743

View file

@ -745,16 +745,16 @@ end
end end
end end
local config = textutils.unserialize(script.config) local _config = textutils.unserialize(script.config)
if not config.id then if not _config.id then
error("SPK: id not found",2) error("SPK: id not found",2)
end end
if not config.main then if not _config.main then
error("SPK: main not found",2) error("SPK: main not found",2)
end end
writeDown(textutils.unserialize(script.files),"/.sPhone/apps/spk/"..config.id) writeDown(textutils.unserialize(script.files),"/.sPhone/apps/spk/".._config.id)
local f = fs.open("/.sPhone/apps/spk/"..config.id.."/.spk","w") local f = fs.open("/.sPhone/apps/spk/".._config.id.."/.spk","w")
f.write(textutils.serialize(config)) f.write(textutils.serialize(_config))
f.close() f.close()
local f = fs.open("/.sPhone/config/spklist","r") local f = fs.open("/.sPhone/config/spklist","r")
local lists = f.readAll() local lists = f.readAll()
@ -764,11 +764,11 @@ end
error("Cannot open config",2) error("Cannot open config",2)
end end
if not config.name then if not _config.name then
config.name = config.id _config.name = _config.id
end end
lists[config.id] = config.name lists[_config.id] = _config.name
local f = fs.open("/.sPhone/config/spklist","w") local f = fs.open("/.sPhone/config/spklist","w")
f.write(textutils.serialize(lists)) f.write(textutils.serialize(lists))
@ -805,31 +805,31 @@ end
local f = fs.open("/.sPhone/apps/spk/"..spk.."/.spk","r") local f = fs.open("/.sPhone/apps/spk/"..spk.."/.spk","r")
local script = f.readAll() local script = f.readAll()
f.close() f.close()
config = textutils.unserialize(script) _config = textutils.unserialize(script)
if not script then if not script then
error("config corrupted",2) error("config corrupted",2)
end end
local ok, err = pcall(function() local ok, err = pcall(function()
setfenv(loadfile(fs.combine("/.sPhone/apps/spk",config.id.."/"..config.main)), setmetatable({ setfenv(loadfile(fs.combine("/.sPhone/apps/spk",_config.id.."/".._config.main)), setmetatable({
spk = { spk = {
getName = function() getName = function()
return (config.name or nil) return (_config.name or nil)
end, end,
getID = function() getID = function()
return (config.id or nil) return (_config.id or nil)
end, end,
getPath = function() getPath = function()
return "/.sPhone/apps/spk/"..config.id return "/.sPhone/apps/spk/".._config.id
end, end,
getAuthor = function() getAuthor = function()
return (config.author or nil) return (_config.author or nil)
end, end,
getVersion = function() getVersion = function()
return (config.version or nil) return (_config.version or nil)
end, end,
}, },
string = string, string = string,