comparison core/src/luan/modules/TableLuan.java @ 221:ec016471c6eb

make LuanTable an interface git-svn-id: https://luan-java.googlecode.com/svn/trunk@222 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 17 Jul 2014 07:49:26 +0000
parents 3dcb0f9bee82
children b76fcb72d97d
comparison
equal deleted inserted replaced
220:61afe2a1ce96 221:ec016471c6eb
16 16
17 public final class TableLuan { 17 public final class TableLuan {
18 18
19 public static final LuanFunction LOADER = new LuanFunction() { 19 public static final LuanFunction LOADER = new LuanFunction() {
20 @Override public Object call(LuanState luan,Object[] args) { 20 @Override public Object call(LuanState luan,Object[] args) {
21 LuanTable module = new LuanTable(); 21 LuanTable module = Luan.newTable();
22 try { 22 try {
23 add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class ); 23 add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class );
24 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class ); 24 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class );
25 add( module, "pack", new Object[0].getClass() ); 25 add( module, "pack", new Object[0].getClass() );
26 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE ); 26 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE );
109 throw (LuanException)e.getCause(); 109 throw (LuanException)e.getCause();
110 } 110 }
111 } 111 }
112 112
113 public static LuanTable pack(Object... args) { 113 public static LuanTable pack(Object... args) {
114 return new LuanTable(new ArrayList<Object>(Arrays.asList(args))); 114 LuanTable tbl = Luan.newTable();
115 boolean hasNull = false;
116 for( int i=0; i<args.length; i++ ) {
117 Object v = args[i];
118 if( v==null ) {
119 hasNull = true;
120 } else if( !hasNull ) {
121 tbl.add(v);
122 } else {
123 tbl.put(i+1,v);
124 }
125 }
126 tbl.put( "n", args.length );
127 return tbl;
115 } 128 }
116 129
117 public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) { 130 public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) {
118 int from = iFrom!=null ? iFrom : 1; 131 int from = iFrom!=null ? iFrom : 1;
119 int to = iTo!=null ? iTo : tbl.length(); 132 int to = iTo!=null ? iTo : tbl.length();