comparison core/src/luan/modules/PackageLuan.java @ 301:a6bf8ff720f8

add java security git-svn-id: https://luan-java.googlecode.com/svn/trunk@302 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 17 Dec 2014 12:35:57 +0000
parents a74559240b4f
children d34be4588556
comparison
equal deleted inserted replaced
300:9fb523472035 301:a6bf8ff720f8
39 throw luan.exception( "module '"+modName+"' not found" ); 39 throw luan.exception( "module '"+modName+"' not found" );
40 return mod; 40 return mod;
41 } 41 }
42 42
43 public static Object load(LuanState luan,String modName) throws LuanException { 43 public static Object load(LuanState luan,String modName) throws LuanException {
44 if( modName.startsWith("java:") )
45 return JavaLuan.load(luan,modName.substring(5));
46 LuanTable loaded = loaded(luan); 44 LuanTable loaded = loaded(luan);
47 Object mod = loaded.get(modName); 45 Object mod = loaded.get(modName);
48 if( mod == null ) { 46 if( mod == null ) {
49 String src = read(luan,modName+".luan"); 47 if( modName.startsWith("java:") ) {
50 if( src == null ) 48 mod = JavaLuan.load(luan,modName.substring(5));
51 return null; 49 } else {
52 LuanFunction loader = BasicLuan.load(luan,src,modName,null,false); 50 String src = read(luan,modName+".luan");
53 mod = Luan.first(luan.call(loader,"<require \""+modName+"\">",new Object[]{modName})); 51 if( src == null )
52 return null;
53 LuanFunction loader = BasicLuan.load(luan,src,modName,null,false);
54 mod = Luan.first(
55 luan.call(loader,"<require \""+modName+"\">",new Object[]{modName})
56 );
57 }
54 if( mod != null ) { 58 if( mod != null ) {
55 loaded.put(modName,mod); 59 loaded.put(modName,mod);
56 } else { 60 } else {
57 mod = loaded.get(modName); 61 mod = loaded.get(modName);
58 if( mod==null ) { 62 if( mod==null ) {
66 70
67 static String read(LuanState luan,String uri) throws LuanException { 71 static String read(LuanState luan,String uri) throws LuanException {
68 LuanTable t = IoLuan.Uri(luan,uri); 72 LuanTable t = IoLuan.Uri(luan,uri);
69 if( t == null ) 73 if( t == null )
70 return null; 74 return null;
75 LuanFunction existsFn = (LuanFunction)t.get("exists");
76 boolean exists = (Boolean)Luan.first(luan.call(existsFn));
77 if( !exists )
78 return null;
71 LuanFunction reader = (LuanFunction)t.get("read_text"); 79 LuanFunction reader = (LuanFunction)t.get("read_text");
72 return (String)Luan.first(luan.call(reader)); 80 return (String)Luan.first(luan.call(reader));
73 } 81 }
74 82
75 } 83 }