Class JseIoLib

All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable

public class JseIoLib extends IoLib
Subclass of IoLib and therefore LibFunction which implements the lua standard io library for the JSE platform.

It uses RandomAccessFile to implement seek on files.

Typically, this library is included as part of a call to org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()

 
 Globals globals = JsePlatform.standardGlobals();
 globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
  

For special cases where the smallest possible footprint is desired, a minimal set of libraries could be loaded directly via LuaValue.load(LuaValue) using code such as:

 
 Globals globals = new Globals();
 globals.load(new JseBaseLib());
 globals.load(new PackageLib());
 globals.load(new JseIoLib());
 globals.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
  

However, other libraries such as MathLib are not loaded in this case.

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

See Also:
  • Constructor Details

    • JseIoLib

      public JseIoLib()
  • Method Details

    • wrapStdin

      protected IoLib.File wrapStdin() throws IOException
      Description copied from class: IoLib
      Wrap the standard input.
      Specified by:
      wrapStdin in class IoLib
      Returns:
      File
      Throws:
      IOException
    • wrapStdout

      protected IoLib.File wrapStdout() throws IOException
      Description copied from class: IoLib
      Wrap the standard output.
      Specified by:
      wrapStdout in class IoLib
      Returns:
      File
      Throws:
      IOException
    • wrapStderr

      protected IoLib.File wrapStderr() throws IOException
      Description copied from class: IoLib
      Wrap the standard error output.
      Specified by:
      wrapStderr in class IoLib
      Returns:
      File
      Throws:
      IOException
    • openFile

      protected IoLib.File openFile(String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode) throws IOException
      Description copied from class: IoLib
      Open a file in a particular mode.
      Specified by:
      openFile in class IoLib
      readMode - true if opening in read mode
      appendMode - true if opening in append mode
      updateMode - true if opening in update mode
      binaryMode - true if opening in binary mode
      Returns:
      File object if successful
      Throws:
      IOException - if could not be opened
    • openProgram

      protected IoLib.File openProgram(String prog, String mode) throws IOException
      Description copied from class: IoLib
      Start a new process and return a file for input or output
      Specified by:
      openProgram in class IoLib
      Parameters:
      prog - the program to execute
      mode - "r" to read, "w" to write
      Returns:
      File to read to or write from
      Throws:
      IOException - if an i/o exception occurs
    • tmpFile

      protected IoLib.File tmpFile() throws IOException
      Description copied from class: IoLib
      Open a temporary file.
      Specified by:
      tmpFile in class IoLib
      Returns:
      File object if successful
      Throws:
      IOException - if could not be opened