Difference between revisions of "Coroutine.yield"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[coroutine]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/coroutine|coroutine]]<br/>
+
 
=== <translate>Description</translate> ===
+
=== Description ===
<translate>In order for multiple coroutines to share execution they must stop executing (after performing a sensible amount of processing) and pass control to another thread. This act of submission is called yielding. Coroutines explicitly call a Lua function coroutine.yield(), which is similar to using return in functions. What differentiates yielding from function returns is that at a later point we can reenter the thread and carry on where we left off. When you exit a function scope using return the scope is destroyed and we cannot reenter it, e.g.,</translate>
+
Suspends execution of the coroutine.
<source lang="lua">
+
<syntaxhighlight lang="lua">
  coroutine.yield(val1,...)
+
(any) = coroutine.yield(...)
</source>
+
</syntaxhighlight>
=== <translate>Parameters</translate> ===
+
 
'''val1''': (any) <translate>value to return from coroutine.resume call</translate> '''optional'''<br/>
+
'''In order for multiple coroutines to share execution they must stop executing (after performing a sensible amount of processing) and pass control to another thread. This act of submission is called yielding. Coroutines explicitly call a Lua function coroutine.yield(), which is similar to using return in functions. What differentiates yielding from function returns is that at a later point we can reenter the thread and carry on where we left off. When you exit a function scope using return the scope is destroyed and we cannot reenter it'''
'''...''': (multiple) <translate>other optional values that will be returned from coroutine.resume call</translate> '''optional'''<br/>
+
 
 +
  '''Any arguments to yield are passed as extra results to resume. Yielding a coroutine inside metamethods or C functions is prohibited, with the exception of pcall and xpcall'''
 +
 
 +
=== Parameters ===
 +
'''...''': (any) values to return from coroutine.resume call '''optional'''<br/>
 +
 
 +
=== Return values ===
 +
'''Returns''' (any) values to return if any<br/>
 +
 
 +
{{Coroutine}}

Latest revision as of 14:27, 13 July 2023

Available since: Gideros 2011.6
Class: coroutine

Description

Suspends execution of the coroutine.

(any) = coroutine.yield(...)
In order for multiple coroutines to share execution they must stop executing (after performing a sensible amount of processing) and pass control to another thread. This act of submission is called yielding. Coroutines explicitly call a Lua function coroutine.yield(), which is similar to using return in functions. What differentiates yielding from function returns is that at a later point we can reenter the thread and carry on where we left off. When you exit a function scope using return the scope is destroyed and we cannot reenter it
Any arguments to yield are passed as extra results to resume. Yielding a coroutine inside metamethods or C functions is prohibited, with the exception of pcall and xpcall

Parameters

...: (any) values to return from coroutine.resume call optional

Return values

Returns (any) values to return if any