Posted 06 March 2015 - 01:11 PM
I am creating a small multitasking system, I am clearly creating the process with the new() function, however when I use the run() function it claims that the process doesn't exist. My code is as follows:
local tArgs = {...}
local process = { }
local proc = { }
local er = function(text)
error(shell.getRunningProgram()..": "..text, 0)
end
local new = function(name, func, dVa)
if type(name) == "string" then
if type(func) == "function" then
if type(dVa) == "table" then
process[name] = { }
process[name]["Pr"] = coroutine.create(func)
process[name]["Di"] = window.create(term.native(), dVa[1], dVa[2], dVa[3], dVa[4], dVa[5])
table.insert(proc, name)
end
else
er("Function expected")
end
else
er("String expected")
end
end
local run = function(name)
if type(name) == "string" then
if process[name] then
if coroutine.status(process[name]["Pr"]) == "suspended" then
coroutine.resume(process[name]["Pr"])
term = process[name]["Di"]
else
er("Process is "..coroutine.status(process[name]["Pr"]))
end
else
er("Process doesn't exist")
end
else
er("String expected")
end
end
local hello = function()
shell.run("hello")
end
new("hi", hello)
run("hi")