|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.luaj.vm2.LoadState
public class LoadState
Class to undump compiled lua bytecode into a Prototype
instances.
The LoadState
class provides the default Globals.Undumper
which is used to undump a string of bytes that represent a lua binary file
using either the C-based lua compiler, or luaj's
LuaC
compiler.
The canonical method to load and execute code is done indirectly using the Globals:
Globals globals = JsePlatform.standardGlobals();
LuaValue chunk = globasl.load("print('hello, world')", "main.lua");
chunk.call();
This should work regardless of which Globals.Compiler
or Globals.Undumper
have been installed.
By default, when using JsePlatform
or
JmePlatform
to construct globals, the LoadState
default undumper is installed
as the default Globals.Undumper
.
A lua binary file is created via the org.luaj.vm2.compiler.DumpState
class
:
Globals globals = JsePlatform.standardGlobals();
Prototype p = globals.compilePrototype(new StringReader("print('hello, world')"), "main.lua");
ByteArrayOutputStream o = new ByteArrayOutputStream();
org.luaj.vm2.compiler.DumpState.dump(p, o, false);
byte[] lua_binary_file_bytes = o.toByteArray();
The LoadState
's default undumper instance
may be used directly to undump these bytes:
Prototypep = LoadState.instance.undump(new ByteArrayInputStream(lua_binary_file_bytes), "main.lua");
LuaClosure c = new LuaClosure(p, globals);
c.call();
More commonly, the Globals.Undumper
may be used to undump them:
Prototype p = globals.loadPrototype(new ByteArrayInputStream(lua_binary_file_bytes), "main.lua", "b");
LuaClosure c = new LuaClosure(p, globals);
c.call();
Globals.Compiler
,
Globals.Undumper
,
LuaClosure
,
LuaFunction
,
LuaC
,
LuaJC
,
Globals.compiler
,
Globals#load(InputStream, String, LuaValue)
Field Summary | |
---|---|
static java.lang.String |
encoding
The character encoding to use for file encoding. |
static Globals.Undumper |
instance
Shared instance of Globals.Undumper to use loading prototypes from binary lua files |
java.io.DataInputStream |
is
input stream from which we are loading |
static byte[] |
LUA_SIGNATURE
Signature byte indicating the file is a compiled binary chunk |
static int |
LUA_TBOOLEAN
|
static int |
LUA_TFUNCTION
|
static int |
LUA_TINT
|
static int |
LUA_TLIGHTUSERDATA
|
static int |
LUA_TNIL
|
static int |
LUA_TNONE
|
static int |
LUA_TNUMBER
|
static int |
LUA_TSTRING
|
static int |
LUA_TTABLE
|
static int |
LUA_TTHREAD
|
static int |
LUA_TUSERDATA
|
static int |
LUA_TVALUE
|
static int |
LUAC_FORMAT
for header of binary files -- this is the official format |
static int |
LUAC_HEADERSIZE
size of header of binary files |
static byte[] |
LUAC_TAIL
Data to catch conversion errors |
static int |
LUAC_VERSION
for header of binary files -- this is Lua 5.2 |
static int |
NUMBER_FORMAT_FLOATS_OR_DOUBLES
format corresponding to non-number-patched lua, all numbers are floats or doubles |
static int |
NUMBER_FORMAT_INTS_ONLY
format corresponding to non-number-patched lua, all numbers are ints |
static int |
NUMBER_FORMAT_NUM_PATCH_INT32
format corresponding to number-patched lua, all numbers are 32-bit (4 byte) ints |
static java.lang.String |
SOURCE_BINARY_STRING
Name for compiled chunks |
Method Summary | |
---|---|
static java.lang.String |
getSourceName(java.lang.String name)
Construct a source name from a supplied chunk name |
static void |
install(Globals globals)
Install this class as the standard Globals.Undumper for the supplied Globals |
Prototype |
loadFunction(LuaString p)
Load a function prototype from the input stream |
void |
loadHeader()
Load the lua chunk header values. |
static LuaValue |
longBitsToLuaNumber(long bits)
Convert bits in a long value to a LuaValue . |
static Prototype |
undump(java.io.InputStream stream,
java.lang.String chunkname)
Load input stream as a lua binary chunk if the first 4 bytes are the lua binary signature. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Globals.Undumper instance
public static final int NUMBER_FORMAT_FLOATS_OR_DOUBLES
public static final int NUMBER_FORMAT_INTS_ONLY
public static final int NUMBER_FORMAT_NUM_PATCH_INT32
public static final int LUA_TINT
public static final int LUA_TNONE
public static final int LUA_TNIL
public static final int LUA_TBOOLEAN
public static final int LUA_TLIGHTUSERDATA
public static final int LUA_TNUMBER
public static final int LUA_TSTRING
public static final int LUA_TTABLE
public static final int LUA_TFUNCTION
public static final int LUA_TUSERDATA
public static final int LUA_TTHREAD
public static final int LUA_TVALUE
public static java.lang.String encoding
public static final byte[] LUA_SIGNATURE
public static final byte[] LUAC_TAIL
public static final java.lang.String SOURCE_BINARY_STRING
public static final int LUAC_VERSION
public static final int LUAC_FORMAT
public static final int LUAC_HEADERSIZE
public final java.io.DataInputStream is
Method Detail |
---|
public static void install(Globals globals)
public static LuaValue longBitsToLuaNumber(long bits)
LuaValue
.
bits
- long value containing the bits
LuaInteger
or LuaDouble
whose value corresponds to the bits provided.public Prototype loadFunction(LuaString p) throws java.io.IOException
p
- name of the source
Prototype
instance that was loaded
java.io.IOException
public void loadHeader() throws java.io.IOException
java.io.IOException
- if an i/o exception occurs.public static Prototype undump(java.io.InputStream stream, java.lang.String chunkname) throws java.io.IOException
stream
- InputStream to read, after having read the first byte alreadychunkname
- Name to apply to the loaded chunk
Prototype
that was loaded, or null if the first 4 bytes were not the lua signature.
java.io.IOException
- if an IOException occurspublic static java.lang.String getSourceName(java.lang.String name)
name
- String name that appears in the chunk
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |