This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
logsys's profile picture

Coroutine returning to main program

Started by logsys, 29 April 2014 - 04:59 PM
logsys #1
Posted 29 April 2014 - 06:59 PM
To proper explain this, I will explain by topics:
  • I have a program that has a GUI that manages everything
  • When I adapted coroutine for program to run it like
    
    runProg = function(program)
      x, y = term.getSize()
      myWindow = window.create(term.current(),1,2,x,y-1, true)
      term.redirect(myWindow)
      shell.run(program)
      term.redirect(term.native())`
      myWindow.setVisibility(false) --not sure about this part
    end
    runProgC = coroutine.create(runProg(the program here))
    ok, err = coroutine.resume(runProgC)
  • then, it returns to the main program without running that program
  • Yes, it's for my OS
CometWolf #2
Posted 29 April 2014 - 07:05 PM
Im suprised it dosen't error lol. You can't pass an argument to the function used in coroutine.create. Use an anonymous function first.
logsys #3
Posted 29 April 2014 - 07:06 PM
Im suprised it dosen't error lol. You can't pass an argument to the function used in coroutine.create. Use an anonymous function first.
Can you explain that pls? I didn't understand the anonymous function
Edited on 29 April 2014 - 05:18 PM
Lyqyd #4
Posted 29 April 2014 - 07:20 PM
Separate from the issue CometWolf mentions, I think you have a basic misunderstanding of how coroutines work. Coroutines can be thought of as functions that can be paused (when they yield) and resumed (when the coroutine manager resumes them). They don't just fork off and run independently from the code that created them. You will want to look at the parallel API (or use it, if it will work) to see how to create a coroutine manager that will handle the coroutines you create the same way that they would be handled in CraftOS.