Improve error reporting.

This commit is contained in:
James Roseborough
2010-05-10 00:07:54 +00:00
parent 5eb1ef1079
commit 82e9d89115
3 changed files with 9 additions and 7 deletions

View File

@@ -161,11 +161,11 @@ public class LuaValue extends Varargs {
// errors
public static LuaValue error(String message) { throw new LuaError(message); }
public static LuaValue error(int iarg, String message) { throw new LuaError("arg "+iarg+": "+message); }
public static LuaValue error(int iarg, String message) { throw new LuaError("bad argument #"+iarg+": "+message); }
public static void assert_(boolean b,String msg) { if(!b) throw new LuaError(msg); }
public static void argerror(int i,String msg) { throw new LuaError("arg "+i+": "+msg); }
public static void argerror(int iarg,String msg) { throw new LuaError("bad argument #"+iarg+": "+msg); }
protected LuaValue typerror(String expected) { throw new LuaError(expected+" expected, got "+typename()); }
protected LuaValue typerror(int iarg, String expected) { throw new LuaError("arg "+iarg+": "+expected+" expected, got "+typename()); }
protected LuaValue typerror(int iarg, String expected) { throw new LuaError("bad argument #"+iarg+": "+expected+" expected, got "+typename()); }
protected LuaValue unimplemented(String fun) { throw new LuaError("'"+fun+"' not implemented for "+typename()); }
protected LuaValue aritherror() { throw new LuaError("attempt to perform arithmetic on "+typename()); }
protected LuaValue aritherror(String fun) { throw new LuaError("attempt to perform arithmetic '"+fun+"' on "+typename()); }

View File

@@ -153,19 +153,20 @@ public class BaseLib extends OneArgFunction implements ResourceFinder {
public LuaValue call(LuaValue arg1, LuaValue arg2) {
switch ( opcode ) {
case 0: // "collectgarbage", // ( opt [,arg] ) -> value
String s = arg1.optjstring("collect");
String s = arg1.checkjstring();
int result = 0;
if ( "collect".equals(s) ) {
System.gc();
return ZERO;
}
else if ( "count".equals(s) ) {
} else if ( "count".equals(s) ) {
Runtime rt = Runtime.getRuntime();
long used = rt.totalMemory() - rt.freeMemory();
return valueOf(used/1024.);
} else if ( "step".equals(s) ) {
System.gc();
return LuaValue.TRUE;
} else {
this.argerror(1, "gc op");
}
return NIL;
case 1: // "error", // ( message [,level] ) -> ERR

View File

@@ -12,7 +12,8 @@ checkallerrors('assert',{{nil,false,n=2},{'message'}},'message')
-- collectgarbage
banner('collectgarbage')
checkallpass('collectgarbage',{{'collect','count'}},true)
checkallerrors('collectgarbage',{notanil},'bad argument #1')
checkallerrors('collectgarbage',{{astring, anumber}},'bad argument #1')
checkallerrors('collectgarbage',{{aboolean, atable, afunction, athread}},'string expected')
-- dofile
banner('dofile')