static final class TableLibV extends VarArgFunction {
public Varargs invoke(Varargs args) {
switch ( opcode ) {
case 0: { // "remove" (table [, pos]) -> removed-ele
LuaTable table = args.checktable(1);
int pos = args.narg()>1? args.checkint(2): 0;
return table.remove(pos);
}
case 1: { // "concat" (table [, sep [, i [, j]]]) -> string
LuaTable table = args.checktable(1);
return table.concat(
args.optstring(2,LuaValue.EMPTYSTRING),
args.optint(3,1),
args.isvalue(4)? args.checkint(4): table.length() );
}
case 2: { // "insert" (table, [pos,] value) -> prev-ele
final LuaTable table = args.checktable(1);
final int pos = args.narg()>2? args.checkint(2): 0;
final LuaValue value = args.arg( args.narg()>2? 3: 2 );
table.insert( pos, value );
return NONE;
}
case 3: { // "sort" (table [, comp]) -> void
LuaTable table = args.checktable(1);
LuaValue compare = (args.isnoneornil(2)? NIL: args.checkfunction(2));
table.sort( compare );
return NONE;
}
case 4: { // (table, func) -> void
return args.checktable(1).foreach( args.checkfunction(2) );
}