Mercurial Hosting > luan
comparison core/src/luan/modules/BasicLuan.java @ 265:454a486d9c19
allow IO on files that don't exist
git-svn-id: https://luan-java.googlecode.com/svn/trunk@266 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 29 Oct 2014 16:26:42 +0000 |
parents | 9e0d4452e649 |
children | 9a0cc6d9b27b |
comparison
equal
deleted
inserted
replaced
264:9e0d4452e649 | 265:454a486d9c19 |
---|---|
72 allowExpr = false; | 72 allowExpr = false; |
73 return LuanCompiler.compile(luan,new LuanSource(sourceName,text),env,allowExpr); | 73 return LuanCompiler.compile(luan,new LuanSource(sourceName,text),env,allowExpr); |
74 } | 74 } |
75 | 75 |
76 public static LuanFunction load_file(LuanState luan,String fileName) throws LuanException { | 76 public static LuanFunction load_file(LuanState luan,String fileName) throws LuanException { |
77 LuanTable t = fileName==null ? IoLuan.stdin.table() : IoLuan.get(luan,fileName,false); | 77 if( fileName == null ) |
78 if( t == null ) | 78 fileName = "stdin:"; |
79 LuanFunction fn = PackageLuan.loader(luan,fileName,false); | |
80 if( fn == null ) | |
79 throw luan.exception( "file '"+fileName+"' not found" ); | 81 throw luan.exception( "file '"+fileName+"' not found" ); |
80 LuanFunction loader = (LuanFunction)t.get("loader"); | 82 return fn; |
81 return (LuanFunction)Luan.first(luan.call(loader,new Object[]{fileName})); | |
82 } | 83 } |
83 | 84 |
84 public static Object do_file(LuanState luan,String fileName) throws LuanException { | 85 public static Object do_file(LuanState luan,String fileName) throws LuanException { |
85 LuanFunction fn = load_file(luan,fileName); | 86 LuanFunction fn = load_file(luan,fileName); |
86 return luan.call(fn); | 87 return luan.call(fn); |