Improve debug lib consistency with lua 5.2

This commit is contained in:
James Roseborough
2012-09-15 04:53:37 +00:00
parent 4795171956
commit 6ae66f6fce
9 changed files with 217 additions and 164 deletions

View File

@@ -124,6 +124,10 @@ public class LuaClosure extends LuaFunction {
return s_metatable; return s_metatable;
} }
public String tojstring() {
return "function: " + p.toString();
}
public final LuaValue call() { public final LuaValue call() {
LuaValue[] stack = new LuaValue[p.maxstacksize]; LuaValue[] stack = new LuaValue[p.maxstacksize];
for (int i = 0; i < p.numparams; ++i ) for (int i = 0; i < p.numparams; ++i )
@@ -185,7 +189,8 @@ public class LuaClosure extends LuaFunction {
LuaValue[] k = p.k; LuaValue[] k = p.k;
// upvalues are only possible when closures create closures // upvalues are only possible when closures create closures
UpValue[] openups = p.p.length>0? new UpValue[p.p.length]: null; // TODO: use linked list.
UpValue[] openups = p.p.length>0? new UpValue[stack.length]: null;
// debug wants args to this function // debug wants args to this function
if (DebugLib.DEBUG_ENABLED && globals != null) if (DebugLib.DEBUG_ENABLED && globals != null)

View File

@@ -47,8 +47,8 @@ public class LuaError extends RuntimeException {
protected Throwable cause; protected Throwable cause;
public String getMessage() { public String getMessage() {
return (fileline != null? fileline + " ": "") return traceback != null? traceback:
+ (traceback != null? traceback: super.getMessage()); (fileline != null? fileline: "?:-1") + " " + super.getMessage();
} }
/** Construct LuaError when a program exception occurs. /** Construct LuaError when a program exception occurs.

View File

@@ -72,7 +72,10 @@ public class LuaFunction extends LuaValue {
public String tojstring() { public String tojstring() {
String s = getClass().getName(); String s = getClass().getName();
return "function: " + s.substring(s.lastIndexOf('.')+1); return "function: " + s.substring(Math.max(s.lastIndexOf('.'),s.lastIndexOf('$'))+1);
} }
public LuaString strvalue() {
return valueOf(tojstring());
}
} }

View File

@@ -307,9 +307,17 @@ public class LuaThread extends LuaValue {
public String traceback(int level) { public String traceback(int level) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append( "stack traceback:" ); sb.append( "stack traceback:" );
for (LuaFunction f = null; (f = getFunction(level)) != null; ++level) { CallFrame c = getCallFrame(level);
if (c != null) {
sb.append("\n\t");
sb.append( c.sourceline() );
sb.append( " in " );
while ( (c = getCallFrame(++level)) != null ) {
sb.append( c.tracename() );
sb.append( "\n\t" ); sb.append( "\n\t" );
sb.append( f.tostring() ); sb.append( c.sourceline() );
sb.append( " in " );
}
sb.append( "main chunk" ); sb.append( "main chunk" );
} }
return sb.toString(); return sb.toString();
@@ -332,17 +340,16 @@ public class LuaThread extends LuaValue {
public static class CallFrame { public static class CallFrame {
public LuaFunction f; public LuaFunction f;
int pc, top; public int pc;
int top;
Varargs v; Varargs v;
LuaValue[] stack; LuaValue[] stack;
boolean tail;
public void set(LuaClosure function, Varargs varargs, LuaValue[] stack) { public void set(LuaClosure function, Varargs varargs, LuaValue[] stack) {
this.f = function; this.f = function;
this.v = varargs; this.v = varargs;
this.stack = stack; this.stack = stack;
} this.tail = false;
public void print() {
// TODO Auto-generated method stub
} }
public void set(LuaFunction function) { public void set(LuaFunction function) {
this.f = function; this.f = function;
@@ -356,7 +363,9 @@ public class LuaThread extends LuaValue {
this.pc = pc; this.pc = pc;
this.v = v; this.v = v;
this.top = top; this.top = top;
if (DebugLib.DEBUG_ENABLED && DebugLib.TRACE & f.isclosure()) if (f.checkclosure().p.code[pc] == Lua.OP_TAILCALL)
this.tail = true;
if (DebugLib.TRACE)
Print.printState(f.checkclosure(), pc, stack, top, v); Print.printState(f.checkclosure(), pc, stack, top, v);
} }
public Varargs getLocal(int i) { public Varargs getLocal(int i) {
@@ -377,34 +386,32 @@ public class LuaThread extends LuaValue {
} }
public int currentline() { public int currentline() {
if ( !f.isclosure() ) return -1; if ( !f.isclosure() ) return -1;
int[] li = ((LuaClosure)f).p.lineinfo; int[] li = f.checkclosure().p.lineinfo;
return li==null || pc<0 || pc>=li.length? -1: li[pc]; return li==null || pc<0 || pc>=li.length? -1: li[pc];
} }
public LuaString[] getfunckind() {
if ( !f.isclosure() || pc<0 ) return null;
Prototype p = ((LuaClosure)f).p;
int stackpos = (p.code[pc] >> 6) & 0xff;
return DebugLib.getobjname(p, pc, stackpos);
}
public String sourceline() { public String sourceline() {
if ( !f.isclosure() ) return f.tojstring(); if ( !f.isclosure() ) return f.tojstring();
String s = ((LuaClosure)f).p.source.tojstring(); String s = f.checkclosure().p.source.tojstring();
int line = currentline(); int line = currentline();
return (s.startsWith("@")||s.startsWith("=")? s.substring(1): s) + ":" + line; return (s.startsWith("@")||s.startsWith("=")? s.substring(1): s) + ":" + line;
} }
public String tracename() { public String tracename() {
LuaString[] kind = getfunckind(); LuaString[] kind = DebugLib.getfuncname(this);
if ( kind == null ) if ( kind == null )
return "function ?"; return "function ?";
return "function "+kind[0].tojstring(); return "function "+kind[0].tojstring();
} }
public LuaString getlocalname(int index) { public LuaString getlocalname(int index) {
if ( !f.isclosure() ) return null; if ( !f.isclosure() ) return null;
return ((LuaClosure)f).p.getlocalname(index, pc); return f.checkclosure().p.getlocalname(index, pc);
} }
public String tojstring() { public String tojstring() {
return tracename()+" "+sourceline(); return tracename()+" "+sourceline();
} }
public boolean istailcall() {
return tail;
}
} }
} }

View File

@@ -410,8 +410,7 @@ public class Print extends Lua {
s.substring(0, 32).tojstring()+"...+"+(s.length()-32)+"b"); s.substring(0, 32).tojstring()+"...+"+(s.length()-32)+"b");
break; break;
case LuaValue.TFUNCTION: case LuaValue.TFUNCTION:
ps.print( ( v instanceof LuaClosure )? ps.print( v.tojstring() );
((LuaClosure)v).p.toString(): v.tojstring() );
break; break;
case LuaValue.TUSERDATA: case LuaValue.TUSERDATA:
Object o = v.touserdata(); Object o = v.touserdata();

View File

@@ -21,9 +21,8 @@
******************************************************************************/ ******************************************************************************/
package org.luaj.vm2.lib; package org.luaj.vm2.lib;
import java.lang.ref.WeakReference;
import org.luaj.vm2.Globals; import org.luaj.vm2.Globals;
import org.luaj.vm2.LoadState.LuaCompiler;
import org.luaj.vm2.Lua; import org.luaj.vm2.Lua;
import org.luaj.vm2.LuaBoolean; import org.luaj.vm2.LuaBoolean;
import org.luaj.vm2.LuaClosure; import org.luaj.vm2.LuaClosure;
@@ -34,11 +33,14 @@ import org.luaj.vm2.LuaNumber;
import org.luaj.vm2.LuaString; import org.luaj.vm2.LuaString;
import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaThread; import org.luaj.vm2.LuaThread;
import org.luaj.vm2.LuaThread.CallFrame;
import org.luaj.vm2.LuaUserdata; import org.luaj.vm2.LuaUserdata;
import org.luaj.vm2.LuaValue; import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Print;
import org.luaj.vm2.Prototype; import org.luaj.vm2.Prototype;
import org.luaj.vm2.Varargs; import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.jme.JmePlatform;
import org.luaj.vm2.lib.jse.JsePlatform;
import org.luaj.vm2.luajc.LuaJC;
/** /**
* Subclass of {@link LibFunction} which implements the lua standard {@code debug} * Subclass of {@link LibFunction} which implements the lua standard {@code debug}
@@ -90,9 +92,14 @@ public class DebugLib extends OneArgFunction {
private static final LuaString RETURN = valueOf("return"); private static final LuaString RETURN = valueOf("return");
private static final LuaString TAILRETURN = valueOf("tail return"); private static final LuaString TAILRETURN = valueOf("tail return");
private static final LuaString CONSTANT = valueOf("constant"); private static final LuaString CONSTANT = valueOf("constant");
private static final LuaString FOR_ITERATOR = valueOf("for iterator");
private static final LuaString METAMETHOD = valueOf("metamethod");
private static final LuaString FUNC = valueOf("func"); private static final LuaString FUNC = valueOf("func");
private static final LuaString ISTAILCALL = valueOf("istailcall");
private static final LuaString ISVARARG = valueOf("isvararg");
private static final LuaString NUPS = valueOf("nups"); private static final LuaString NUPS = valueOf("nups");
private static final LuaString NPARAMS = valueOf("nparams");
private static final LuaString NAME = valueOf("name"); private static final LuaString NAME = valueOf("name");
private static final LuaString NAMEWHAT = valueOf("namewhat"); private static final LuaString NAMEWHAT = valueOf("namewhat");
private static final LuaString WHAT = valueOf("what"); private static final LuaString WHAT = valueOf("what");
@@ -110,9 +117,23 @@ public class DebugLib extends OneArgFunction {
globals.debuglib = this; globals.debuglib = this;
DEBUG_ENABLED = true; DEBUG_ENABLED = true;
LuaTable debug = new LuaTable(); LuaTable debug = new LuaTable();
env.set("debug", new debug()); debug.set("debug", new debug());
env.set("gethook", new gethook()); debug.set("gethook", new gethook());
env.set("sethook", new sethook()); debug.set("getinfo", new getinfo());
debug.set("getlocal", new getlocal());
debug.set("getmetatable", new getmetatable());
debug.set("getregistry", new getregistry());
debug.set("getupvalue", new getupvalue());
debug.set("getuservalue", new getuservalue());
debug.set("sethook", new sethook());
debug.set("setlocal", new setlocal());
debug.set("setmetatable", new setmetatable());
debug.set("setupvalue", new setupvalue());
debug.set("setuservalue", new setuservalue());
debug.set("traceback", new traceback());
debug.set("upvalueid", new upvalueid());
debug.set("upvaluejoin", new upvaluejoin());
env.set("debug", debug);
env.get("package").get("loaded").set("debug", debug); env.get("package").get("loaded").set("debug", debug);
return debug; return debug;
} }
@@ -140,9 +161,74 @@ public class DebugLib extends OneArgFunction {
public Varargs invoke(Varargs args) { public Varargs invoke(Varargs args) {
int a=1; int a=1;
LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running_thread; LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running_thread;
LuaValue func = args.optfunction(a++, null); LuaValue func = args.arg(a++);
String what = args.optjstring(a++,""); String what = args.optjstring(a++, "flnStu");
LuaThread.CallStack callstack = thread.callstack;
// find the stack info
LuaThread.CallFrame frame;
if ( func.isnumber() ) {
frame = callstack.getCallFrame(func.toint());
if (frame == null)
return NONE; return NONE;
func = frame.f;
} else if ( func.isfunction() ) {
frame = callstack.findCallFrame(func);
} else {
return argerror(a-2, "function or level");
}
// start a table
LuaTable info = new LuaTable();
LuaClosure c = func.optclosure(null);
if (what.indexOf('S') >= 0) {
if (c != null) {
Prototype p = c.p;
info.set(WHAT, LUA);
info.set(SOURCE, p.source);
info.set(SHORT_SRC, valueOf(sourceshort(p)));
info.set(LINEDEFINED, valueOf(p.linedefined));
info.set(LASTLINEDEFINED, valueOf(p.lastlinedefined));
} else {
String shortName = func.tojstring();
LuaString name = LuaString.valueOf("[Java] " + shortName);
info.set(WHAT, JAVA);
info.set(SOURCE, name);
info.set(SHORT_SRC, valueOf(shortName));
info.set(LINEDEFINED, LuaValue.MINUSONE);
info.set(LASTLINEDEFINED, LuaValue.MINUSONE);
}
}
if (what.indexOf('l') >= 0) {
info.set( CURRENTLINE, valueOf(frame!=null? frame.currentline(): -1) );
}
if (what.indexOf('u') >= 0) {
info.set(NUPS, valueOf(c!=null? c.p.upvalues.length: 0));
info.set(NPARAMS, valueOf(c!=null? c.p.numparams: 0));
info.set(ISVARARG, valueOf(c!=null? c.p.is_vararg: 0));
}
if (what.indexOf('n') >= 0) {
if (frame != null) {
LuaString[] kind = getfuncname(frame);
info.set(NAME, kind!=null? kind[0]: QMARK);
info.set(NAMEWHAT, kind!=null? kind[1]: EMPTYSTRING);
}
}
if (what.indexOf('t') >= 0) {
info.set(ISTAILCALL, frame != null && frame.istailcall()? ONE: ZERO);
}
if (what.indexOf('L') >= 0) {
LuaTable lines = new LuaTable();
info.set(ACTIVELINES, lines);
CallFrame cf;
for (int l = 1; (cf=callstack.getCallFrame(l)) != null; ++l)
if (cf.f == func)
lines.insert(-1, valueOf(cf.currentline()));
}
if (what.indexOf('f') >= 0) {
info.set( FUNC, func );
}
return info;
} }
} }
@@ -151,9 +237,9 @@ public class DebugLib extends OneArgFunction {
public Varargs invoke(Varargs args) { public Varargs invoke(Varargs args) {
int a=1; int a=1;
LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running_thread; LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running_thread;
LuaValue func = args.optfunction(a++, null); int level = args.checkint(a++);
LuaValue local = args.checkvalue(a++); int local = args.checkint(a++);
return thread.callstack.findCallFrame(func).getLocal(local.toint()); return thread.callstack.getCallFrame(level).getLocal(local);
} }
} }
@@ -225,32 +311,27 @@ public class DebugLib extends OneArgFunction {
public Varargs invoke(Varargs args) { public Varargs invoke(Varargs args) {
int a=1; int a=1;
LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running_thread; LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running_thread;
LuaValue func = args.optfunction(a++, null); int level = args.checkint(a++);
LuaValue local = args.checkvalue(a++); int local = args.checkint(a++);
LuaValue value = args.checkvalue(a++); LuaValue value = args.arg(a++);
return thread.callstack.findCallFrame(func).setLocal(local.toint(), value); return thread.callstack.getCallFrame(level).setLocal(local, value);
} }
} }
// debug.setmetatable (value, table) // debug.setmetatable (value, table)
final class setmetatable extends VarArgFunction { final class setmetatable extends TwoArgFunction {
public Varargs invoke(Varargs args) { public LuaValue call(LuaValue value, LuaValue table) {
LuaValue object = args.arg(1); LuaValue mt = table.opttable(null);
try { switch ( value.type() ) {
LuaValue mt = args.opttable(2, null);
switch ( object.type() ) {
case TNIL: LuaNil.s_metatable = mt; break; case TNIL: LuaNil.s_metatable = mt; break;
case TNUMBER: LuaNumber.s_metatable = mt; break; case TNUMBER: LuaNumber.s_metatable = mt; break;
case TBOOLEAN: LuaBoolean.s_metatable = mt; break; case TBOOLEAN: LuaBoolean.s_metatable = mt; break;
case TSTRING: LuaString.s_metatable = mt; break; case TSTRING: LuaString.s_metatable = mt; break;
case TFUNCTION: LuaFunction.s_metatable = mt; break; case TFUNCTION: LuaFunction.s_metatable = mt; break;
case TTHREAD: LuaThread.s_metatable = mt; break; case TTHREAD: LuaThread.s_metatable = mt; break;
default: object.setmetatable( mt ); default: value.setmetatable( mt );
}
return LuaValue.TRUE;
} catch ( LuaError e ) {
return varargsOf(FALSE, valueOf(e.toString()));
} }
return value;
} }
} }
@@ -291,7 +372,7 @@ public class DebugLib extends OneArgFunction {
LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running_thread; LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running_thread;
String message = args.optjstring(a++, null); String message = args.optjstring(a++, null);
int level = args.optint(a++,1); int level = args.optint(a++,1);
String tb = thread.callstack.traceback(level-1); String tb = thread.callstack.traceback(level);
return valueOf(message!=null? message+"\n"+tb: tb); return valueOf(message!=null? message+"\n"+tb: tb);
} }
} }
@@ -332,82 +413,6 @@ public class DebugLib extends OneArgFunction {
return null; return null;
} }
// ------------------- library function implementations -----------------
protected Varargs _getinfo(Varargs args, LuaValue level0func) {
int a=1;
LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running_thread;
LuaValue func = args.arg(a++);
String what = args.optjstring(a++, "nSluf");
LuaThread.CallStack callstack = thread.callstack;
// find the stack info
LuaThread.CallFrame frame;
if ( func.isnumber() ) {
frame = callstack.getCallFrame(func.toint());
} else {
frame = callstack.findCallFrame(func);
}
if (frame == null)
return NIL;
// start a table
LuaTable info = new LuaTable();
LuaClosure c = frame.f.isclosure()? (LuaClosure) frame.f: null;
for (int i = 0, j = what.length(); i < j; i++) {
switch (what.charAt(i)) {
case 'S': {
if ( c != null ) {
Prototype p = c.p;
info.set(WHAT, LUA);
info.set(SOURCE, p.source);
info.set(SHORT_SRC, valueOf(sourceshort(p)));
info.set(LINEDEFINED, valueOf(p.linedefined));
info.set(LASTLINEDEFINED, valueOf(p.lastlinedefined));
} else {
String shortName = frame.f.tojstring();
LuaString name = LuaString.valueOf("[Java] "+shortName);
info.set(WHAT, JAVA);
info.set(SOURCE, name);
info.set(SHORT_SRC, valueOf(shortName));
info.set(LINEDEFINED, LuaValue.MINUSONE);
info.set(LASTLINEDEFINED, LuaValue.MINUSONE);
}
break;
}
case 'l': {
int line = frame.currentline();
info.set( CURRENTLINE, valueOf(line) );
break;
}
case 'u': {
info.set(NUPS, valueOf(c!=null? c.p.upvalues.length: 0));
break;
}
case 'n': {
LuaString[] kind = frame.getfunckind();
info.set(NAME, kind!=null? kind[0]: QMARK);
info.set(NAMEWHAT, kind!=null? kind[1]: EMPTYSTRING);
break;
}
case 'f': {
info.set( FUNC, frame.f );
break;
}
case 'L': {
LuaTable lines = new LuaTable();
info.set(ACTIVELINES, lines);
int line = frame.currentline();
if ( line >= 0 )
lines.set(1, valueOf(line));
break;
}
}
}
return info;
}
public static String sourceshort(Prototype p) { public static String sourceshort(Prototype p) {
String name = p.source.tojstring(); String name = p.source.tojstring();
if ( name.startsWith("@") || name.startsWith("=") ) if ( name.startsWith("@") || name.startsWith("=") )
@@ -417,12 +422,47 @@ public class DebugLib extends OneArgFunction {
return name; return name;
} }
// =======================================================
static void lua_assert(boolean x) { static void lua_assert(boolean x) {
if (!x) throw new RuntimeException("lua_assert failed"); if (!x) throw new RuntimeException("lua_assert failed");
} }
public static LuaString[] getfuncname(CallFrame frame) {
if (!frame.f.isclosure())
return new LuaString[] { frame.f.strvalue(), JAVA };
Prototype p = frame.f.checkclosure().p;
int pc = frame.pc;
int i = p.code[pc]; /* calling instruction */
LuaString tm;
switch (Lua.GET_OPCODE(i)) {
case Lua.OP_CALL:
case Lua.OP_TAILCALL: /* get function name */
return getobjname(p, pc, Lua.GETARG_A(i));
case Lua.OP_TFORCALL: /* for iterator */
return new LuaString[] { FOR_ITERATOR, FOR_ITERATOR};
/* all other instructions can call only through metamethods */
case Lua.OP_SELF:
case Lua.OP_GETTABUP:
case Lua.OP_GETTABLE: tm = LuaValue.INDEX; break;
case Lua.OP_SETTABUP:
case Lua.OP_SETTABLE: tm = LuaValue.NEWINDEX; break;
case Lua.OP_EQ: tm = LuaValue.EQ; break;
case Lua.OP_ADD: tm = LuaValue.ADD; break;
case Lua.OP_SUB: tm = LuaValue.SUB; break;
case Lua.OP_MUL: tm = LuaValue.MUL; break;
case Lua.OP_DIV: tm = LuaValue.DIV; break;
case Lua.OP_MOD: tm = LuaValue.MOD; break;
case Lua.OP_POW: tm = LuaValue.POW; break;
case Lua.OP_UNM: tm = LuaValue.UNM; break;
case Lua.OP_LEN: tm = LuaValue.LEN; break;
case Lua.OP_LT: tm = LuaValue.LT; break;
case Lua.OP_LE: tm = LuaValue.LE; break;
case Lua.OP_CONCAT: tm = LuaValue.CONCAT; break;
default:
return null; /* else no useful name can be found */
}
return new LuaString[] { tm, METAMETHOD };
}
// return StrValue[] { name, namewhat } if found, null if not // return StrValue[] { name, namewhat } if found, null if not
public static LuaString[] getobjname(Prototype p, int lastpc, int reg) { public static LuaString[] getobjname(Prototype p, int lastpc, int reg) {
int pc = lastpc; // currentpc(L, ci); int pc = lastpc; // currentpc(L, ci);
@@ -445,12 +485,12 @@ public class DebugLib extends OneArgFunction {
case Lua.OP_GETTABUP: case Lua.OP_GETTABUP:
case Lua.OP_GETTABLE: { case Lua.OP_GETTABLE: {
int k = Lua.GETARG_C(i); /* key index */ int k = Lua.GETARG_C(i); /* key index */
int t = Lua.GETARG_Bx(i); /* table index */ int t = Lua.GETARG_B(i); /* table index */
LuaString vn = (Lua.GET_OPCODE(i) == Lua.OP_GETTABLE) /* name of indexed variable */ LuaString vn = (Lua.GET_OPCODE(i) == Lua.OP_GETTABLE) /* name of indexed variable */
? p.getlocalname(t + 1, pc) ? p.getlocalname(t + 1, pc)
: (t < p.upvalues.length ? p.upvalues[t].name : QMARK); : (t < p.upvalues.length ? p.upvalues[t].name : QMARK);
name = kname(p, k); name = kname(p, k);
return new LuaString[] { name, vn.eq_b(ENV)? GLOBAL: FIELD }; return new LuaString[] { name, vn != null && vn.eq_b(ENV)? GLOBAL: FIELD };
} }
case Lua.OP_GETUPVAL: { case Lua.OP_GETUPVAL: {
int u = Lua.GETARG_B(i); /* upvalue index */ int u = Lua.GETARG_B(i); /* upvalue index */

View File

@@ -63,10 +63,10 @@ public class ScriptDrivenTest extends TestCase implements ResourceFinder {
default: default:
case JSE: case JSE:
case LUAJIT: case LUAJIT:
globals = org.luaj.vm2.lib.jse.JsePlatform.standardGlobals(); globals = org.luaj.vm2.lib.jse.JsePlatform.debugGlobals();
break; break;
case JME: case JME:
globals = org.luaj.vm2.lib.jme.JmePlatform.standardGlobals(); globals = org.luaj.vm2.lib.jme.JmePlatform.debugGlobals();
break; break;
} }
} }
@@ -179,8 +179,6 @@ public class ScriptDrivenTest extends TestCase implements ResourceFinder {
if ( script == null ) if ( script == null )
fail("Could not load script for test case: " + name); fail("Could not load script for test case: " + name);
try { try {
// Use "stdin" instead of resource name so that output matches
// standard Lua.
switch ( this.platform ) { switch ( this.platform ) {
case LUAJIT: case LUAJIT:
if ( nocompile ) { if ( nocompile ) {
@@ -190,7 +188,7 @@ public class ScriptDrivenTest extends TestCase implements ResourceFinder {
return LuaJC.getInstance().load( script, name, _G); return LuaJC.getInstance().load( script, name, _G);
} }
default: default:
return LoadState.load(script, "=stdin", "bt", _G); return LoadState.load(script, "@"+name+".lua", "bt", _G);
} }
} catch ( Exception e ) { } catch ( Exception e ) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -80,6 +80,7 @@ local echo = function(msg,...)
return ... return ...
end end
local echocr = function(...) local echocr = function(...)
local arg = table.pack(...)
echo('(echocr) first args', table.unpack(arg,1,arg.n)) echo('(echocr) first args', table.unpack(arg,1,arg.n))
local a = arg local a = arg
while true do while true do

View File

@@ -85,11 +85,11 @@ print( 'a.a='..tostring(a.a)..' a.b='..tostring(a.b)..' b.a='..tostring(b.a)..'
local s1,x1,y1 = pcall( debug.getmetatable, a ) local s1,x1,y1 = pcall( debug.getmetatable, a )
local s2,x2,y2 = pcall( debug.setmetatable, a, mt ) local s2,x2,y2 = pcall( debug.setmetatable, a, mt )
print( 'a.a='..tostring(a.a)..' a.b='..tostring(a.b)..' b.a='..tostring(b.a)..' b.b='..tostring(b.b)) print( 'a.a='..tostring(a.a)..' a.b='..tostring(a.b)..' b.a='..tostring(b.a)..' b.b='..tostring(b.b))
local s3,x3,y3 = pcall( debug.getmetatable, a ) local s3,x3,y3 = pcall( debug.getmetatable, a ) print(type(s3), type(x3), type(y3), type(getmetatable(a)))
local s4,x4,y4 = pcall( debug.getmetatable, b ) local s4,x4,y4 = pcall( debug.getmetatable, b ) print(type(s4), type(x4), type(y4), type(getmetatable(b)))
local s5,x5,y5 = pcall( debug.setmetatable, a, nil ) local s5,x5,y5 = pcall( debug.setmetatable, a, nil ) print(type(s5), type(x5), type(y5), type(getmetatable(a)))
print( 'a.a='..tostring(a.a)..' a.b='..tostring(a.b)..' b.a='..tostring(b.a)..' b.b='..tostring(b.b)) print( 'a.a='..tostring(a.a)..' a.b='..tostring(a.b)..' b.a='..tostring(b.a)..' b.b='..tostring(b.b))
local s6,x6,y6 = pcall( debug.getmetatable, a ) local s6,x6,y6 = pcall( debug.getmetatable, a ) print(type(s6), type(x6), type(y6), type(getmetatable(a)))
if not s1 then print( 's1 error', x1 ) end if not s1 then print( 's1 error', x1 ) end
if not s2 then print( 's2 error', x2 ) end if not s2 then print( 's2 error', x2 ) end
if not s3 then print( 's3 error', x3 ) end if not s3 then print( 's3 error', x3 ) end