diff core/src/luan/modules/IoLuan.java @ 421:b31d614343e8

add Io.LuanString.text_writer(); improve java related errors; fix to_string;
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 01 May 2015 15:13:14 -0600
parents 23b99a5039b5
children 23a93c118042
line wrap: on
line diff
--- a/core/src/luan/modules/IoLuan.java	Fri May 01 14:23:17 2015 -0600
+++ b/core/src/luan/modules/IoLuan.java	Fri May 01 15:13:14 2015 -0600
@@ -18,6 +18,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
+import java.io.StringWriter;
 import java.io.IOException;
 import java.io.FileNotFoundException;
 import java.net.URL;
@@ -301,14 +302,18 @@
 		}
 	}
 
-	public static final class LuanString extends LuanIn {
-		private final String s;
+	public static final class LuanString extends LuanIO {
+		private String s;
 
 		private LuanString(String s) {
 			this.s = s;
 		}
 
-		@Override InputStream inputStream() throws IOException {
+		@Override InputStream inputStream() {
+			throw new UnsupportedOperationException();
+		}
+
+		@Override OutputStream outputStream() {
 			throw new UnsupportedOperationException();
 		}
 
@@ -327,6 +332,23 @@
 		@Override public boolean exists() {
 			return true;
 		}
+
+		@Override public LuanTable text_writer() throws IOException {
+			LuanWriter luanWriter = new LuanWriter() {
+				private final Writer out = new StringWriter();
+	
+				public void write(LuanState luan,Object... args) throws LuanException, IOException {
+					for( Object obj : args ) {
+						out.write( luan.toString(obj) );
+					}
+				}
+	
+				public void close() throws IOException {
+					s = out.toString();
+				}
+			};
+			return writer(luanWriter);
+		}
 	}
 
 	public static final class LuanUrl extends LuanIn {