Print any code #10
10
.cvsignore → .gitignore
vendored
10
.cvsignore → .gitignore
vendored
@@ -1,8 +1,8 @@
|
||||
bin
|
||||
target
|
||||
build
|
||||
lib
|
||||
jit
|
||||
bin/
|
||||
target/
|
||||
build/
|
||||
lib/
|
||||
jit/
|
||||
*.ser
|
||||
*.gz
|
||||
*.jar
|
||||
@@ -1,21 +1,18 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
# This is a fork!
|
||||
<div style="border: 1px dotted red; margin: 1.em 0.5em; font-weight: bold; color: red;">
|
||||
This repository has been forked from the original CVS sources of Luaj.
|
||||
The commit history has been converted to make sure that the original work of
|
||||
James Roseborough and Ian Farmer is not lost.
|
||||
Unfortunately, I was not able to contact either James or Ian to hand over
|
||||
ownership of the Github organization/repo as I have originally intended to.
|
||||
The community however seems interested enough to continue work on the original
|
||||
sources and therefore I have decided to make sure that any useful pull requests
|
||||
that may add some value to the original code base shall be merged in from now
|
||||
on.<br>
|
||||
-- Benjamin P. Jung, Jan. 26th 2018
|
||||
</div>
|
||||
|
||||
<head>
|
||||
<title>Getting Started with LuaJ</title>
|
||||
<link rel="stylesheet" type="text/css" href="http://www.lua.org/lua.css">
|
||||
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<hr>
|
||||
<h1>
|
||||
<a href="README.html"><img src="http://sourceforge.net/dbimage.php?id=196139" alt="" border="0"></a>
|
||||
|
||||
Getting Started with LuaJ
|
||||
|
||||
</h1>
|
||||
<h1>Getting Started with LuaJ</h1>
|
||||
James Roseborough, Ian Farmer, Version 3.0.1
|
||||
<p>
|
||||
<small>
|
||||
@@ -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) {
|
||||
@@ -152,7 +156,7 @@ public class Print extends Lua {
|
||||
int[] code = f.code;
|
||||
int pc, n = code.length;
|
||||
for (pc = 0; pc < n; pc++) {
|
||||
printOpCode(f, pc);
|
||||
pc = printOpCode(f, pc);
|
||||
ps.println();
|
||||
}
|
||||
}
|
||||
@@ -161,9 +165,10 @@ public class Print extends Lua {
|
||||
* Print an opcode in a prototype
|
||||
* @param f the {@link Prototype}
|
||||
* @param pc the program counter to look up and print
|
||||
* @return pc same as above or changed
|
||||
*/
|
||||
public static void printOpCode(Prototype f, int pc) {
|
||||
printOpCode(ps,f,pc);
|
||||
public static int printOpCode(Prototype f, int pc) {
|
||||
return printOpCode(ps,f,pc);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,8 +176,9 @@ public class Print extends Lua {
|
||||
* @param ps the {@link PrintStream} to print to
|
||||
* @param f the {@link Prototype}
|
||||
* @param pc the program counter to look up and print
|
||||
* @return pc same as above or changed
|
||||
*/
|
||||
public static void printOpCode(PrintStream ps, Prototype f, int pc) {
|
||||
public static int printOpCode(PrintStream ps, Prototype f, int pc) {
|
||||
int[] code = f.code;
|
||||
int i = code[pc];
|
||||
int o = GET_OPCODE(i);
|
||||
@@ -187,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:
|
||||
@@ -218,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));
|
||||
@@ -231,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));
|
||||
@@ -278,11 +299,15 @@ 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)
|
||||
ps.print(" ; " + ((int) code[++pc]));
|
||||
ps.print(" ; " + ((int) code[++pc]) + " (stored in the next OP)");
|
||||
else
|
||||
ps.print(" ; " + ((int) c));
|
||||
break;
|
||||
@@ -293,6 +318,8 @@ public class Print extends Lua {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pc;
|
||||
}
|
||||
|
||||
private static int getline(Prototype f, int pc) {
|
||||
return pc>0 && f.lineinfo!=null && pc<f.lineinfo.length? f.lineinfo[pc]: -1;
|
||||
|
||||
Reference in New Issue
Block a user