public class Prototype extends Object
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);
public LuaValue[] k
public int[] code
public Prototype[] p
public int[] lineinfo
public LocVars[] locvars
public Upvaldesc[] upvalues
public LuaString source
public int linedefined
public int lastlinedefined
public int numparams
public int is_vararg
public int maxstacksize
public int endidx
public int startidx
public String name
Copyright © 2020. All rights reserved.