Improve error messages for lib table.

This commit is contained in:
Enyby
2019-10-20 07:07:17 +03:00
parent 5fe0a3950d
commit c71f277697
2 changed files with 14 additions and 11 deletions

View File

@@ -74,12 +74,6 @@ public class TableLib extends TwoArgFunction {
return NIL;
}
static class TableLibFunction extends LibFunction {
public LuaValue call() {
return argerror(1, "table expected, got no value");
}
}
// "concat" (table [, sep [, i [, j]]]) -> string
static class concat extends TableLibFunction {
public LuaValue call(LuaValue list) {
@@ -104,12 +98,12 @@ public class TableLib extends TwoArgFunction {
return argerror(2, "value expected");
}
case 2: {
LuaTable table = args.arg1().checktable();
LuaTable table = args.checktable(1);
table.insert(table.length()+1,args.arg(2));
return NONE;
}
default: {
args.arg1().checktable().insert(args.checkint(2),args.arg(3));
args.checktable(1).insert(args.checkint(2),args.arg(3));
return NONE;
}
}
@@ -128,15 +122,15 @@ public class TableLib extends TwoArgFunction {
// "remove" (table [, pos]) -> removed-ele
static class remove extends VarArgFunction {
public Varargs invoke(Varargs args) {
return args.arg1().checktable().remove(args.optint(2, 0));
return args.checktable(1).remove(args.optint(2, 0));
}
}
// "sort" (table [, comp])
static class sort extends VarArgFunction {
public Varargs invoke(Varargs args) {
args.arg1().checktable().sort(
args.arg(2).isnil()? NIL: args.arg(2).checkfunction());
args.checktable(1).sort(
args.isnil(2)? NIL: args.checkfunction(2));
return NONE;
}
}

View File

@@ -0,0 +1,9 @@
package org.luaj.vm2.lib;
import org.luaj.vm2.LuaValue;
class TableLibFunction extends LibFunction {
public LuaValue call() {
return argerror(1, "table expected, got no value");
}
}