Difference between revisions of "Coroutine.wrap"
From ComputerCraft Wiki
(Missed dat stray function reference. ;_;) |
(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.wrap | |name=coroutine.wrap | ||
− | |args= | + | |args={{Type|function}} f |
|api=Coroutine | |api=Coroutine | ||
− | |returns= | + | |returns={{Type|function}} coroutine wrapper |
|addon=ComputerCraft | |addon=ComputerCraft | ||
− | |desc=Creates and | + | |desc=Creates a new coroutine and wraps it in a function. The coroutine itself is created similarly to [[coroutine.create]], but is not made visible to the caller. Calling the function returned by [[coroutine.wrap]] is equivalent to calling [[coroutine.resume]] on the underlying coroutine, with any parameters passed to the wrapper function being passed in turn to [[coroutine.resume]]. Should [[coroutine.resume]] return success (that is, its first return value be <code>true</code>), the wrapper function will return the rest of the return values (that is, the parameters the wrapped coroutine’s body passed to [[coroutine.yield]] or returned at the end of the function); should [[coroutine.resume]] return failure (that is, its first return value be <code>false</code>), the wrapper function will reraise the error and propagate it to the caller. |
− | + | |examples=Please see [[Coroutine (API)]] for a worked example of using all the coroutine functions. | |
− | + | ||
− | + | ||
− | + | ||
− | | | + | |
− | + | ||
}} | }} | ||
[[Category:Lua_Core_Functions]] | [[Category:Lua_Core_Functions]] |
Latest revision as of 18:24, 22 April 2013
Function coroutine.wrap | |
Creates a new coroutine and wraps it in a function. The coroutine itself is created similarly to coroutine.create, but is not made visible to the caller. Calling the function returned by coroutine.wrap is equivalent to calling coroutine.resume on the underlying coroutine, with any parameters passed to the wrapper function being passed in turn to coroutine.resume. Should coroutine.resume return success (that is, its first return value be true ), the wrapper function will return the rest of the return values (that is, the parameters the wrapped coroutine’s body passed to coroutine.yield or returned at the end of the function); should coroutine.resume return failure (that is, its first return value be false ), the wrapper function will reraise the error and propagate it to the caller. | |
Syntax | coroutine.wrap(function f) |
Returns | function coroutine wrapper |
Part of | ComputerCraft |
API | Coroutine |
Examples
Please see Coroutine (API) for a worked example of using all the coroutine functions.