changeset 262:3ccc5205d04d

add "socket" protocol git-svn-id: https://luan-java.googlecode.com/svn/trunk@263 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 28 Oct 2014 23:54:41 +0000
parents 715c4a6e1169
children 54873a389f80
files core/src/luan/modules/IoLuan.java
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/modules/IoLuan.java	Tue Oct 28 23:36:29 2014 +0000
+++ b/core/src/luan/modules/IoLuan.java	Tue Oct 28 23:54:41 2014 +0000
@@ -39,14 +39,9 @@
 			LuanTable module = Luan.newTable();
 			try {
 				add( module, "read_console_line", String.class );
-
 				module.put( "protocols", newProtocols() );
-
 				add( module, "get", LuanState.class, String.class );
-
 				module.put( "stdin", stdin.table() );
-
-				add( module, "Socket", String.class, Integer.TYPE );
 				add( module, "socket_server", Integer.TYPE );
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
@@ -442,6 +437,7 @@
 		try {
 			add( protocols, "file", LuanState.class, String.class );
 			add( protocols, "classpath", LuanState.class, String.class );
+			add( protocols, "socket", LuanState.class, String.class );
 		} catch(NoSuchMethodException e) {
 			throw new RuntimeException(e);
 		}
@@ -522,7 +518,13 @@
 		}
 	}
 
-	public static LuanTable Socket(String host,int port) throws IOException {
+	public static LuanTable socket(LuanState luan,String name) throws LuanException, IOException {
+		int i = name.indexOf(':');
+		if( i == -1 )
+			throw luan.exception( "invalid socket '"+name+"', format is: <host>:<port>" );
+		String host = name.substring(0,i);
+		String portStr = name.substring(i+1);
+		int port = Integer.parseInt(portStr);
 		return new LuanSocket(host,port).table();
 	}