Mercurial Hosting > luan
comparison src/luan/lib/TableLib.java @ 86:6db8f286fa6c
_ENV is per module, not global
git-svn-id: https://luan-java.googlecode.com/svn/trunk@87 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 27 Feb 2013 08:03:51 +0000 |
parents | 4bf3d0c0b6b9 |
children | 6ca02b188dba |
comparison
equal
deleted
inserted
replaced
85:b2551f00bc51 | 86:6db8f286fa6c |
---|---|
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; | |
10 import luan.LuanJavaFunction; | 11 import luan.LuanJavaFunction; |
11 import luan.LuanElement; | 12 import luan.LuanElement; |
12 import luan.LuanException; | 13 import luan.LuanException; |
13 import luan.LuanRuntimeException; | 14 import luan.LuanRuntimeException; |
14 | 15 |
15 | 16 |
16 public final class TableLib { | 17 public final class TableLib { |
17 | 18 |
18 public static final String NAME = "table"; | 19 public static final String NAME = "table"; |
19 | 20 |
20 public static final LuanFunction LOADER = new LuanFunction() { | 21 public static final LuanLoader LOADER = new LuanLoader() { |
21 public Object[] call(LuanState luan,Object[] args) throws LuanException { | 22 @Override protected void load(LuanState luan) { |
22 LuanTable module = new LuanTable(); | 23 LuanTable module = new LuanTable(); |
23 LuanTable global = luan.global(); | |
24 try { | 24 try { |
25 add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class ); | 25 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 ); | 26 add( module, "insert", LuanState.class, LuanTable.class, Integer.TYPE, Object.class ); |
27 add( module, "pack", new Object[0].getClass() ); | 27 add( module, "pack", new Object[0].getClass() ); |
28 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE ); | 28 add( module, "remove", LuanState.class, LuanTable.class, Integer.TYPE ); |
30 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE ); | 30 add( module, "sub_list", LuanTable.class, Integer.TYPE, Integer.TYPE ); |
31 add( module, "unpack", LuanTable.class ); | 31 add( module, "unpack", LuanTable.class ); |
32 } catch(NoSuchMethodException e) { | 32 } catch(NoSuchMethodException e) { |
33 throw new RuntimeException(e); | 33 throw new RuntimeException(e); |
34 } | 34 } |
35 return new Object[]{module}; | 35 luan.loaded().put(NAME,module); |
36 } | 36 } |
37 }; | 37 }; |
38 | 38 |
39 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 { |
40 t.put( method, new LuanJavaFunction(TableLib.class.getMethod(method,parameterTypes),null) ); | 40 t.put( method, new LuanJavaFunction(TableLib.class.getMethod(method,parameterTypes),null) ); |