org.luaj.vm2
Class Prototype

java.lang.Object
  extended by org.luaj.vm2.Prototype

public class Prototype
extends java.lang.Object

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 LuaC may be used:

 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(org.luaj.vm2.Prototype):
 Print.print(p);
 

See Also:
LuaClosure, Globals, Globals.undumper, Globals.compiler, Print.print(org.luaj.vm2.Prototype)

Field Summary
 int[] code
           
 int is_vararg
           
 LuaValue[] k
           
 int lastlinedefined
           
 int linedefined
           
 int[] lineinfo
           
 LocVars[] locvars
           
 int maxstacksize
           
 int numparams
           
 Prototype[] p
           
 LuaString source
           
 Upvaldesc[] upvalues
           
 
Constructor Summary
Prototype()
           
Prototype(int n_upvalues)
           
 
Method Summary
 LuaString getlocalname(int number, int pc)
          Get the name of a local variable.
 java.lang.String shortsource()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

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 Detail

Prototype

public Prototype()

Prototype

public Prototype(int n_upvalues)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.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 java.lang.String shortsource()


Copyright © 2007-2015 Luaj.org. All Rights Reserved.