comparison src/luan/lib/TableLib.java @ 73:f86e4f77ef32

add package module git-svn-id: https://luan-java.googlecode.com/svn/trunk@74 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 12 Feb 2013 09:46:45 +0000
parents 8ede219cd111
children f003338d503b
comparison
equal deleted inserted replaced
72:cd9dbd7477ca 73:f86e4f77ef32
12 import luan.LuanException; 12 import luan.LuanException;
13 13
14 14
15 public final class TableLib { 15 public final class TableLib {
16 16
17 public static void register(LuanState luan) { 17 public static final String NAME = "table";
18 LuanTable module = new LuanTable(); 18
19 LuanTable global = luan.global(); 19 public static final LuanFunction LOADER = new LuanFunction() {
20 global.put("table",module); 20 public Object[] call(LuanState luan,Object[] args) throws LuanException {
21 try { 21 LuanTable module = new LuanTable();
22 add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class ); 22 LuanTable global = luan.global;
23 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class ); 23 global.put(NAME,module);
24 add( module, "pack", new Object[0].getClass() ); 24 try {
25 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE ); 25 add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class );
26 add( module, "sort", LuanState.class, LuanTable.class, LuanFunction.class ); 26 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class );
27 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE ); 27 add( module, "pack", new Object[0].getClass() );
28 add( module, "unpack", LuanTable.class ); 28 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE );
29 } catch(NoSuchMethodException e) { 29 add( module, "sort", LuanState.class, LuanTable.class, LuanFunction.class );
30 throw new RuntimeException(e); 30 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE );
31 add( module, "unpack", LuanTable.class );
32 } catch(NoSuchMethodException e) {
33 throw new RuntimeException(e);
34 }
35 return LuanFunction.EMPTY_RTN;
31 } 36 }
32 } 37 };
33 38
34 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { 39 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
35 t.put( method, new LuanJavaFunction(TableLib.class.getMethod(method,parameterTypes),null) ); 40 t.put( method, new LuanJavaFunction(TableLib.class.getMethod(method,parameterTypes),null) );
36 } 41 }
37 42