From e9b277f578fcd2149a5c10a0bca2b90663771c2a Mon Sep 17 00:00:00 2001 From: Ale32bit Date: Sun, 6 Nov 2016 13:33:25 +0100 Subject: [PATCH] added new SPK function --- src/sPhone.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/sPhone.lua b/src/sPhone.lua index 6f9bcf6..caae2cf 100644 --- a/src/sPhone.lua +++ b/src/sPhone.lua @@ -1,6 +1,6 @@ local function kernel() _G.sPhone = { - version = "Alpha 3.9.1", + version = "Alpha 3.10", user = "Guest", devMode = false, mainTerm = term.current(), @@ -764,7 +764,7 @@ end if not _config.main then error("SPK: main not found",2) 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") f.write(textutils.serialize(_config)) f.close() @@ -785,7 +785,7 @@ end local f = fs.open("/.sPhone/config/spklist","w") f.write(textutils.serialize(lists)) f.close() - return true + return true, _config.id else return false, "not a spk file" end @@ -812,7 +812,9 @@ end return false, "not installed" 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 script = f.readAll() @@ -822,7 +824,7 @@ end error("config corrupted",2) end 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 = { getName = function() return (_config.name or nil) @@ -836,6 +838,10 @@ end return "/.sPhone/apps/spk/".._config.id end, + getDataPath = function() + return "/.sPhone/apps/spk/".._config.id.."/data" + end, + getAuthor = function() return (_config.author or nil) end, @@ -843,6 +849,10 @@ end getVersion = function() return (_config.version or nil) end, + + open = function(file, mode) + return fs.open("/.sPhone/apps/spk/".._config.id.."/data/"..file,mode) + end, }, string = string, sPhone = sPhone,