Mercurial Hosting > luan
comparison src/luan/lib/PickleServer.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 | |
children | 90f38a5d0e0a |
comparison
equal
deleted
inserted
replaced
128:f0a4abe58593 | 129:486a0641bca4 |
---|---|
1 package luan.lib; | |
2 | |
3 import java.io.DataInputStream; | |
4 import java.io.DataOutputStream; | |
5 import java.io.IOException; | |
6 import java.io.EOFException; | |
7 import java.util.List; | |
8 import java.util.ArrayList; | |
9 import luan.Luan; | |
10 import luan.LuanState; | |
11 import luan.LuanException; | |
12 | |
13 | |
14 final class PickleServer { | |
15 | |
16 private final PickleCon con; | |
17 | |
18 PickleServer(LuanState luan,DataInputStream in,DataOutputStream out) { | |
19 con = new PickleCon(luan,in,out); | |
20 } | |
21 | |
22 void next() throws IOException { | |
23 try { | |
24 List<String> list = new ArrayList<String>(); | |
25 try { | |
26 Object[] result = Luan.array(con.read()); | |
27 list.add( "return true" ); | |
28 for( Object obj : result ) { | |
29 list.add( ", " ); | |
30 list.add( con.pickle(obj) ); | |
31 } | |
32 } catch(LuanException e) { | |
33 list.add( "return false, " ); | |
34 list.add( con.pickle(e.getMessage()) ); | |
35 list.add( ", " ); | |
36 list.add( con.pickle(con.src) ); | |
37 } | |
38 list.add( "\n" ); | |
39 con.write( list.toArray() ); | |
40 } catch(LuanException e2) { | |
41 throw new RuntimeException(e2); | |
42 } | |
43 } | |
44 | |
45 public void run() { | |
46 try { | |
47 while( true ) { | |
48 next(); | |
49 } | |
50 } catch(EOFException e) { | |
51 // done | |
52 } catch(IOException e) { | |
53 e.printStackTrace(); | |
54 } | |
55 try { | |
56 con.close(); | |
57 } catch(IOException e) { | |
58 throw new RuntimeException(e); | |
59 } | |
60 } | |
61 | |
62 } |