Class Prototype

java.lang.Object
com.prineside.luaj.Prototype
All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable

public class Prototype extends Object implements com.esotericsoftware.kryo.KryoSerializable
Prototype representing compiled lua code. This is both a straight translation of the corresponding C type, and the main data structure for execution of compiled lua bytecode. Generally, the Prototype is not constructed directly is an intermediate result as lua code is loaded using Globals.load(java.io.Reader, String):
 
 Globals globals = JsePlatform.standardGlobals();
 globals.load( new StringReader("print 'hello'"), "main.lua" ).call(); 
  
To create a Prototype directly, a compiler such as
 
 InputStream is = new ByteArrayInputStream("print('hello,world')".getBytes());
 Prototype p = LuaC.instance.compile(is, "script");
 
To simplify loading, the Globals.compilePrototype(java.io.InputStream, String) method may be used:
 
 Prototype p = globals.compileProtoytpe(is, "script");
 
It may also be loaded from a Reader via Globals.compilePrototype(java.io.Reader, String):
 
 Prototype p = globals.compileProtoytpe(new StringReader(script), "script");
 
To un-dump a binary file known to be a binary lua file that has been dumped to a string, the Globals.Undumper interface may be used:
 
 FileInputStream lua_binary_file = new FileInputStream("foo.lc");  // Known to be compiled lua.
 Prototype p = globals.undumper.undump(lua_binary_file, "foo.lua");
 
To execute the code represented by the Prototype it must be supplied to the constructor of a LuaClosure:
 
 Globals globals = JsePlatform.standardGlobals();
 LuaClosure f = new LuaClosure(p, globals);
 f.call();
 
To simplify the debugging of prototype values, the contents may be printed using Print.print(com.prineside.luaj.Prototype):
 
 Print.print(p);
 
See Also:
  • Field Details

    • k

      public LuaValue[] k
    • code

      public int[] code
    • p

      public Prototype[] p
    • lineinfo

      public int[] lineinfo
    • locvars

      public LocVars[] locvars
    • upvalues

      public Upvaldesc[] upvalues
    • source

      public LuaString source
    • linedefined

      public int linedefined
    • lastlinedefined

      public int lastlinedefined
    • numparams

      public int numparams
    • is_vararg

      public int is_vararg
    • maxstacksize

      public int maxstacksize
  • Constructor Details

    • Prototype

      public Prototype()
    • Prototype

      public Prototype(int n_upvalues)
  • Method Details

    • write

      public void write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output)
      Specified by:
      write in interface com.esotericsoftware.kryo.KryoSerializable
    • read

      public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input)
      Specified by:
      read in interface com.esotericsoftware.kryo.KryoSerializable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getlocalname

      public LuaString getlocalname(int number, int pc)
      Get the name of a local variable.
      Parameters:
      number - the local variable number to look up
      pc - the program counter
      Returns:
      the name, or null if not found
    • shortsource

      public String shortsource()