Jump to content




Coroutines & tArgs?


  • You cannot reply to this topic
3 replies to this topic

#1 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited 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?

#2 Exerro

  • Members
  • 801 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.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited 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
}


#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 26 November 2014 - 05:19 PM

Technically, no (capitalization & table formatting are off). But close enough, yeah. :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users