comparison src/luan/lib/TableLib.java @ 74:f003338d503b

improve package lib git-svn-id: https://luan-java.googlecode.com/svn/trunk@75 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 13 Feb 2013 06:27:56 +0000
parents f86e4f77ef32
children 97b03fc807ad
comparison
equal deleted inserted replaced
73:f86e4f77ef32 74:f003338d503b
18 18
19 public static final LuanFunction LOADER = new LuanFunction() { 19 public static final LuanFunction LOADER = new LuanFunction() {
20 public Object[] call(LuanState luan,Object[] args) throws LuanException { 20 public Object[] call(LuanState luan,Object[] args) throws LuanException {
21 LuanTable module = new LuanTable(); 21 LuanTable module = new LuanTable();
22 LuanTable global = luan.global; 22 LuanTable global = luan.global;
23 global.put(NAME,module);
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() );
28 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE ); 27 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE );
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 return LuanFunction.EMPTY_RTN; 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) );