Mercurial Hosting > luan
comparison src/luan/lib/IoLib.java @ 122:d00f41edbbd6
minor
git-svn-id: https://luan-java.googlecode.com/svn/trunk@123 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 04 Jun 2014 06:15:47 +0000 |
parents | 735708619119 |
children | f537ff5e511d |
comparison
equal
deleted
inserted
replaced
121:cba7ed3f06cc | 122:d00f41edbbd6 |
---|---|
51 ) ); | 51 ) ); |
52 module.put( "stdin", stdin ); | 52 module.put( "stdin", stdin ); |
53 } catch(NoSuchMethodException e) { | 53 } catch(NoSuchMethodException e) { |
54 throw new RuntimeException(e); | 54 throw new RuntimeException(e); |
55 } | 55 } |
56 module.put( "stdout", writer(System.out) ); | 56 module.put( "stdout", textWriter(System.out) ); |
57 module.put( "stderr", writer(System.err) ); | 57 module.put( "stderr", textWriter(System.err) ); |
58 return module; | 58 return module; |
59 } | 59 } |
60 }; | 60 }; |
61 | 61 |
62 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { | 62 private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { |
91 } | 91 } |
92 throw luan.JAVA.exception( "bad argument #1 to 'write' (string or binary expected)" ); | 92 throw luan.JAVA.exception( "bad argument #1 to 'write' (string or binary expected)" ); |
93 } | 93 } |
94 | 94 |
95 public LuanTable text_writer() throws IOException { | 95 public LuanTable text_writer() throws IOException { |
96 return writer(new FileWriter(file)); | 96 return textWriter(new FileWriter(file)); |
97 } | 97 } |
98 | 98 |
99 public LuanTable binary_writer() throws IOException { | 99 public LuanTable binary_writer() throws IOException { |
100 return binaryWriter(new FileOutputStream(file)); | 100 return binaryWriter(new FileOutputStream(file)); |
101 } | 101 } |
233 public interface LuanWriter { | 233 public interface LuanWriter { |
234 public void write(LuanState luan,Object... args) throws LuanException, IOException; | 234 public void write(LuanState luan,Object... args) throws LuanException, IOException; |
235 public void close() throws IOException; | 235 public void close() throws IOException; |
236 } | 236 } |
237 | 237 |
238 public static LuanTable writer(final PrintStream out) { | 238 public static LuanTable textWriter(final PrintStream out) { |
239 LuanWriter luanWriter = new LuanWriter() { | 239 LuanWriter luanWriter = new LuanWriter() { |
240 | 240 |
241 public void write(LuanState luan,Object... args) throws LuanException { | 241 public void write(LuanState luan,Object... args) throws LuanException { |
242 for( Object obj : args ) { | 242 for( Object obj : args ) { |
243 out.print( luan.JAVA.toString(obj) ); | 243 out.print( luan.JAVA.toString(obj) ); |
249 } | 249 } |
250 }; | 250 }; |
251 return writer(luanWriter); | 251 return writer(luanWriter); |
252 } | 252 } |
253 | 253 |
254 public static LuanTable writer(final Writer out) { | 254 public static LuanTable textWriter(final Writer out) { |
255 LuanWriter luanWriter = new LuanWriter() { | 255 LuanWriter luanWriter = new LuanWriter() { |
256 | 256 |
257 public void write(LuanState luan,Object... args) throws LuanException, IOException { | 257 public void write(LuanState luan,Object... args) throws LuanException, IOException { |
258 for( Object obj : args ) { | 258 for( Object obj : args ) { |
259 out.write( luan.JAVA.toString(obj) ); | 259 out.write( luan.JAVA.toString(obj) ); |