3057 posts
Location
United States of America
Posted 26 November 2014 - 04:26 PM
I'm currently working on multitasking.
How would you pass arguments to a coroutine? You can't call the function with arguments, and resuming it will wait for coroutine.yeild, not the arguments. Should I simply add an 'in between' function that handles this?
797 posts
Posted 26 November 2014 - 05:10 PM
You pass arguments to a coroutine through coroutine.resume. If it is the first time resuming the coroutine, the args you resume it with are passed in as if you were calling the original function with those args. If you have already resumed it, then it must have just called coroutine.yield() for you to be running any code, and resuming it will cause whatever you resume it with to be returned by the coroutine.yield() called from the coroutine.
3057 posts
Location
United States of America
Posted 26 November 2014 - 05:17 PM
So, just to be clear…
local co = coroutine.create( function( ... ) print( textutils.serialize( { ... } ) ) end )
coroutine.resume( co, "hello" )
Will print
{
Hello
}
8543 posts
Posted 26 November 2014 - 05:19 PM
Technically, no (capitalization & table formatting are off). But close enough, yeah. :P/>