The important thing is: Can I kill the program from a function defined in the parent program? I am running the child program with pall. If it's possible, then how?
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Killing a program from its parent program
Started by Geforce Fan, 16 May 2014 - 12:23 AMPosted 16 May 2014 - 02:23 AM
basicly I have a program that defines a bunch of functions then runs a program. The program will use those functions and in short the parent program is sort of still running.
The important thing is: Can I kill the program from a function defined in the parent program? I am running the child program with pall. If it's possible, then how?
The important thing is: Can I kill the program from a function defined in the parent program? I am running the child program with pall. If it's possible, then how?
Edited on 16 May 2014 - 12:24 AM
Posted 16 May 2014 - 02:25 AM
You probably want to create a custom coroutine manager to use instead of pcall.
Posted 16 May 2014 - 02:31 AM
I would die for one of those. But I'm pretty sure OneOS has it's own that only works in the operating system, so already my parent program is actually a child program to OneOS, and
OneOS does not like foreighn coroutine managers.
One "upper hand" I have is I could edit the program from the parent while it's still a string, however I don't really know where I should go about injecting my code, nor do I know how.
Here's an example program. SapphUtils.pullEvent is currently how I "inject" my program, but it still can't kill the child program. It works just like os.pullEvent. Well, it returns the same stuff anyway.
OneOS does not like foreighn coroutine managers.
One "upper hand" I have is I could edit the program from the parent while it's still a string, however I don't really know where I should go about injecting my code, nor do I know how.
Here's an example program. SapphUtils.pullEvent is currently how I "inject" my program, but it still can't kill the child program. It works just like os.pullEvent. Well, it returns the same stuff anyway.
print("test site")
print("to get back, go to, ''homepage'' without the quotes.")
while true do
sapphUtils.pullEvent()
end
Edited on 16 May 2014 - 12:37 AM
Posted 16 May 2014 - 03:23 AM
Killing the programs was one of the hardest parts of the program manager in OneOS, and it's still not perfect.
This is the code I used to kill the programs is this:
Take a look at this file for the full code.
But essentially, I yield the coroutine then set it to nil.
This is the code I used to kill the programs is this:
Kill = function(self, code)
term.setBackgroundColour(colours.black)
term.setTextColour(colours.white)
Current.CursorPos[1] = 1
Current.CursorPos[2] = 1
term.setCursorBlink(false)
print('Click anywhere to close this program.')
for i, program in ipairs(Current.Programs) do
if program == self then
Current.Programs[i].Running = false
if code ~= 0 then
coroutine.yield(Current.Programs[i].Process)
end
Current.Programs[i].Process = nil
end
end
end
Take a look at this file for the full code.
But essentially, I yield the coroutine then set it to nil.
Edited on 16 May 2014 - 01:23 AM
Posted 16 May 2014 - 03:40 AM
Thanks, but can I use coroutines with PearOS?
Posted 16 May 2014 - 05:05 AM
Thanks, but can I use coroutines with PearOS?
I don't think PearOS actually used corountines to be honest.
Posted 16 May 2014 - 09:25 PM
DERP sorry I mean OneOS
xD
…hello?
Seems to be a ghost town. Do people not want to answer my question?
xD
…hello?
Seems to be a ghost town. Do people not want to answer my question?