Package com.prineside.luaj
Class Prototype
java.lang.Object
com.prineside.luaj.Prototype
- All Implemented Interfaces:
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);
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetlocalname
(int number, int pc) Get the name of a local variable.void
read
(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) toString()
void
write
(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output)
-
Field Details
-
k
-
code
public int[] code -
p
-
lineinfo
public int[] lineinfo -
locvars
-
upvalues
-
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 interfacecom.esotericsoftware.kryo.KryoSerializable
-
read
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) - Specified by:
read
in interfacecom.esotericsoftware.kryo.KryoSerializable
-
toString
-
getlocalname
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
-