org.luaj.vm2
Class Prototype
java.lang.Object
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)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
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
Prototype
public Prototype()
Prototype
public Prototype(int n_upvalues)
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 uppc
- 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.