Difference between revisions of "Coroutine.resume"

From ComputerCraft Wiki
Jump to: navigation, search
m (Moved to CAT:LuaCoreFunctions)
(Remove example that doesn’t show anything interesting on its own, improve description, and use type template)
 
Line 1: Line 1:
 
{{Function
 
{{Function
 
|name=coroutine.resume
 
|name=coroutine.resume
|args=[[coroutine]], var1, var2, ...
+
|args={{Type|coroutine}} coro, [var1], [var2],
 
|api=Coroutine
 
|api=Coroutine
 +
|returns={{Type|boolean}} <code>true</code> and the values returned from <var>coro</var>’s body (if it returned) or passed to [[coroutine.yield]] (if it yielded) on success, or <code>false</code> and a message if <var>coro</var> cannot be resumed (e.g. because it is not suspended) or if its body throws an error
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Runs a coroutine.
+
|desc=Starts or resumes an existing coroutine. The second and subsequent parameters are passed as parameters to <var>coro</var>’s body if this is the first resumption of <var>coro</var>, or appear as return values from [[coroutine.yield]] otherwise. The coroutine calling this function becomes the parent of <var>coro</var>.
|examples=
+
|examples=Please see [[Coroutine (API)]] for a worked example of using all the coroutine functions.
{{Example
+
|desc=Creates and Runs a coroutine.
+
|code=local co = coroutine.create(print)<br/>coroutine.resume(co, "Hello World!")
+
|output=Hello World!
+
}}
+
 
}}
 
}}
  
 
[[Category:Lua_Core_Functions]]
 
[[Category:Lua_Core_Functions]]

Latest revision as of 18:25, 22 April 2013

Grid Redstone.png  Function coroutine.resume
Starts or resumes an existing coroutine. The second and subsequent parameters are passed as parameters to coro’s body if this is the first resumption of coro, or appear as return values from coroutine.yield otherwise. The coroutine calling this function becomes the parent of coro.
Syntax coroutine.resume(coroutine coro, [var1], [var2], …)
Returns boolean true and the values returned from coro’s body (if it returned) or passed to coroutine.yield (if it yielded) on success, or false and a message if coro cannot be resumed (e.g. because it is not suspended) or if its body throws an error
Part of ComputerCraft
API Coroutine

Examples

Please see Coroutine (API) for a worked example of using all the coroutine functions.