diff core/src/luan/modules/PackageLuan.java @ 200:9fb218211763

add Package.block(); add LuanException.getFullMessage(); git-svn-id: https://luan-java.googlecode.com/svn/trunk@201 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 03 Jul 2014 22:22:16 +0000
parents be0275bda373
children 75750ceb45ee
line wrap: on
line diff
--- a/core/src/luan/modules/PackageLuan.java	Thu Jul 03 21:37:47 2014 +0000
+++ b/core/src/luan/modules/PackageLuan.java	Thu Jul 03 22:22:16 2014 +0000
@@ -27,8 +27,9 @@
 			module.put("jpath",jpath);
 			try {
 				module.put("require",requireFn);
+				add( module, "block_lib", LuanState.class, String.class );
 				add( module, "load", LuanState.class, String.class );
-				add( module, "load_lib", String.class );
+				add( module, "load_lib", LuanState.class, String.class );
 				add( module, "search_path", String.class, String.class );
 				add( module, "search", LuanState.class, String.class );
 			} catch(NoSuchMethodException e) {
@@ -149,7 +150,7 @@
 		@Override public Object call(LuanState luan,Object[] args) throws LuanException {
 			try {
 				String objName = (String)args[1];
-				LuanFunction fn = load_lib(objName);
+				LuanFunction fn = load_lib(luan,objName);
 				return fn.call(luan,args);
 			} catch(ClassNotFoundException e) {
 				throw new RuntimeException(e);
@@ -162,7 +163,9 @@
 	};
 
 	public static final LuanFunction javaSearcher = new LuanFunction() {
-		@Override public Object[] call(LuanState luan,Object[] args) {
+		@Override public Object[] call(LuanState luan,Object[] args)
+			throws LuanException
+		{
 			String modName = (String)args[0];
 			modName = modName.replace('/','.');
 			String path = (String)luan.get("Package.jpath");
@@ -171,7 +174,7 @@
 			for( String s : path.split(";") ) {
 				String objName = s.replaceAll("\\?",modName);
 				try {
-					load_lib(objName);  // throws exception if not found
+					load_lib(luan,objName);  // throws exception if not found
 					return new Object[]{javaLoader,objName};
 				} catch(ClassNotFoundException e) {
 				} catch(NoSuchFieldException e) {
@@ -183,9 +186,15 @@
 	};
 
 
-	public static LuanFunction load_lib(String path)
-		throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
+	public static void block_lib(LuanState luan,String path) {
+		luan.blocked.add(path);
+	}
+
+	public static LuanFunction load_lib(LuanState luan,String path)
+		throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, LuanException
 	{
+		if( luan.blocked.contains(path) )
+			throw luan.exception(path+" is blocked");
 		int i = path.lastIndexOf('.');
 		String clsPath = path.substring(0,i);
 		String fld = path.substring(i+1);