Mercurial Hosting > luan
comparison src/luan/lib/TableLib.java @ 108:3c404a296995
make Package module more standard;
return _ENV by default;
add "import" statement;
git-svn-id: https://luan-java.googlecode.com/svn/trunk@109 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 23 May 2014 03:21:54 +0000 |
parents | b1e87f1bcc13 |
children | f5af13062b10 |
comparison
equal
deleted
inserted
replaced
107:dbf459397217 | 108:3c404a296995 |
---|---|
5 import java.util.Arrays; | 5 import java.util.Arrays; |
6 import luan.Luan; | 6 import luan.Luan; |
7 import luan.LuanState; | 7 import luan.LuanState; |
8 import luan.LuanTable; | 8 import luan.LuanTable; |
9 import luan.LuanFunction; | 9 import luan.LuanFunction; |
10 import luan.LuanLoader; | |
11 import luan.LuanJavaFunction; | 10 import luan.LuanJavaFunction; |
12 import luan.LuanElement; | 11 import luan.LuanElement; |
13 import luan.LuanException; | 12 import luan.LuanException; |
14 import luan.LuanRuntimeException; | 13 import luan.LuanRuntimeException; |
15 | 14 |
16 | 15 |
17 public final class TableLib { | 16 public final class TableLib { |
18 | 17 |
19 public static final String NAME = "Table"; | 18 public static final String NAME = "Table"; |
20 | 19 |
21 public static final LuanLoader LOADER = new LuanLoader() { | 20 public static final LuanFunction LOADER = new LuanFunction() { |
22 @Override protected void load(LuanState luan) { | 21 @Override public Object[] call(LuanState luan,Object[] args) { |
23 LuanTable module = new LuanTable(); | 22 LuanTable module = new LuanTable(); |
24 try { | 23 try { |
25 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 ); |
26 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class ); | 25 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class ); |
27 add( module, "pack", new Object[0].getClass() ); | 26 add( module, "pack", new Object[0].getClass() ); |
30 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE ); | 29 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE ); |
31 add( module, "unpack", LuanTable.class ); | 30 add( module, "unpack", LuanTable.class ); |
32 } catch(NoSuchMethodException e) { | 31 } catch(NoSuchMethodException e) { |
33 throw new RuntimeException(e); | 32 throw new RuntimeException(e); |
34 } | 33 } |
35 luan.loaded().put(NAME,module); | 34 return new Object[]{module}; |
36 } | 35 } |
37 }; | 36 }; |
38 | 37 |
39 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 { |
40 t.put( method, new LuanJavaFunction(TableLib.class.getMethod(method,parameterTypes),null) ); | 39 t.put( method, new LuanJavaFunction(TableLib.class.getMethod(method,parameterTypes),null) ); |