Mercurial Hosting > luan
comparison src/luan/lib/PackageLib.java @ 141:c2ee8a717b73
move loading of standard modules to luan
git-svn-id: https://luan-java.googlecode.com/svn/trunk@142 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 13 Jun 2014 16:37:49 +0000 |
parents | 06159094b802 |
children | 05f8c21160ef |
comparison
equal
deleted
inserted
replaced
140:f4ce03ff6b2f | 141:c2ee8a717b73 |
---|---|
26 module.put("loaded",luan.loaded()); | 26 module.put("loaded",luan.loaded()); |
27 module.put("preload",luan.preload()); | 27 module.put("preload",luan.preload()); |
28 module.put("path","?.luan"); | 28 module.put("path","?.luan"); |
29 try { | 29 try { |
30 add( global, "require", LuanState.class, String.class ); | 30 add( global, "require", LuanState.class, String.class ); |
31 add( module, "get_loader", String.class ); | |
31 add( module, "search_path", String.class, String.class ); | 32 add( module, "search_path", String.class, String.class ); |
32 } catch(NoSuchMethodException e) { | 33 } catch(NoSuchMethodException e) { |
33 throw new RuntimeException(e); | 34 throw new RuntimeException(e); |
34 } | 35 } |
35 LuanTable searchers = luan.searchers(); | 36 LuanTable searchers = luan.searchers(); |
151 } | 152 } |
152 return LuanFunction.NOTHING; | 153 return LuanFunction.NOTHING; |
153 } | 154 } |
154 }; | 155 }; |
155 | 156 |
157 | |
158 public static LuanFunction get_loader(String path) | |
159 throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException | |
160 { | |
161 int i = path.lastIndexOf('.'); | |
162 String clsPath = path.substring(0,i); | |
163 String fld = path.substring(i+1); | |
164 Class cls = Class.forName(clsPath); | |
165 return (LuanFunction)cls.getField(fld).get(null); | |
166 } | |
167 | |
156 } | 168 } |