Mercurial Hosting > luan
comparison core/src/luan/modules/TableLuan.java @ 297:899253043270
remove PackageLuan.load_lib()
git-svn-id: https://luan-java.googlecode.com/svn/trunk@298 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 16 Dec 2014 03:26:43 +0000 |
parents | 8afe9f2fdfec |
children | 7fd9f1b7b878 |
comparison
equal
deleted
inserted
replaced
296:7ea6dfdf81ba | 297:899253043270 |
---|---|
6 import java.util.Arrays; | 6 import java.util.Arrays; |
7 import luan.Luan; | 7 import luan.Luan; |
8 import luan.LuanState; | 8 import luan.LuanState; |
9 import luan.LuanTable; | 9 import luan.LuanTable; |
10 import luan.LuanFunction; | 10 import luan.LuanFunction; |
11 import luan.LuanJavaFunction; | |
12 import luan.LuanElement; | |
13 import luan.LuanException; | 11 import luan.LuanException; |
14 import luan.LuanRuntimeException; | 12 import luan.LuanRuntimeException; |
13 import luan.LuanMethod; | |
15 | 14 |
16 | 15 |
17 public final class TableLuan { | 16 public final class TableLuan { |
18 | |
19 public static final LuanFunction LOADER = new LuanFunction() { | |
20 @Override public Object call(LuanState luan,Object[] args) { | |
21 LuanTable module = Luan.newTable(); | |
22 try { | |
23 add( module, "clone", LuanTable.class ); | |
24 add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class ); | |
25 add( module, "insert", LuanTable.class, Integer.TYPE, Object.class ); | |
26 add( module, "pack", new Object[0].getClass() ); | |
27 add( module, "remove", LuanTable.class, Integer.TYPE ); | |
28 add( module, "sort", LuanState.class, LuanTable.class, LuanFunction.class ); | |
29 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE ); | |
30 add( module, "unpack", LuanTable.class, Integer.class, Integer.class ); | |
31 } catch(NoSuchMethodException e) { | |
32 throw new RuntimeException(e); | |
33 } | |
34 return module; | |
35 } | |
36 }; | |
37 | |
38 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { | |
39 t.put( method, new LuanJavaFunction(TableLuan.class.getMethod(method,parameterTypes),null) ); | |
40 } | |
41 | 17 |
42 public static String concat(LuanState luan,LuanTable list,String sep,Integer i,Integer j) throws LuanException { | 18 public static String concat(LuanState luan,LuanTable list,String sep,Integer i,Integer j) throws LuanException { |
43 int first = i==null ? 1 : i; | 19 int first = i==null ? 1 : i; |
44 int last = j==null ? list.length() : j; | 20 int last = j==null ? list.length() : j; |
45 StringBuilder buf = new StringBuilder(); | 21 StringBuilder buf = new StringBuilder(); |
118 } | 94 } |
119 tbl.put( "n", args.length ); | 95 tbl.put( "n", args.length ); |
120 return tbl; | 96 return tbl; |
121 } | 97 } |
122 | 98 |
123 public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) { | 99 @LuanMethod public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) { |
124 int from = iFrom!=null ? iFrom : 1; | 100 int from = iFrom!=null ? iFrom : 1; |
125 int to = iTo!=null ? iTo : tbl.length(); | 101 int to = iTo!=null ? iTo : tbl.length(); |
126 List<Object> list = new ArrayList<Object>(); | 102 List<Object> list = new ArrayList<Object>(); |
127 for( int i=from; i<=to; i++ ) { | 103 for( int i=from; i<=to; i++ ) { |
128 list.add( tbl.get(i) ); | 104 list.add( tbl.get(i) ); |