added new SPK function

This commit is contained in:
Ale32bit 2016-11-06 13:33:25 +01:00 committed by GitHub
parent 856ebe6ab8
commit e9b277f578

View file

@ -1,6 +1,6 @@
local function kernel() local function kernel()
_G.sPhone = { _G.sPhone = {
version = "Alpha 3.9.1", version = "Alpha 3.10",
user = "Guest", user = "Guest",
devMode = false, devMode = false,
mainTerm = term.current(), mainTerm = term.current(),
@ -764,7 +764,7 @@ 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.."/files")
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()
@ -785,7 +785,7 @@ end
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))
f.close() f.close()
return true return true, _config.id
else else
return false, "not a spk file" return false, "not a spk file"
end end
@ -812,7 +812,9 @@ end
return false, "not installed" return false, "not installed"
end end
if not fs.exists("/.sPhone/apps/spk/"..spk.."/.spk") then
error("Invalid SPK, .spk not found",2)
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()
@ -822,7 +824,7 @@ end
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.."/files/".._config.main)), setmetatable({
spk = { spk = {
getName = function() getName = function()
return (_config.name or nil) return (_config.name or nil)
@ -836,6 +838,10 @@ end
return "/.sPhone/apps/spk/".._config.id return "/.sPhone/apps/spk/".._config.id
end, end,
getDataPath = function()
return "/.sPhone/apps/spk/".._config.id.."/data"
end,
getAuthor = function() getAuthor = function()
return (_config.author or nil) return (_config.author or nil)
end, end,
@ -843,6 +849,10 @@ end
getVersion = function() getVersion = function()
return (_config.version or nil) return (_config.version or nil)
end, end,
open = function(file, mode)
return fs.open("/.sPhone/apps/spk/".._config.id.."/data/"..file,mode)
end,
}, },
string = string, string = string,
sPhone = sPhone, sPhone = sPhone,