changeset 1316:11d3640e739d

load_file returns nil for missing file
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 31 Jan 2019 04:26:23 -0700
parents 5763597ca5c0
children c286c1e36b81
files src/luan/modules/BasicLuan.java src/luan/modules/Luan.luan website/src/manual.html.luan
diffstat 3 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
diff -r 5763597ca5c0 -r 11d3640e739d src/luan/modules/BasicLuan.java
--- a/src/luan/modules/BasicLuan.java	Wed Jan 30 01:21:49 2019 -0700
+++ b/src/luan/modules/BasicLuan.java	Thu Jan 31 04:26:23 2019 -0700
@@ -39,7 +39,7 @@
 		}
 		String src = PackageLuan.read(luan,fileName);
 		if( src == null )
-			throw new LuanException("file '"+fileName+"' not found" );
+			return null;
 		return load(src,fileName,null);
 	}
 
diff -r 5763597ca5c0 -r 11d3640e739d src/luan/modules/Luan.luan
--- a/src/luan/modules/Luan.luan	Wed Jan 30 01:21:49 2019 -0700
+++ b/src/luan/modules/Luan.luan	Thu Jan 31 04:26:23 2019 -0700
@@ -4,7 +4,8 @@
 
 local Luan = {}
 
-Luan.error = Boot.error
+local error = Boot.error
+Luan.error = error
 Luan.get_metatable = BasicLuan.get_metatable
 Luan.hash_code = BasicLuan.hash_code
 Luan.ipairs = BasicLuan.ipairs
@@ -26,7 +27,8 @@
 Luan.values = BasicLuan.values
 
 function Luan.do_file(uri)
-	return Luan.load_file(uri)()
+	local fn = Luan.load_file(uri) or error("file '"..uri.."' not found")
+	return fn()
 end
 
 Luan.VERSION = Luan.do_file "classpath:luan/version.luan"
diff -r 5763597ca5c0 -r 11d3640e739d website/src/manual.html.luan
--- a/website/src/manual.html.luan	Wed Jan 30 01:21:49 2019 -0700
+++ b/website/src/manual.html.luan	Thu Jan 31 04:26:23 2019 -0700
@@ -1817,7 +1817,8 @@
 
 <pre>
 	function Luan.do_file(uri)
-		return <a href="#Luan.load_file">Luan.load_file</a>(uri)()
+		local fn = <a href="#Luan.load_file">Luan.load_file</a>(uri) or <a href="#Luan.error">Luan.error</a>("file '"..uri.."' not found")
+		return fn()
 	end
 </pre>
 
@@ -1930,7 +1931,9 @@
 	function Luan.load_file(file_uri)
 		file_uri = file_uri or "stdin:"
 		local f = Io.uri(file_uri)
-		f.exists() or <a href="#Luan.error">Luan.error</a>("file '"..file_uri.."' not found")
+		if not f.exists() then
+			return nil
+		end
 		return <a href="#Luan.load">Luan.load</a>( f.read_text(), file_uri )
 	end
 </pre>