Mercurial Hosting > luan
comparison src/luan/lib/PackageLib.java @ 124:f537ff5e511d
minor cleanup
git-svn-id: https://luan-java.googlecode.com/svn/trunk@125 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 06 Jun 2014 03:41:04 +0000 |
parents | d7be9b3abf1a |
children | 0cd559a16758 |
comparison
equal
deleted
inserted
replaced
123:d7be9b3abf1a | 124:f537ff5e511d |
---|---|
14 import luan.LuanException; | 14 import luan.LuanException; |
15 | 15 |
16 | 16 |
17 public final class PackageLib { | 17 public final class PackageLib { |
18 | 18 |
19 public static final String NAME = "Package"; | 19 public static void load(LuanState luan) throws LuanException { |
20 luan.load("Package",LOADER); | |
21 } | |
20 | 22 |
21 public static final LuanFunction LOADER = new LuanFunction() { | 23 public static final LuanFunction LOADER = new LuanFunction() { |
22 @Override public Object call(LuanState luan,Object[] args) { | 24 @Override public Object call(LuanState luan,Object[] args) { |
23 LuanTable module = new LuanTable(); | 25 LuanTable module = new LuanTable(); |
24 LuanTable global = luan.global(); | 26 LuanTable global = luan.global(); |
25 module.put("loaded",luan.loaded()); | 27 module.put("loaded",luan.loaded()); |
26 module.put("preload",luan.preload()); | 28 module.put("preload",luan.preload()); |
27 module.put("path","?.luan"); | 29 module.put("path","?.luan"); |
28 try { | 30 try { |
29 global.put("require",require); | 31 add( global, "require", LuanState.class, String.class ); |
30 add( module, "search_path", String.class, String.class ); | 32 add( module, "search_path", String.class, String.class ); |
31 } catch(NoSuchMethodException e) { | 33 } catch(NoSuchMethodException e) { |
32 throw new RuntimeException(e); | 34 throw new RuntimeException(e); |
33 } | 35 } |
34 LuanTable searchers = luan.searchers(); | 36 LuanTable searchers = luan.searchers(); |
37 searchers.add(javaFileSearcher); | 39 searchers.add(javaFileSearcher); |
38 module.put("searchers",searchers); | 40 module.put("searchers",searchers); |
39 return module; | 41 return module; |
40 } | 42 } |
41 }; | 43 }; |
42 | |
43 public static final LuanFunction require; | |
44 static { | |
45 try { | |
46 require = new LuanJavaFunction(PackageLib.class.getMethod("require", LuanState.class, String.class),null); | |
47 } catch(NoSuchMethodException e) { | |
48 throw new RuntimeException(e); | |
49 } | |
50 } | |
51 | 44 |
52 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { | 45 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { |
53 t.put( method, new LuanJavaFunction(PackageLib.class.getMethod(method,parameterTypes),null) ); | 46 t.put( method, new LuanJavaFunction(PackageLib.class.getMethod(method,parameterTypes),null) ); |
54 } | 47 } |
55 | 48 |