Class IoLib

All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable
Direct Known Subclasses:
JseIoLib

public abstract class IoLib extends TwoArgFunction
Abstract base class extending LibFunction which implements the core of the lua standard io library.

It contains the implementation of the io library support that is common to the JSE and JME platforms. In practice on of the concrete IOLib subclasses is chosen: org.luaj.vm2.lib.jse.JseIoLib for the JSE platform, and

The JSE implementation conforms almost completely to the C-based lua library, while the JME implementation follows closely except in the area of random-access files, which are difficult to support properly on JME.

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

 
 Globals globals = JsePlatform.standardGlobals();
 globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
  
In this example the platform-specific org.luaj.vm2.lib.jse.JseIoLib library will be loaded, which will include the base functionality provided by this class, whereas the org.luaj.vm2.lib.jse.JsePlatform would load the org.luaj.vm2.lib.jse.JseIoLib.

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 OsLib());
 globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
  

This has been implemented to match as closely as possible the behavior in the corresponding library in C.

See Also: