Lua 5.2 compatibility fixes.
This commit is contained in:
@@ -106,14 +106,18 @@ public class LoadState {
|
||||
public static LuaCompiler compiler = null;
|
||||
|
||||
/** Signature byte indicating the file is a compiled binary chunk */
|
||||
private static final byte[] LUA_SIGNATURE = { '\033', 'L', 'u', 'a' };
|
||||
public static final byte[] LUA_SIGNATURE = { '\033', 'L', 'u', 'a' };
|
||||
|
||||
/** Data to catch conversion errors */
|
||||
public static final byte[] LUAC_TAIL = { (byte) 0x19, (byte) 0x93, '\r', '\n', (byte) 0x1a, '\n', };
|
||||
|
||||
|
||||
/** Name for compiled chunks */
|
||||
public static final String SOURCE_BINARY_STRING = "binary string";
|
||||
|
||||
|
||||
/** for header of binary files -- this is Lua 5.1 */
|
||||
public static final int LUAC_VERSION = 0x51;
|
||||
/** for header of binary files -- this is Lua 5.2 */
|
||||
public static final int LUAC_VERSION = 0x52;
|
||||
|
||||
/** for header of binary files -- this is the official format */
|
||||
public static final int LUAC_FORMAT = 0;
|
||||
@@ -346,15 +350,6 @@ public class LoadState {
|
||||
return f;
|
||||
}
|
||||
|
||||
static final byte[] LUAC_TAIL = {
|
||||
(byte) 0x19,
|
||||
(byte) 0x93,
|
||||
(byte) '\r',
|
||||
(byte) '\n',
|
||||
(byte) 0x1a,
|
||||
(byte) '\n',
|
||||
};
|
||||
|
||||
/**
|
||||
* Load the lua chunk header values.
|
||||
* @throws IOException if an i/o exception occurs.
|
||||
|
||||
@@ -25,7 +25,9 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.luaj.vm2.LoadState;
|
||||
import org.luaj.vm2.LocVars;
|
||||
import org.luaj.vm2.LuaUserdata;
|
||||
import org.luaj.vm2.Prototype;
|
||||
import org.luaj.vm2.LuaString;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
@@ -33,21 +35,6 @@ import org.luaj.vm2.LuaValue;
|
||||
|
||||
public class DumpState {
|
||||
|
||||
/** mark for precompiled code (`<esc>Lua') */
|
||||
public static final String LUA_SIGNATURE = "\033Lua";
|
||||
|
||||
/** for header of binary files -- this is Lua 5.1 */
|
||||
public static final int LUAC_VERSION = 0x51;
|
||||
|
||||
/** for header of binary files -- this is the official format */
|
||||
public static final int LUAC_FORMAT = 0;
|
||||
|
||||
/** size of header of binary files */
|
||||
public static final int LUAC_HEADERSIZE = 12;
|
||||
|
||||
/** expected lua header bytes */
|
||||
private static final byte[] LUAC_HEADER_SIGNATURE = { '\033', 'L', 'u', 'a' };
|
||||
|
||||
/** set true to allow integer compilation */
|
||||
public static boolean ALLOW_INTEGER_CASTING = false;
|
||||
|
||||
@@ -133,6 +120,7 @@ public class DumpState {
|
||||
final LuaValue o = k[i];
|
||||
switch ( o.type() ) {
|
||||
case LuaValue.TNIL:
|
||||
case LuaValue.TUSERDATA:
|
||||
writer.write(LuaValue.TNIL);
|
||||
break;
|
||||
case LuaValue.TBOOLEAN:
|
||||
@@ -209,10 +197,10 @@ public class DumpState {
|
||||
}
|
||||
|
||||
void dumpFunction(final Prototype f, final LuaString string) throws IOException {
|
||||
if ( f.source == null || f.source.equals(string) || strip )
|
||||
dumpInt(0);
|
||||
else
|
||||
dumpString(f.source);
|
||||
// if ( f.source == null || f.source.equals(string) || strip )
|
||||
// dumpInt(0);
|
||||
// else
|
||||
// dumpString(f.source);
|
||||
dumpInt(f.linedefined);
|
||||
dumpInt(f.lastlinedefined);
|
||||
dumpChar(f.numparams);
|
||||
@@ -225,15 +213,16 @@ public class DumpState {
|
||||
}
|
||||
|
||||
void dumpHeader() throws IOException {
|
||||
writer.write( LUAC_HEADER_SIGNATURE );
|
||||
writer.write( LUAC_VERSION );
|
||||
writer.write( LUAC_FORMAT );
|
||||
writer.write( LoadState.LUA_SIGNATURE );
|
||||
writer.write( LoadState.LUAC_VERSION );
|
||||
writer.write( LoadState.LUAC_FORMAT );
|
||||
writer.write( IS_LITTLE_ENDIAN? 1: 0 );
|
||||
writer.write( SIZEOF_INT );
|
||||
writer.write( SIZEOF_SIZET );
|
||||
writer.write( SIZEOF_INSTRUCTION );
|
||||
writer.write( SIZEOF_LUA_NUMBER );
|
||||
writer.write( NUMBER_FORMAT );
|
||||
writer.write( LoadState.LUAC_TAIL );
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -537,6 +537,7 @@ public class FuncState extends LuaC {
|
||||
}
|
||||
|
||||
void dischargevars(expdesc e) {
|
||||
System.out.println(" discharg vars e.k " + e.k);
|
||||
switch (e.k) {
|
||||
case LexState.VLOCAL: {
|
||||
e.k = LexState.VNONRELOC;
|
||||
@@ -665,6 +666,11 @@ public class FuncState extends LuaC {
|
||||
return e.u.info;
|
||||
}
|
||||
|
||||
void exp2anyregup (expdesc e) {
|
||||
if (e.k != LexState.VUPVAL || e.hasjumps())
|
||||
exp2anyreg(e);
|
||||
}
|
||||
|
||||
void exp2val(expdesc e) {
|
||||
if (e.hasjumps())
|
||||
this.exp2anyreg(e);
|
||||
@@ -868,7 +874,7 @@ public class FuncState extends LuaC {
|
||||
t.u.ind_t = (short) t.u.info;
|
||||
t.u.ind_idx = (short) this.exp2RK(k);
|
||||
LuaC._assert(t.k == LexState.VUPVAL || vkisinreg(t.k));
|
||||
t.u.ind_vt = (short) ((t.k == LexState.VUPVAL) ? LexState.VUPVAL : LexState.VLOCAL);
|
||||
t.u.ind_vt = (short) ((t.k == LexState.VUPVAL) ? LexState.VUPVAL : LexState.VLOCAL);
|
||||
t.k = LexState.VINDEXED;
|
||||
}
|
||||
|
||||
|
||||
@@ -699,7 +699,7 @@ public class LexState {
|
||||
lookahead.token = TK_EOS; /* and discharge it */
|
||||
} else
|
||||
t.token = llex(t.seminfo); /* read next token */
|
||||
// System.out.println("---- next t.token " + t.token + " (" + txtToken(t.token) + ") " + linenumber );
|
||||
System.out.println("---- next t.token " + t.token + " (" + txtToken(t.token) + ") " + linenumber );
|
||||
}
|
||||
|
||||
void lookahead() {
|
||||
@@ -1109,7 +1109,7 @@ public class LexState {
|
||||
/* fieldsel -> ['.' | ':'] NAME */
|
||||
FuncState fs = this.fs;
|
||||
expdesc key = new expdesc();
|
||||
fs.exp2anyreg(v);
|
||||
fs.exp2anyregup(v);
|
||||
this.next(); /* skip the dot or colon */
|
||||
this.checkname(key);
|
||||
fs.indexed(v, key);
|
||||
@@ -1384,7 +1384,7 @@ public class LexState {
|
||||
}
|
||||
case '[': { /* `[' exp1 `]' */
|
||||
expdesc key = new expdesc();
|
||||
fs.exp2anyreg(v);
|
||||
fs.exp2anyregup(v);
|
||||
this.yindex(key);
|
||||
fs.indexed(v, key);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user