Small program fix
This commit is contained in:
@@ -2,14 +2,32 @@ local processes = {}
|
|||||||
local process = {}
|
local process = {}
|
||||||
local processId = 0
|
local processId = 0
|
||||||
|
|
||||||
function process:new(path, window, ...)
|
local newPackage = dofile("rom/modules/main/cc/require.lua").make
|
||||||
|
|
||||||
|
function process:new(path, window, newEnv, ...)
|
||||||
local args = {...}
|
local args = {...}
|
||||||
local newP = setmetatable({ path = path }, { __index = self })
|
local newP = setmetatable({ path = path }, { __index = self })
|
||||||
newP.window = window
|
newP.window = window
|
||||||
|
window.current = term.current
|
||||||
|
window.redirect = term.redirect
|
||||||
newP.processId = processId
|
newP.processId = processId
|
||||||
if(type(path)=="string")then
|
if(type(path)=="string")then
|
||||||
newP.coroutine = coroutine.create(function()
|
newP.coroutine = coroutine.create(function()
|
||||||
shell.execute(path, table.unpack(args))
|
local pPath = shell.resolveProgram(path)
|
||||||
|
local env = setmetatable(newEnv, {__index=_ENV})
|
||||||
|
env.shell = shell
|
||||||
|
env.basaltProgram=true
|
||||||
|
env.arg = {[0]=path, table.unpack(args)}
|
||||||
|
env.require, env.package = newPackage(env, fs.getDir(pPath))
|
||||||
|
if(fs.exists(pPath))then
|
||||||
|
local file = fs.open(pPath, "r")
|
||||||
|
local content = file.readAll()
|
||||||
|
file.close()
|
||||||
|
local program = load(content, path, "bt", env)
|
||||||
|
if(program~=nil)then
|
||||||
|
return program()
|
||||||
|
end
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
elseif(type(path)=="function")then
|
elseif(type(path)=="function")then
|
||||||
newP.coroutine = coroutine.create(function()
|
newP.coroutine = coroutine.create(function()
|
||||||
@@ -24,17 +42,21 @@ function process:new(path, window, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function process:resume(event, ...)
|
function process:resume(event, ...)
|
||||||
|
local cur = term.current()
|
||||||
term.redirect(self.window)
|
term.redirect(self.window)
|
||||||
if(self.filter~=nil)then
|
if(self.filter~=nil)then
|
||||||
if(event~=self.filter)then return end
|
if(event~=self.filter)then return end
|
||||||
self.filter=nil
|
self.filter=nil
|
||||||
end
|
end
|
||||||
local ok, result = coroutine.resume(self.coroutine, event, ...)
|
local ok, result = coroutine.resume(self.coroutine, event, ...)
|
||||||
|
|
||||||
if ok then
|
if ok then
|
||||||
self.filter = result
|
self.filter = result
|
||||||
else
|
else
|
||||||
error(result)
|
printError(result)
|
||||||
end
|
end
|
||||||
|
term.redirect(cur)
|
||||||
|
return ok, result
|
||||||
end
|
end
|
||||||
|
|
||||||
function process:isDead()
|
function process:isDead()
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ return function(name, parent)
|
|||||||
pWindow.setTextColor(self.fgColor)
|
pWindow.setTextColor(self.fgColor)
|
||||||
pWindow.basalt_setVisible(true)
|
pWindow.basalt_setVisible(true)
|
||||||
|
|
||||||
resumeProcess(self)
|
--resumeProcess(self)
|
||||||
paused = false
|
paused = false
|
||||||
if(self.parent~=nil)then
|
if(self.parent~=nil)then
|
||||||
self.parent:addEvent("mouse_click", self)
|
self.parent:addEvent("mouse_click", self)
|
||||||
@@ -793,7 +793,7 @@ return function(name, parent)
|
|||||||
|
|
||||||
init = function(self)
|
init = function(self)
|
||||||
if(base.init(self))then
|
if(base.init(self))then
|
||||||
elf.bgColor = self.parent:getTheme("ProgramBG")
|
self.bgColor = self.parent:getTheme("ProgramBG")
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user