Mercurial Hosting > luan
diff core/src/luan/modules/PackageLuan.java @ 175:bdbd4740121f
finish web server
git-svn-id: https://luan-java.googlecode.com/svn/trunk@176 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 23 Jun 2014 07:48:17 +0000 |
parents | 3dcb0f9bee82 |
children | cf939124461a |
line wrap: on
line diff
--- a/core/src/luan/modules/PackageLuan.java Mon Jun 23 02:57:50 2014 +0000 +++ b/core/src/luan/modules/PackageLuan.java Mon Jun 23 07:48:17 2014 +0000 @@ -26,6 +26,7 @@ module.put("jpath",jpath); try { add( module, "require", LuanState.class, String.class ); + add( module, "load", LuanState.class, String.class ); add( module, "load_lib", String.class ); add( module, "search_path", String.class, String.class ); add( module, "search", LuanState.class, String.class ); @@ -46,12 +47,19 @@ } public static Object require(LuanState luan,String modName) throws LuanException { + Object mod = load(luan,modName); + if( mod==null ) + throw luan.exception( "module '"+modName+"' not found" ); + return mod; + } + + public static Object load(LuanState luan,String modName) throws LuanException { LuanTable loaded = luan.loaded(); Object mod = loaded.get(modName); if( mod == null ) { Object[] a = search(luan,modName); if( a == null ) - throw luan.exception( "module '"+modName+"' not found" ); + return null; LuanFunction loader = (LuanFunction)a[0]; a[0] = modName; mod = Luan.first(luan.call(loader,"<require \""+modName+"\">",a)); @@ -59,8 +67,10 @@ loaded.put(modName,mod); } else { mod = loaded.get(modName); - if( mod==null ) - loaded.put(modName,true); + if( mod==null ) { + mod = true; + loaded.put(modName,mod); + } } } return mod; @@ -91,7 +101,6 @@ }; public static String search_path(String name,String path) { - name = name.replace('.','/'); for( String s : path.split(";") ) { String file = s.replaceAll("\\?",name); if( Utils.exists(file) ) @@ -139,6 +148,7 @@ public static final LuanFunction javaSearcher = new LuanFunction() { @Override public Object[] call(LuanState luan,Object[] args) { String modName = (String)args[0]; + modName = modName.replace('/','.'); String path = (String)luan.get("Package.jpath"); if( path==null ) path = jpath;