Mercurial Hosting > luan
comparison core/src/luan/modules/PackageLuan.java @ 260:f1f7d8c7e94e
add Io.protocols
git-svn-id: https://luan-java.googlecode.com/svn/trunk@261 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 28 Oct 2014 23:25:13 +0000 |
parents | f9b201530b85 |
children | 9e0d4452e649 |
comparison
equal
deleted
inserted
replaced
259:f9b201530b85 | 260:f1f7d8c7e94e |
---|---|
25 module.put( "jpath", jpath ); | 25 module.put( "jpath", jpath ); |
26 try { | 26 try { |
27 module.put("require",requireFn); | 27 module.put("require",requireFn); |
28 add( module, "load", LuanState.class, String.class ); | 28 add( module, "load", LuanState.class, String.class ); |
29 add( module, "load_lib", LuanState.class, String.class ); | 29 add( module, "load_lib", LuanState.class, String.class ); |
30 add( module, "search_path", String.class, String.class ); | 30 add( module, "search_path", LuanState.class, String.class, String.class ); |
31 add( module, "search", LuanState.class, String.class ); | 31 add( module, "search", LuanState.class, String.class ); |
32 } catch(NoSuchMethodException e) { | 32 } catch(NoSuchMethodException e) { |
33 throw new RuntimeException(e); | 33 throw new RuntimeException(e); |
34 } | 34 } |
35 module.put( "searchers", searchers(luan) ); | 35 module.put( "searchers", searchers(luan) ); |
114 return a; | 114 return a; |
115 } | 115 } |
116 return null; | 116 return null; |
117 } | 117 } |
118 | 118 |
119 public static String search_path(String name,String path) { | 119 public static String search_path(LuanState luan,String name,String path) throws LuanException { |
120 for( String s : path.split(";") ) { | 120 for( String s : path.split(";") ) { |
121 String file = s.replaceAll("\\?",name); | 121 String file = s.replaceAll("\\?",name); |
122 if( Utils.exists(file) ) | 122 if( file.indexOf(':') > 0 && IoLuan.get(luan,file) != null ) |
123 return file; | 123 return file; |
124 } | 124 } |
125 return null; | 125 return null; |
126 } | 126 } |
127 | 127 |
132 return fn.call(luan,args); | 132 return fn.call(luan,args); |
133 } | 133 } |
134 }; | 134 }; |
135 | 135 |
136 public static final LuanFunction fileSearcher = new LuanFunction() { | 136 public static final LuanFunction fileSearcher = new LuanFunction() { |
137 @Override public Object[] call(LuanState luan,Object[] args) { | 137 @Override public Object[] call(LuanState luan,Object[] args) throws LuanException { |
138 String modName = (String)args[0]; | 138 String modName = (String)args[0]; |
139 String path = (String)pkg(luan,"path"); | 139 String path = (String)pkg(luan,"path"); |
140 if( path==null ) | 140 if( path==null ) |
141 return LuanFunction.NOTHING; | 141 return LuanFunction.NOTHING; |
142 String file = search_path(modName,path); | 142 String file = search_path(luan,modName,path); |
143 return file==null ? LuanFunction.NOTHING : new Object[]{fileLoader,file}; | 143 return file==null ? LuanFunction.NOTHING : new Object[]{fileLoader,file}; |
144 } | 144 } |
145 }; | 145 }; |
146 | 146 |
147 | 147 |