comparison core/src/luan/modules/PackageLuan.java @ 207:5aafb5b9f70f

various git-svn-id: https://luan-java.googlecode.com/svn/trunk@208 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 08 Jul 2014 02:04:24 +0000
parents 75750ceb45ee
children 5ba136769034
comparison
equal deleted inserted replaced
206:77365c9fdfe4 207:5aafb5b9f70f
25 module.put( "preload", new LuanTable() ); 25 module.put( "preload", new LuanTable() );
26 module.put( "path", "?.luan;java:luan/modules/?.luan" ); 26 module.put( "path", "?.luan;java:luan/modules/?.luan" );
27 module.put( "jpath", jpath ); 27 module.put( "jpath", jpath );
28 try { 28 try {
29 module.put("require",requireFn); 29 module.put("require",requireFn);
30 add( module, "block_lib", LuanState.class, String.class ); 30 add( module, "block_path", LuanState.class, String.class );
31 add( module, "is_blocked_path", LuanState.class, String.class );
31 add( module, "load", LuanState.class, String.class ); 32 add( module, "load", LuanState.class, String.class );
32 add( module, "load_lib", LuanState.class, String.class ); 33 add( module, "load_lib", LuanState.class, String.class );
33 add( module, "search_path", String.class, String.class ); 34 add( module, "search_path", String.class, String.class );
34 add( module, "search", LuanState.class, String.class ); 35 add( module, "search", LuanState.class, String.class );
35 } catch(NoSuchMethodException e) { 36 } catch(NoSuchMethodException e) {
201 return LuanFunction.NOTHING; 202 return LuanFunction.NOTHING;
202 } 203 }
203 }; 204 };
204 205
205 206
206 public static void block_lib(LuanState luan,String path) { 207 public static void block_path(LuanState luan,String path) {
207 blocked(luan).put(path,true); 208 blocked(luan).put(path,true);
209 }
210
211 public static boolean is_blocked_path(LuanState luan,String path) {
212 return blocked(luan).get(path) != null;
208 } 213 }
209 214
210 public static LuanFunction load_lib(LuanState luan,String path) 215 public static LuanFunction load_lib(LuanState luan,String path)
211 throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, LuanException 216 throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, LuanException
212 { 217 {
213 if( blocked(luan).get(path) != null ) 218 if( is_blocked_path(luan,path) )
214 throw luan.exception(path+" is blocked"); 219 throw luan.exception(path+" is blocked");
215 int i = path.lastIndexOf('.'); 220 int i = path.lastIndexOf('.');
216 String clsPath = path.substring(0,i); 221 String clsPath = path.substring(0,i);
217 String fld = path.substring(i+1); 222 String fld = path.substring(i+1);
218 Class cls = Class.forName(clsPath); 223 Class cls = Class.forName(clsPath);