diff 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
line wrap: on
line diff
--- a/src/luan/lib/TableLib.java	Fri May 30 08:57:24 2014 +0000
+++ b/src/luan/lib/TableLib.java	Sun Jun 01 07:07:31 2014 +0000
@@ -1,6 +1,7 @@
 package luan.lib;
 
 import java.util.Comparator;
+import java.util.List;
 import java.util.ArrayList;
 import java.util.Arrays;
 import luan.Luan;
@@ -27,7 +28,7 @@
 				add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE );
 				add( module, "sort", LuanState.class, LuanTable.class, LuanFunction.class );
 				add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE );
-				add( module, "unpack", LuanTable.class );
+				add( module, "unpack", LuanTable.class, Integer.class, Integer.class );
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
 			}
@@ -111,12 +112,18 @@
 		}
 	}
 
-	public static LuanTable pack(Object[] args) {
+	public static LuanTable pack(Object... args) {
 		return new LuanTable(new ArrayList<Object>(Arrays.asList(args)));
 	}
 
-	public static Object[] unpack(LuanTable list) {
-		return list.listToArray();
+	public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) {
+		int from = iFrom!=null ? iFrom : 1;
+		int to = iTo!=null ? iTo : tbl.length();
+		List<Object> list = new ArrayList<Object>();
+		for( int i=from; i<=to; i++ ) {
+			list.add( tbl.get(i) );
+		}
+		return list.toArray();
 	}
 
 	public static LuanTable sub_list(LuanTable list,int from,int to) {