Mercurial Hosting > luan
comparison src/luan/lib/IoLib.java @ 129:486a0641bca4
add pickle client/server;
fix parser bugs;
git-svn-id: https://luan-java.googlecode.com/svn/trunk@130 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 09 Jun 2014 09:16:16 +0000 |
parents | 0cd559a16758 |
children | 0594c132888b |
comparison
equal
deleted
inserted
replaced
128:f0a4abe58593 | 129:486a0641bca4 |
---|---|
7 import java.io.Writer; | 7 import java.io.Writer; |
8 import java.io.FileReader; | 8 import java.io.FileReader; |
9 import java.io.FileWriter; | 9 import java.io.FileWriter; |
10 import java.io.BufferedReader; | 10 import java.io.BufferedReader; |
11 import java.io.BufferedWriter; | 11 import java.io.BufferedWriter; |
12 import java.io.BufferedInputStream; | |
12 import java.io.BufferedOutputStream; | 13 import java.io.BufferedOutputStream; |
13 import java.io.File; | 14 import java.io.File; |
14 import java.io.FileInputStream; | 15 import java.io.FileInputStream; |
15 import java.io.FileOutputStream; | 16 import java.io.FileOutputStream; |
16 import java.io.InputStreamReader; | 17 import java.io.InputStreamReader; |
17 import java.io.OutputStreamWriter; | 18 import java.io.OutputStreamWriter; |
18 import java.io.ByteArrayInputStream; | 19 import java.io.ByteArrayInputStream; |
20 import java.io.DataInputStream; | |
21 import java.io.DataOutputStream; | |
19 import java.io.IOException; | 22 import java.io.IOException; |
20 import java.net.URL; | 23 import java.net.URL; |
21 import java.net.Socket; | 24 import java.net.Socket; |
22 import java.net.ServerSocket; | 25 import java.net.ServerSocket; |
23 import java.net.MalformedURLException; | 26 import java.net.MalformedURLException; |
298 | 301 |
299 public LuanTable binary_writer() throws IOException { | 302 public LuanTable binary_writer() throws IOException { |
300 return binaryWriter(new BufferedOutputStream(outputStream())); | 303 return binaryWriter(new BufferedOutputStream(outputStream())); |
301 } | 304 } |
302 | 305 |
303 LuanTable table() { | 306 @Override LuanTable table() { |
304 LuanTable tbl = super.table(); | 307 LuanTable tbl = super.table(); |
305 try { | 308 try { |
306 tbl.put( "write", new LuanJavaFunction( | 309 tbl.put( "write", new LuanJavaFunction( |
307 LuanIO.class.getMethod( "write", LuanState.class, Object.class ), this | 310 LuanIO.class.getMethod( "write", LuanState.class, Object.class ), this |
308 ) ); | 311 ) ); |
370 return socket.getInputStream(); | 373 return socket.getInputStream(); |
371 } | 374 } |
372 | 375 |
373 OutputStream outputStream() throws IOException { | 376 OutputStream outputStream() throws IOException { |
374 return socket.getOutputStream(); | 377 return socket.getOutputStream(); |
378 } | |
379 | |
380 public LuanTable pickle_client(LuanState luan) throws IOException { | |
381 DataInputStream in = new DataInputStream(new BufferedInputStream(inputStream())); | |
382 DataOutputStream out = new DataOutputStream(new BufferedOutputStream(outputStream())); | |
383 return new PickleClient(luan,in,out).table(); | |
384 } | |
385 | |
386 public void run_pickle_server(LuanState luan) throws IOException { | |
387 DataInputStream in = new DataInputStream(new BufferedInputStream(inputStream())); | |
388 DataOutputStream out = new DataOutputStream(new BufferedOutputStream(outputStream())); | |
389 new PickleServer(luan,in,out).run(); | |
390 } | |
391 | |
392 @Override LuanTable table() { | |
393 LuanTable tbl = super.table(); | |
394 try { | |
395 tbl.put( "pickle_client", new LuanJavaFunction( | |
396 LuanSocket.class.getMethod( "pickle_client", LuanState.class ), this | |
397 ) ); | |
398 tbl.put( "run_pickle_server", new LuanJavaFunction( | |
399 LuanSocket.class.getMethod( "run_pickle_server", LuanState.class ), this | |
400 ) ); | |
401 } catch(NoSuchMethodException e) { | |
402 throw new RuntimeException(e); | |
403 } | |
404 return tbl; | |
375 } | 405 } |
376 } | 406 } |
377 | 407 |
378 public static LuanTable socket(String host,int port) throws IOException { | 408 public static LuanTable socket(String host,int port) throws IOException { |
379 return new LuanSocket(host,port).table(); | 409 return new LuanSocket(host,port).table(); |