diff core/src/luan/modules/IoLuan.java @ 646:cdc70de628b5

simplify LuanException
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 29 Mar 2016 19:58:39 -0600
parents 8bd98da6991a
children ca169567ce07
line wrap: on
line diff
--- a/core/src/luan/modules/IoLuan.java	Tue Mar 29 18:09:51 2016 -0600
+++ b/core/src/luan/modules/IoLuan.java	Tue Mar 29 19:58:39 2016 -0600
@@ -122,7 +122,7 @@
 				try {
 					if( args.length > 0 ) {
 						if( args.length > 1 || !"close".equals(args[0]) )
-							throw new LuanException(luan, "the only argument allowed is 'close'" );
+							throw new LuanException( "the only argument allowed is 'close'" );
 						in.close();
 						return null;
 					}
@@ -131,7 +131,7 @@
 						in.close();
 					return rtn;
 				} catch(IOException e) {
-					throw new LuanException(luan,e);
+					throw new LuanException(e);
 				}
 			}
 		};
@@ -145,7 +145,7 @@
 				try {
 					if( args.length > 0 ) {
 						if( args.length > 1 || !"close".equals(args[0]) )
-							throw new LuanException(luan, "the only argument allowed is 'close'" );
+							throw new LuanException( "the only argument allowed is 'close'" );
 						in.close();
 						return null;
 					}
@@ -155,7 +155,7 @@
 					}
 					return a;
 				} catch(IOException e) {
-					throw new LuanException(luan,e);
+					throw new LuanException(e);
 				}
 			}
 		};
@@ -258,7 +258,7 @@
 	public static abstract class LuanIO extends LuanIn {
 		abstract OutputStream outputStream() throws IOException;
 
-		public void write(LuanState luan,Object obj) throws LuanException, IOException {
+		public void write(Object obj) throws LuanException, IOException {
 			if( obj instanceof String ) {
 				String s = (String)obj;
 				Writer out = new OutputStreamWriter(outputStream());
@@ -273,7 +273,7 @@
 				out.close();
 				return;
 			}
-			throw new LuanException(luan, "bad argument #1 to 'write' (string or binary expected)" );
+			throw new LuanException( "bad argument #1 to 'write' (string or binary expected)" );
 		}
 
 		public LuanTable text_writer() throws IOException {
@@ -288,7 +288,7 @@
 			LuanTable tbl = super.table();
 			try {
 				tbl.rawPut( "write", new LuanJavaFunction(
-					LuanIO.class.getMethod( "write", LuanState.class, Object.class ), this
+					LuanIO.class.getMethod( "write", Object.class ), this
 				) );
 				tbl.rawPut( "text_writer", new LuanJavaFunction(
 					LuanIO.class.getMethod( "text_writer" ), this
@@ -516,8 +516,8 @@
 		return nullIO.table();
 	}
 
-	public static LuanTable string(LuanState luan,String s) throws LuanException {
-		Utils.checkNotNull(luan,s);
+	public static LuanTable string(String s) throws LuanException {
+		Utils.checkNotNull(s);
 		return new LuanString(s).table();
 	}
 
@@ -588,10 +588,10 @@
 		LuanTable schemes = new LuanTable();
 		try {
 			schemes.rawPut( "null", new LuanJavaFunction(IoLuan.class.getMethod("null_"),null) );
-			add( schemes, "string", LuanState.class, String.class );
+			add( schemes, "string", String.class );
 			add( schemes, "file", LuanState.class, String.class, Boolean.class );
 			add( schemes, "classpath", LuanState.class, String.class, Boolean.class );
-			add( schemes, "socket", LuanState.class, String.class );
+			add( schemes, "socket", String.class );
 			add( schemes, "http", String.class, Boolean.class );
 			add( schemes, "https", String.class, Boolean.class );
 			add( schemes, "luan", LuanState.class, String.class, Boolean.class );
@@ -615,13 +615,13 @@
 	public static LuanTable uri(LuanState luan,String name,Boolean addExtension) throws LuanException {
 		int i = name.indexOf(':');
 		if( i == -1 )
-			throw new LuanException(luan, "invalid Io.uri name '"+name+"', missing scheme" );
+			throw new LuanException( "invalid Io.uri name '"+name+"', missing scheme" );
 		String scheme = name.substring(0,i);
 		String location = name.substring(i+1);
 		LuanTable schemes = schemes(luan);
 		LuanFunction opener = (LuanFunction)schemes.get(luan,scheme);
 		if( opener == null )
-			throw new LuanException(luan, "invalid scheme '"+scheme+"' in '"+name+"'" );
+			throw new LuanException( "invalid scheme '"+scheme+"' in '"+name+"'" );
 		return (LuanTable)Luan.first(opener.call(luan,new Object[]{location,addExtension}));
 	}
 
@@ -649,10 +649,10 @@
 		}
 	}
 
-	public static LuanTable socket(LuanState luan,String name) throws LuanException, IOException {
+	public static LuanTable socket(String name) throws LuanException, IOException {
 		int i = name.indexOf(':');
 		if( i == -1 )
-			throw new LuanException(luan, "invalid socket '"+name+"', format is: <host>:<port>" );
+			throw new LuanException( "invalid socket '"+name+"', format is: <host>:<port>" );
 		String host = name.substring(0,i);
 		String portStr = name.substring(i+1);
 		int port = Integer.parseInt(portStr);
@@ -666,13 +666,13 @@
 				try {
 					if( args.length > 0 ) {
 						if( args.length > 1 || !"close".equals(args[0]) )
-							throw new LuanException(luan, "the only argument allowed is 'close'" );
+							throw new LuanException( "the only argument allowed is 'close'" );
 						ss.close();
 						return null;
 					}
 					return new LuanSocket(ss.accept()).table();
 				} catch(IOException e) {
-					throw new LuanException(luan,e);
+					throw new LuanException(e);
 				}
 			}
 		};