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

What does coroutine.resume() return? And what does it mean?

Started by Jummit, 20 September 2018 - 09:38 AM
Jummit #1
Posted 20 September 2018 - 11:38 AM
If you call os.pullEvent() in a coroutine, what does coroutine.resume() return?
Edited on 20 September 2018 - 09:40 AM
SquidDev #2
Posted 20 September 2018 - 11:58 AM
From Lua's documentation on coroutine.resume:
If the coroutine runs without any errors, resume returns true plus any values passed to yield (when the coroutine yields) or any values returned by the body function (when the coroutine terminates). If there is any error, resume returns false plus the error message.
os.pullEvent just passes off it's arguments to coroutine.yield, so you'll either receive true plus the optional filter, or false and an error message.
Jummit #3
Posted 20 September 2018 - 12:07 PM
From Lua's documentation on coroutine.resume:
If the coroutine runs without any errors, resume returns true plus any values passed to yield (when the coroutine yields) or any values returned by the body function (when the coroutine terminates). If there is any error, resume returns false plus the error message.
os.pullEvent just passes off it's arguments to coroutine.yield, so you'll either receive true plus the optional filter, or false and an error message.
Ah, thats where that true comes from! Thanks!
Jummit #4
Posted 20 September 2018 - 12:13 PM
Does the os.pullEvent function just do

function os.pullEvent(filter)
   local event, var1, var2, var3 = os.pullEventRaw(filter)
   if event=="terminate" then
	  error("terminated")
   end
   return event, var1, var2, var3
end
?
Edited on 20 September 2018 - 10:13 AM
SquidDev #5
Posted 20 September 2018 - 12:33 PM
Does the os.pullEvent function just do -snip-?
Yes.
Jummit #6
Posted 20 September 2018 - 12:53 PM
Does the os.pullEvent function just do -snip-?
Yes.
I didn't expect that to be so close to the actual code :D/>, thanks for the file, there are some other interesting functions in there!
Lupus590 #7
Posted 20 September 2018 - 04:42 PM
You may find this useful too: http://www.computercraft.info/forums2/index.php?/topic/26369-computercraft-event-system-flowchart/
Jummit #8
Posted 21 September 2018 - 09:12 PM
You may find this useful too: http://www.computerc...stem-flowchart/
Yeah, I am aware of this. Its pretty damn useful, I just find it hard to wrap my head around what is done by the program, the OS or by the mod.