comparison core/src/luan/modules/TableLuan.java @ 646:cdc70de628b5

simplify LuanException
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 29 Mar 2016 19:58:39 -0600
parents e3d19d525915
children 8e8c30b72e9b
comparison
equal deleted inserted replaced
645:859c0dedc8b6 646:cdc70de628b5
30 buf.append(s); 30 buf.append(s);
31 } 31 }
32 return buf.toString(); 32 return buf.toString();
33 } 33 }
34 34
35 public static void insert(LuanState luan,LuanTable list,int pos,Object value) throws LuanException { 35 public static void insert(LuanTable list,int pos,Object value) throws LuanException {
36 Utils.checkNotNull(luan,list); 36 Utils.checkNotNull(list);
37 if( list.getMetatable() != null ) 37 if( list.getMetatable() != null )
38 throw new LuanException(luan,"can't insert into a table with a metatable"); 38 throw new LuanException("can't insert into a table with a metatable");
39 list.rawInsert(pos,value); 39 list.rawInsert(pos,value);
40 } 40 }
41 41
42 public static Object remove(LuanState luan,LuanTable list,int pos) throws LuanException { 42 public static Object remove(LuanTable list,int pos) throws LuanException {
43 if( list.getMetatable() != null ) 43 if( list.getMetatable() != null )
44 throw new LuanException(luan,"can't remove from a table with a metatable"); 44 throw new LuanException("can't remove from a table with a metatable");
45 return list.rawRemove(pos); 45 return list.rawRemove(pos);
46 } 46 }
47 47
48 private static interface LessThan { 48 private static interface LessThan {
49 public boolean isLessThan(Object o1,Object o2); 49 public boolean isLessThan(Object o1,Object o2);
50 } 50 }
51 51
52 public static void sort(final LuanState luan,LuanTable list,final LuanFunction comp) throws LuanException { 52 public static void sort(final LuanState luan,LuanTable list,final LuanFunction comp) throws LuanException {
53 if( list.getMetatable() != null ) 53 if( list.getMetatable() != null )
54 throw new LuanException(luan,"can't sort a table with a metatable"); 54 throw new LuanException("can't sort a table with a metatable");
55 final LessThan lt; 55 final LessThan lt;
56 if( comp==null ) { 56 if( comp==null ) {
57 lt = new LessThan() { 57 lt = new LessThan() {
58 public boolean isLessThan(Object o1,Object o2) { 58 public boolean isLessThan(Object o1,Object o2) {
59 try { 59 try {