Difference between revisions of "Coroutine (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(Updated to API overview v2)
Line 9: Line 9:
 
Please list any non-working functions here.
 
Please list any non-working functions here.
  
==Methods==
+
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
{| border="1" cellpadding="2" cellspacing="0"
+
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
!style="background:#EEE" width="200px"|Method name
+
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;
!style="background:#EEE" width="*"|Description
+
Coroutine (API)
|-
+
</td></tr>
|[[coroutine.create]](function)
+
|Creates and Returns a new coroutine.
+
|-
+
|[[coroutine.resume]](coroutine, [var1], [var2], ...)
+
|Starts or Resumes an already-made coroutine.
+
|-
+
|[[coroutine.running]]()
+
|Returns the coroutine running (nil if it's the main coroutine).
+
|-
+
|[[coroutine.status]](coroutine)
+
|Returns the status of the given coroutine.
+
|-
+
|[[coroutine.wrap]](function)
+
|Creates and Returns a new coroutine in the form of a function.
+
|-
+
|[[coroutine.yield]]([var1], [var2], ...)
+
|Pauses the coroutine. Variables passed will be extra variables next time the coroutine starts.
+
|}
+
  
 +
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
 +
 +
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[coroutine.create]](function)</td>
 +
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Creates and Returns a new coroutine.</td></tr>
 +
 +
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[coroutine.resume]](coroutine, [var1], [var2], ...)</td>
 +
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Starts or Resumes an already-made coroutine.</td></tr>
 +
 +
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[coroutine.running]]()</td>
 +
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the coroutine running (nil if it's the main coroutine).</td></tr>
 +
 +
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[coroutine.status]](coroutine)</td>
 +
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the status of the given coroutine.</td></tr>
 +
 +
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[coroutine.wrap]](function)</td>
 +
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Creates and Returns a new coroutine in the form of a function.</td></tr>
 +
 +
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[coroutine.yield]]([var1], [var2], ...)</td>
 +
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Pauses the coroutine. Variables passed will be extra variables next time the coroutine starts.</td></tr>
 +
</table>
  
 
==List of non-working functions==
 
==List of non-working functions==

Revision as of 21:59, 30 November 2012

Bug

From ComputerCraft 1.3 this API suffers from the problem of potentially spawning Java threads that live forever therefore, use of coroutines should be minimized. This is fixed in ComputerCraft 1.32+, though.

This is for the Coroutine API. For the Coroutine Object, visit Coroutine.

Coroutine is a default Lua 5.1 API defined here. Please list any non-working functions here.

Grid disk.png   Coroutine (API)

Method NameDescription
coroutine.create(function) Creates and Returns a new coroutine.
coroutine.resume(coroutine, [var1], [var2], ...) Starts or Resumes an already-made coroutine.
coroutine.running() Returns the coroutine running (nil if it's the main coroutine).
coroutine.status(coroutine) Returns the status of the given coroutine.
coroutine.wrap(function) Creates and Returns a new coroutine in the form of a function.
coroutine.yield([var1], [var2], ...) Pauses the coroutine. Variables passed will be extra variables next time the coroutine starts.

List of non-working functions

List any non-working functions here.