comparison src/luan/lib/TableLib.java @ 118:735708619119

add Debug.debug() git-svn-id: https://luan-java.googlecode.com/svn/trunk@119 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 01 Jun 2014 07:07:31 +0000
parents f5af13062b10
children f537ff5e511d
comparison
equal deleted inserted replaced
117:e935581cf9fb 118:735708619119
1 package luan.lib; 1 package luan.lib;
2 2
3 import java.util.Comparator; 3 import java.util.Comparator;
4 import java.util.List;
4 import java.util.ArrayList; 5 import java.util.ArrayList;
5 import java.util.Arrays; 6 import java.util.Arrays;
6 import luan.Luan; 7 import luan.Luan;
7 import luan.LuanState; 8 import luan.LuanState;
8 import luan.LuanTable; 9 import luan.LuanTable;
25 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class ); 26 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class );
26 add( module, "pack", new Object[0].getClass() ); 27 add( module, "pack", new Object[0].getClass() );
27 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE ); 28 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE );
28 add( module, "sort", LuanState.class, LuanTable.class, LuanFunction.class ); 29 add( module, "sort", LuanState.class, LuanTable.class, LuanFunction.class );
29 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE ); 30 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE );
30 add( module, "unpack", LuanTable.class ); 31 add( module, "unpack", LuanTable.class, Integer.class, Integer.class );
31 } catch(NoSuchMethodException e) { 32 } catch(NoSuchMethodException e) {
32 throw new RuntimeException(e); 33 throw new RuntimeException(e);
33 } 34 }
34 return module; 35 return module;
35 } 36 }
109 } catch(LuanRuntimeException e) { 110 } catch(LuanRuntimeException e) {
110 throw (LuanException)e.getCause(); 111 throw (LuanException)e.getCause();
111 } 112 }
112 } 113 }
113 114
114 public static LuanTable pack(Object[] args) { 115 public static LuanTable pack(Object... args) {
115 return new LuanTable(new ArrayList<Object>(Arrays.asList(args))); 116 return new LuanTable(new ArrayList<Object>(Arrays.asList(args)));
116 } 117 }
117 118
118 public static Object[] unpack(LuanTable list) { 119 public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) {
119 return list.listToArray(); 120 int from = iFrom!=null ? iFrom : 1;
121 int to = iTo!=null ? iTo : tbl.length();
122 List<Object> list = new ArrayList<Object>();
123 for( int i=from; i<=to; i++ ) {
124 list.add( tbl.get(i) );
125 }
126 return list.toArray();
120 } 127 }
121 128
122 public static LuanTable sub_list(LuanTable list,int from,int to) { 129 public static LuanTable sub_list(LuanTable list,int from,int to) {
123 return list.subList(from,to); 130 return list.subList(from,to);
124 } 131 }