Class CoroutineLib

All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable

public class CoroutineLib extends TwoArgFunction implements com.esotericsoftware.kryo.KryoSerializable
Subclass of LibFunction which implements the lua standard coroutine library.

The coroutine library in luaj has the same behavior as the coroutine library in C, but is implemented using Java Threads to maintain the call state between invocations. Therefore it can be yielded from anywhere, similar to the "Coco" yield-from-anywhere patch available for C-based lua. However, coroutines that are yielded but never resumed to complete their execution may not be collected by the garbage collector.

Typically, this library is included as part of a call to either

 
 Globals globals = JsePlatform.standardGlobals();
 System.out.println( globals.get("coroutine").get("running").call() );
  

To instantiate and use it directly, link it into your globals table via LuaValue.load(LuaValue) using code such as:

 
 Globals globals = new Globals();
 globals.load(new JseBaseLib());
 globals.load(new PackageLib());
 globals.load(new CoroutineLib());
 System.out.println( globals.get("coroutine").get("running").call() );
  

See Also: