Mercurial Hosting > luan
changeset 590:f050c30952c0
add Io.schemes.null
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 27 Aug 2015 08:35:03 -0600 |
parents | 97c8ae330efe |
children | 790d5de23042 |
files | core/src/luan/modules/IoLuan.java |
diffstat | 1 files changed, 29 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/core/src/luan/modules/IoLuan.java Wed Aug 26 04:38:37 2015 -0600 +++ b/core/src/luan/modules/IoLuan.java Thu Aug 27 08:35:03 2015 -0600 @@ -302,6 +302,30 @@ } } + private static final LuanIO nullIO = new LuanIO() { + private final InputStream in = new InputStream() { + @Override public int read() { + return -1; + } + }; + private final OutputStream out = new OutputStream() { + @Override public void write(int b) {} + }; + + @Override InputStream inputStream() { + return in; + } + + @Override OutputStream outputStream() { + return out; + } + + @Override public String to_string() { + return "<null>"; + } + + }; + public static final class LuanString extends LuanIO { private String s; @@ -487,6 +511,10 @@ } } + public static LuanTable null_() { + return nullIO.table(); + } + public static LuanTable string(LuanState luan,String s) throws LuanException { Utils.checkNotNull(luan,s); return new LuanString(s).table(); @@ -558,6 +586,7 @@ public static LuanTable newSchemes() { LuanTable schemes = new LuanTable(); try { + schemes.rawPut( "null", new LuanJavaFunction(IoLuan.class.getMethod("null_"),null) ); add( schemes, "string", LuanState.class, String.class ); add( schemes, "file", LuanState.class, String.class, Boolean.class ); add( schemes, "classpath", LuanState.class, String.class, Boolean.class );