Print any code
This commit is contained in:
@@ -128,6 +128,10 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void printValue( PrintStream ps, LuaValue v ) {
|
static void printValue( PrintStream ps, LuaValue v ) {
|
||||||
|
if (v == null) {
|
||||||
|
ps.print("null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch ( v.type() ) {
|
switch ( v.type() ) {
|
||||||
case LuaValue.TSTRING: printString( ps, (LuaString) v ); break;
|
case LuaValue.TSTRING: printString( ps, (LuaString) v ); break;
|
||||||
default: ps.print( v.tojstring() );
|
default: ps.print( v.tojstring() );
|
||||||
@@ -136,7 +140,7 @@ public class Print extends Lua {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void printConstant(PrintStream ps, Prototype f, int i) {
|
static void printConstant(PrintStream ps, Prototype f, int i) {
|
||||||
printValue( ps, f.k[i] );
|
printValue( ps, i < f.k.length ? f.k[i] : LuaValue.valueOf("UNKNOWN_CONST_" + i) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printUpvalue(PrintStream ps, Upvaldesc u) {
|
static void printUpvalue(PrintStream ps, Upvaldesc u) {
|
||||||
@@ -189,6 +193,9 @@ public class Print extends Lua {
|
|||||||
ps.print("[" + line + "] ");
|
ps.print("[" + line + "] ");
|
||||||
else
|
else
|
||||||
ps.print("[-] ");
|
ps.print("[-] ");
|
||||||
|
if (o >= OPNAMES.length - 1) {
|
||||||
|
ps.print("UNKNOWN_OP_" + o + " ");
|
||||||
|
} else {
|
||||||
ps.print(OPNAMES[o] + " ");
|
ps.print(OPNAMES[o] + " ");
|
||||||
switch (getOpMode(o)) {
|
switch (getOpMode(o)) {
|
||||||
case iABC:
|
case iABC:
|
||||||
@@ -220,11 +227,19 @@ public class Print extends Lua {
|
|||||||
case OP_GETUPVAL:
|
case OP_GETUPVAL:
|
||||||
case OP_SETUPVAL:
|
case OP_SETUPVAL:
|
||||||
ps.print(" ; ");
|
ps.print(" ; ");
|
||||||
|
if (b < f.upvalues.length) {
|
||||||
printUpvalue(ps, f.upvalues[b]);
|
printUpvalue(ps, f.upvalues[b]);
|
||||||
|
} else {
|
||||||
|
ps.print("UNKNOWN_UPVALUE_" + b);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OP_GETTABUP:
|
case OP_GETTABUP:
|
||||||
ps.print(" ; ");
|
ps.print(" ; ");
|
||||||
|
if (b < f.upvalues.length) {
|
||||||
printUpvalue(ps, f.upvalues[b]);
|
printUpvalue(ps, f.upvalues[b]);
|
||||||
|
} else {
|
||||||
|
ps.print("UNKNOWN_UPVALUE_" + b);
|
||||||
|
}
|
||||||
ps.print(" ");
|
ps.print(" ");
|
||||||
if (ISK(c))
|
if (ISK(c))
|
||||||
printConstant(ps, f, INDEXK(c));
|
printConstant(ps, f, INDEXK(c));
|
||||||
@@ -233,7 +248,11 @@ public class Print extends Lua {
|
|||||||
break;
|
break;
|
||||||
case OP_SETTABUP:
|
case OP_SETTABUP:
|
||||||
ps.print(" ; ");
|
ps.print(" ; ");
|
||||||
|
if (a < f.upvalues.length) {
|
||||||
printUpvalue(ps, f.upvalues[a]);
|
printUpvalue(ps, f.upvalues[a]);
|
||||||
|
} else {
|
||||||
|
ps.print("UNKNOWN_UPVALUE_" + a);
|
||||||
|
}
|
||||||
ps.print(" ");
|
ps.print(" ");
|
||||||
if (ISK(b))
|
if (ISK(b))
|
||||||
printConstant(ps, f, INDEXK(b));
|
printConstant(ps, f, INDEXK(b));
|
||||||
@@ -280,7 +299,11 @@ public class Print extends Lua {
|
|||||||
ps.print(" ; to " + (sbx + pc + 2));
|
ps.print(" ; to " + (sbx + pc + 2));
|
||||||
break;
|
break;
|
||||||
case OP_CLOSURE:
|
case OP_CLOSURE:
|
||||||
|
if (bx < f.p.length) {
|
||||||
ps.print(" ; " + f.p[bx].getClass().getName());
|
ps.print(" ; " + f.p[bx].getClass().getName());
|
||||||
|
} else {
|
||||||
|
ps.print(" ; UNKNOWN_PROTYPE_" + bx);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case OP_SETLIST:
|
case OP_SETLIST:
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
@@ -294,6 +317,7 @@ public class Print extends Lua {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user