comparison src/luan/lib/TableLib.java @ 112:f5af13062b10

fix previous rev git-svn-id: https://luan-java.googlecode.com/svn/trunk@113 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 23 May 2014 22:52:39 +0000
parents 3c404a296995
children 735708619119
comparison
equal deleted inserted replaced
111:2428ecfed375 112:f5af13062b10
16 public final class TableLib { 16 public final class TableLib {
17 17
18 public static final String NAME = "Table"; 18 public static final String NAME = "Table";
19 19
20 public static final LuanFunction LOADER = new LuanFunction() { 20 public static final LuanFunction LOADER = new LuanFunction() {
21 @Override public Object[] call(LuanState luan,Object[] args) { 21 @Override public Object call(LuanState luan,Object[] args) {
22 LuanTable module = new LuanTable(); 22 LuanTable module = new LuanTable();
23 try { 23 try {
24 add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class ); 24 add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class );
25 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class ); 25 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class );
26 add( module, "pack", new Object[0].getClass() ); 26 add( module, "pack", new Object[0].getClass() );
29 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE ); 29 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE );
30 add( module, "unpack", LuanTable.class ); 30 add( module, "unpack", LuanTable.class );
31 } catch(NoSuchMethodException e) { 31 } catch(NoSuchMethodException e) {
32 throw new RuntimeException(e); 32 throw new RuntimeException(e);
33 } 33 }
34 return new Object[]{module}; 34 return module;
35 } 35 }
36 }; 36 };
37 37
38 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { 38 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
39 t.put( method, new LuanJavaFunction(TableLib.class.getMethod(method,parameterTypes),null) ); 39 t.put( method, new LuanJavaFunction(TableLib.class.getMethod(method,parameterTypes),null) );
91 }; 91 };
92 } else { 92 } else {
93 lt = new LessThan() { 93 lt = new LessThan() {
94 public boolean isLessThan(Object o1,Object o2) { 94 public boolean isLessThan(Object o1,Object o2) {
95 try { 95 try {
96 return Luan.toBoolean(Luan.first(luan.JAVA.call(comp,"comp-arg",o1,o2))); 96 return Luan.toBoolean(Luan.first(luan.JAVA.call(comp,"comp-arg",new Object[]{o1,o2})));
97 } catch(LuanException e) { 97 } catch(LuanException e) {
98 throw new LuanRuntimeException(e); 98 throw new LuanRuntimeException(e);
99 } 99 }
100 } 100 }
101 }; 101 };