Files
Basalt/Basalt/libraries/process.lua
Robert Jelic f76ead42ce Mouse_move + shrink fix
- Added mouse_move support (still not fully done but should work)
- fixed :shrink bug ignoring object size
2022-09-13 21:55:22 +02:00

63 lines
1.4 KiB
Lua

local processes = {}
local process = {}
local processId = 0
function process:new(path, window, ...)
local args = {...}
local newP = setmetatable({ path = path }, { __index = self })
newP.window = window
newP.processId = processId
if(type(path)=="string")then
newP.coroutine = coroutine.create(function()
shell.execute(path, table.unpack(args))
end)
elseif(type(path)=="function")then
newP.coroutine = coroutine.create(function()
path(table.unpack(args))
end)
else
return
end
processes[processId] = newP
processId = processId + 1
return newP
end
function process:resume(event, ...)
term.redirect(self.window)
if(self.filter~=nil)then
if(event~=self.filter)then return end
self.filter=nil
end
local ok, result = coroutine.resume(self.coroutine, event, ...)
if ok then
self.filter = result
else
error(result)
end
end
function process:isDead()
if (self.coroutine ~= nil) then
if (coroutine.status(self.coroutine) == "dead") then
table.remove(processes, self.processId)
return true
end
else
return true
end
return false
end
function process:getStatus()
if (self.coroutine ~= nil) then
return coroutine.status(self.coroutine)
end
return nil
end
function process:start()
coroutine.resume(self.coroutine)
end
return process