diff --git a/src/core/org/luaj/vm2/LuaValue.java b/src/core/org/luaj/vm2/LuaValue.java index 4dadb235..42d3627a 100644 --- a/src/core/org/luaj/vm2/LuaValue.java +++ b/src/core/org/luaj/vm2/LuaValue.java @@ -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()); } diff --git a/src/core/org/luaj/vm2/lib/BaseLib.java b/src/core/org/luaj/vm2/lib/BaseLib.java index 0e888dad..8e0b40e0 100644 --- a/src/core/org/luaj/vm2/lib/BaseLib.java +++ b/src/core/org/luaj/vm2/lib/BaseLib.java @@ -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 diff --git a/test/lua/errors/baselibargs.lua b/test/lua/errors/baselibargs.lua index 60c07b2f..77ac43e6 100644 --- a/test/lua/errors/baselibargs.lua +++ b/test/lua/errors/baselibargs.lua @@ -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')