changeset 261:715c4a6e1169

simplify Io.stdin git-svn-id: https://luan-java.googlecode.com/svn/trunk@262 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 28 Oct 2014 23:36:29 +0000
parents f1f7d8c7e94e
children 3ccc5205d04d
files core/src/luan/modules/IoLuan.java
diffstat 1 files changed, 20 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
diff -r f1f7d8c7e94e -r 715c4a6e1169 core/src/luan/modules/IoLuan.java
--- a/core/src/luan/modules/IoLuan.java	Tue Oct 28 23:25:13 2014 +0000
+++ b/core/src/luan/modules/IoLuan.java	Tue Oct 28 23:36:29 2014 +0000
@@ -44,20 +44,7 @@
 
 				add( module, "get", LuanState.class, String.class );
 
-				LuanTable stdin = Luan.newTable();
-				stdin.put( "read_text", new LuanJavaFunction(
-					IoLuan.class.getMethod( "stdin_read_text" ), null
-				) );
-				stdin.put( "read_binary", new LuanJavaFunction(
-					IoLuan.class.getMethod( "stdin_read_binary" ), null
-				) );
-				stdin.put( "read_lines", new LuanJavaFunction(
-					IoLuan.class.getMethod( "stdin_read_lines" ), null
-				) );
-				stdin.put( "read_blocks", new LuanJavaFunction(
-					IoLuan.class.getMethod( "stdin_read_blocks", Integer.class ), null
-				) );
-				module.put( "stdin", stdin );
+				module.put( "stdin", stdin.table() );
 
 				add( module, "Socket", String.class, Integer.TYPE );
 				add( module, "socket_server", Integer.TYPE );
@@ -75,23 +62,6 @@
 	}
 
 
-	public static String stdin_read_text() throws IOException {
-		return Utils.readAll(new InputStreamReader(System.in));
-	}
-
-	public static byte[] stdin_read_binary() throws IOException {
-		return Utils.readAll(System.in);
-	}
-
-	public static LuanFunction stdin_read_lines() throws IOException {
-		return lines(new BufferedReader(new InputStreamReader(System.in)));
-	}
-
-	public static LuanFunction stdin_read_blocks(Integer blockSize) throws IOException {
-		int n = blockSize!=null ? blockSize : Utils.bufSize;
-		return blocks(System.in,n);
-	}
-
 	public static String read_console_line(String prompt) throws IOException {
 		if( prompt==null )
 			prompt = "> ";
@@ -266,6 +236,25 @@
 		}
 	}
 
+	private static final LuanIn stdin = new LuanIn() {
+
+		@Override InputStream inputStream() {
+			return System.in;
+		}
+
+		@Override public String to_string() {
+			return "<stdin>";
+		}
+
+		@Override public String read_text() throws IOException {
+			return Utils.readAll(new InputStreamReader(System.in));
+		}
+
+		@Override public byte[] read_binary() throws IOException {
+			return Utils.readAll(System.in);
+		}
+	};
+
 	public static abstract class LuanIO extends LuanIn {
 		abstract OutputStream outputStream() throws IOException;