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