Print any code

This commit is contained in:
Enyby
2018-09-14 02:09:43 +03:00
committed by GitHub
parent b459724103
commit f073919f64

View File

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