Class DumpState

java.lang.Object
com.prineside.luaj.compiler.DumpState

public class DumpState extends Object
Class to dump a Prototype into an output stream, as part of compiling.

Generally, this class is not used directly, but rather indirectly via a command line interface tool such as luac.

A lua binary file is created via dump(com.prineside.luaj.FPrototype, java.io.OutputStream, boolean):

 
 Globals globals = JsePlatform.standardGlobals();
 Prototype p = globals.compilePrototype(new StringReader("print('hello, world')"), "main.lua");
 ByteArrayOutputStream o = new ByteArrayOutputStream();
 DumpState.dump(p, o, false);
 byte[] lua_binary_file_bytes = o.toByteArray();
  
The LoadState may be used directly to undump these bytes:
 
 Prototypep = LoadState.instance.undump(new ByteArrayInputStream(lua_binary_file_bytes), "main.lua");
 LuaClosure c = new LuaClosure(p, globals);
 c.call();
  
More commonly, the Globals.undumper may be used to undump them:
 
 Prototype p = globals.loadPrototype(new ByteArrayInputStream(lua_binary_file_bytes), "main.lua", "b");
 LuaClosure c = new LuaClosure(p, globals);
 c.call();
  
See Also:
  • Field Details

    • ALLOW_INTEGER_CASTING

      public static boolean ALLOW_INTEGER_CASTING
      set true to allow integer compilation
    • NUMBER_FORMAT_FLOATS_OR_DOUBLES

      public static final int NUMBER_FORMAT_FLOATS_OR_DOUBLES
      format corresponding to non-number-patched lua, all numbers are floats or doubles
      See Also:
    • NUMBER_FORMAT_INTS_ONLY

      public static final int NUMBER_FORMAT_INTS_ONLY
      format corresponding to non-number-patched lua, all numbers are ints
      See Also:
    • NUMBER_FORMAT_NUM_PATCH_INT32

      public static final int NUMBER_FORMAT_NUM_PATCH_INT32
      format corresponding to number-patched lua, all numbers are 32-bit (4 byte) ints
      See Also:
    • NUMBER_FORMAT_DEFAULT

      public static final int NUMBER_FORMAT_DEFAULT
      default number format
      See Also:
  • Constructor Details

    • DumpState

      public DumpState(OutputStream w, boolean strip)
  • Method Details

    • dump

      public static int dump(FPrototype f, OutputStream w, boolean strip) throws IOException
      Throws:
      IOException
    • dump

      public static int dump(FPrototype f, OutputStream w, boolean stripDebug, int numberFormat, boolean littleendian) throws IOException
      Parameters:
      f - the function to dump
      w - the output stream to dump to
      stripDebug - true to strip debugging info, false otherwise
      numberFormat - one of NUMBER_FORMAT_FLOATS_OR_DOUBLES, NUMBER_FORMAT_INTS_ONLY, NUMBER_FORMAT_NUM_PATCH_INT32
      littleendian - true to use little endian for numbers, false for big endian
      Returns:
      0 if dump succeeds
      Throws:
      IOException
      IllegalArgumentException - if the number format it not supported