changeset 339:673eebd83b74

remove circular package loading
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 31 Mar 2015 00:29:06 -0600
parents f05c631ebaaf
children fb18724521d2
files core/src/luan/modules/PackageLuan.java
diffstat 1 files changed, 5 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
diff -r f05c631ebaaf -r 673eebd83b74 core/src/luan/modules/PackageLuan.java
--- a/core/src/luan/modules/PackageLuan.java	Wed Mar 25 04:29:32 2015 +0000
+++ b/core/src/luan/modules/PackageLuan.java	Tue Mar 31 00:29:06 2015 -0600
@@ -3,8 +3,6 @@
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.Set;
-import java.util.HashSet;
 import luan.Luan;
 import luan.LuanState;
 import luan.LuanTable;
@@ -47,47 +45,18 @@
 		if( mod == null ) {
 			if( modName.startsWith("java:") ) {
 				mod = JavaLuan.load(luan,modName.substring(5));
-				if( mod != null )
-					loaded.put(modName,mod);
 			} else {
 				String src = read(luan,modName+".luan");
 				if( src == null )
 					return null;
 				LuanTable env = Luan.newTable();
 				LuanFunction loader = BasicLuan.load(luan,src,modName,env,false);
-				loaded.put(modName,env);
-				@SuppressWarnings("unchecked")
-				Set<String> loading = (Set<String>)luan.registry().get("Package.loading");
-				boolean top = loading==null;
-				if(top) {
-					loading = new HashSet<String>();
-					luan.registry().put("Package.loading",loading);
-				}
-				loading.add(modName);
-				boolean ok = false;
-				try {
-					mod = Luan.first(
-						luan.call(loader,"<require \""+modName+"\">",new Object[]{modName})
-					);
-					ok = true;
-				} finally {
-					if( !ok ) {
-						if(top) {
-							for( String mn : loading ) {
-								loaded.put(mn,null);
-							}
-						} else {
-							loaded.put(modName,null);
-						}
-					}
-					if(top)
-						luan.registry().put("Package.loading",null);
-				}
-				if( mod != null )
-					loaded.put(modName,mod);
-				else
-					mod = env;
+				Object result = Luan.first(
+					luan.call(loader,"<require \""+modName+"\">",new Object[]{modName})
+				);
+				mod = result!=null ? result : env;
 			}
+			loaded.put(modName,mod);
 		}
 		return mod;
 	}