<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Function_Dump%2FCoroutine_Manipulation</id>
	<title>Function Dump/Coroutine Manipulation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Function_Dump%2FCoroutine_Manipulation"/>
	<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Function_Dump/Coroutine_Manipulation&amp;action=history"/>
	<updated>2026-07-28T16:20:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.starfall.wtf/index.php?title=Function_Dump/Coroutine_Manipulation&amp;diff=442&amp;oldid=prev</id>
		<title>PRG: Created page with &quot;{{CatUp|Function Dump}}  ==[http://www.lua.org/pil/9.1.html Coroutine] Manipulation==  The operations related to coroutines comprise a sub-library of the basic library and come inside the table coroutine. See §2.11 for a general description of coroutines.   &#039;&#039;&#039;coroutine.create (f)&#039;&#039;&#039;   Creates a new coroutine, with body f. f must be a Lua function. Returns this new coroutine, an object with type &quot;thread&quot;.  {{Example| &lt;pre&gt; function f (a, b, c)   print (a, b, c) end  thr...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Function_Dump/Coroutine_Manipulation&amp;diff=442&amp;oldid=prev"/>
		<updated>2024-12-10T21:33:25Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{CatUp|Function Dump}}  ==[http://www.lua.org/pil/9.1.html Coroutine] Manipulation==  The operations related to coroutines comprise a sub-library of the basic library and come inside the table coroutine. See §2.11 for a general description of coroutines.   &amp;#039;&amp;#039;&amp;#039;coroutine.create (f)&amp;#039;&amp;#039;&amp;#039;   Creates a new coroutine, with body f. f must be a Lua function. Returns this new coroutine, an object with type &amp;quot;thread&amp;quot;.  {{Example| &amp;lt;pre&amp;gt; function f (a, b, c)   print (a, b, c) end  thr...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{CatUp|Function Dump}}&lt;br /&gt;
&lt;br /&gt;
==[http://www.lua.org/pil/9.1.html Coroutine] Manipulation==&lt;br /&gt;
&lt;br /&gt;
The operations related to coroutines comprise a sub-library of the basic library and come inside the table coroutine. See §2.11 for a general description of coroutines.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;coroutine.create (f)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Creates a new coroutine, with body f. f must be a Lua function. Returns this new coroutine, an object with type &amp;quot;thread&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{Example|&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function f (a, b, c)&lt;br /&gt;
  print (a, b, c)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
thread = coroutine.create (f) &lt;br /&gt;
assert (coroutine.resume (thread, 1, 2, 3))&lt;br /&gt;
&lt;br /&gt;
Will result in:&lt;br /&gt;
1 2 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;coroutine.resume (co [, val1, ···])&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Starts or continues the execution of coroutine co. The first time you resume a coroutine, it starts running its body. The values val1, ··· are passed as the arguments to the body function. If the coroutine has yielded, resume restarts it; the values val1, ··· are passed as the results from the yield.&lt;br /&gt;
&lt;br /&gt;
If the coroutine runs without any errors, resume returns true plus any values passed to yield (if the coroutine yields) or any values returned by the body function (if the coroutine terminates). If there is any error, resume returns false plus the error message.&lt;br /&gt;
&lt;br /&gt;
{{Example|&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function f (a, b, c)&lt;br /&gt;
  print (a, b, c)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
thread = coroutine.create (f) &lt;br /&gt;
assert (coroutine.resume (thread, 1, 2, 3))&lt;br /&gt;
&lt;br /&gt;
Will result in:&lt;br /&gt;
1 2 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;coroutine.running ()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Returns the running coroutine, or nil when called by the main thread.&lt;br /&gt;
&lt;br /&gt;
{{Example|&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
co = coroutine.create(function ()&lt;br /&gt;
	print(&amp;quot;Hi Mom!&amp;quot;)&lt;br /&gt;
end)&lt;br /&gt;
print(coroutine.running ())&lt;br /&gt;
&lt;br /&gt;
Will result in something similar to:&lt;br /&gt;
thread: 0A7A177C&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;coroutine.status (co)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Returns the status of coroutine co, as a string: &amp;quot;running&amp;quot;, if the coroutine is running (that is, it called status); &amp;quot;suspended&amp;quot;, if the coroutine is suspended in a call to yield, or if it has not started running yet; &amp;quot;normal&amp;quot; if the coroutine is active but not running (that is, it has resumed another coroutine); and &amp;quot;dead&amp;quot; if the coroutine has finished its body function, or if it has stopped with an error.&lt;br /&gt;
&lt;br /&gt;
{{Example|&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function f (a, b, c)&lt;br /&gt;
  print (a, b, c)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
thread = coroutine.create (f) &lt;br /&gt;
assert (coroutine.resume (thread, 1, 2, 3))&lt;br /&gt;
print(coroutine.status (thread))&lt;br /&gt;
&lt;br /&gt;
Will result in:&lt;br /&gt;
1 2 3&lt;br /&gt;
dead&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;coroutine.wrap (f)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Creates a new coroutine, with body f. f must be a Lua function. Returns a function that resumes the coroutine each time it is called. Any arguments passed to the function behave as the extra arguments to resume. Returns the same values returned by resume, except the first boolean. In case of error, propagates the error.&lt;br /&gt;
&lt;br /&gt;
    function perm (a)&lt;br /&gt;
      local n = table.getn(a)&lt;br /&gt;
      return coroutine.wrap(function () permgen(a, n) end)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
{{Example|&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function f (s)&lt;br /&gt;
  print (&amp;quot;Entering f with value&amp;quot;, s)&lt;br /&gt;
  v = coroutine.yield ()&lt;br /&gt;
  print (&amp;quot;After yield, v is&amp;quot;, v)&lt;br /&gt;
  return 22&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
resumer = coroutine.wrap (f) &lt;br /&gt;
resumer (88)&lt;br /&gt;
resumer (99)&lt;br /&gt;
&lt;br /&gt;
Will result in:&lt;br /&gt;
Entering f with value 88&lt;br /&gt;
After yield, v is 99&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;coroutine.yield (···)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Suspends the execution of the calling coroutine. The coroutine cannot be running a C function, a metamethod, or an iterator. Any arguments to yield are passed as extra results to resume. &lt;br /&gt;
&lt;br /&gt;
{{Example|&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
co = coroutine.create (function ()&lt;br /&gt;
	print(coroutine.yield())&lt;br /&gt;
end)&lt;br /&gt;
coroutine.resume(co)&lt;br /&gt;
coroutine.resume(co, 4, 5)&lt;br /&gt;
&lt;br /&gt;
Will result in:&lt;br /&gt;
4 5&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
See:&amp;lt;br&amp;gt;&lt;br /&gt;
[http://www.lua.org/pil/9.1.html Programming in Lua: Coroutine Basics]&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>PRG</name></author>
	</entry>
</feed>