changeset 705:52ecb629a634

add to_uri_string()
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 17 May 2016 16:42:47 -0600
parents 90c89138c234
children 30c87c859277
files core/src/luan/modules/IoLuan.java
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/modules/IoLuan.java	Fri May 13 17:13:13 2016 -0600
+++ b/core/src/luan/modules/IoLuan.java	Tue May 17 16:42:47 2016 -0600
@@ -168,6 +168,7 @@
 	public static abstract class LuanIn {
 		abstract InputStream inputStream() throws IOException;
 		public abstract String to_string();
+		public abstract String to_uri_string();
 
 		public Reader reader() throws IOException {
 			return new InputStreamReader(inputStream());
@@ -212,6 +213,9 @@
 				tbl.rawPut( "to_string", new LuanJavaFunction(
 					LuanIn.class.getMethod( "to_string" ), this
 				) );
+				tbl.rawPut( "to_uri_string", new LuanJavaFunction(
+					LuanIn.class.getMethod( "to_uri_string" ), this
+				) );
 				tbl.rawPut( "read_text", new LuanJavaFunction(
 					LuanIn.class.getMethod( "read_text" ), this
 				) );
@@ -244,6 +248,10 @@
 			return "<stdin>";
 		}
 
+		@Override public String to_uri_string() {
+			return "stdin:";
+		}
+
 		@Override public String read_text() throws IOException {
 			return Utils.readAll(new InputStreamReader(System.in));
 		}
@@ -327,6 +335,10 @@
 			return "<null>";
 		}
 
+		@Override public String to_uri_string() {
+			return "null:";
+		}
+
 	};
 
 	public static final class LuanString extends LuanIO {
@@ -348,6 +360,10 @@
 			return "<string>";
 		}
 
+		@Override public String to_uri_string() {
+			return "string:" + s;
+		}
+
 		@Override public Reader reader() {
 			return new StringReader(s);
 		}
@@ -393,6 +409,10 @@
 			return url.toString();
 		}
 
+		@Override public String to_uri_string() {
+			return url.toString();
+		}
+
 		public String post(String postS) throws IOException {
 			return new UrlCall(url).post(postS);
 		}
@@ -434,6 +454,10 @@
 			return file.toString();
 		}
 
+		@Override public String to_uri_string() {
+			return "file:" + file.toString();
+		}
+
 		public LuanTable child(LuanState luan,String name) throws LuanException {
 			return new LuanFile(luan,new File(file,name)).table();
 		}
@@ -643,6 +667,10 @@
 		@Override public String to_string() {
 			return socket.toString();
 		}
+
+		@Override public String to_uri_string() {
+			throw new UnsupportedOperationException();
+		}
 	}
 
 	public static LuanTable socket(String name) throws LuanException, IOException {