Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/lib/PickleServer.java Mon Jun 09 09:16:16 2014 +0000 @@ -0,0 +1,62 @@ +package luan.lib; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.EOFException; +import java.util.List; +import java.util.ArrayList; +import luan.Luan; +import luan.LuanState; +import luan.LuanException; + + +final class PickleServer { + + private final PickleCon con; + + PickleServer(LuanState luan,DataInputStream in,DataOutputStream out) { + con = new PickleCon(luan,in,out); + } + + void next() throws IOException { + try { + List<String> list = new ArrayList<String>(); + try { + Object[] result = Luan.array(con.read()); + list.add( "return true" ); + for( Object obj : result ) { + list.add( ", " ); + list.add( con.pickle(obj) ); + } + } catch(LuanException e) { + list.add( "return false, " ); + list.add( con.pickle(e.getMessage()) ); + list.add( ", " ); + list.add( con.pickle(con.src) ); + } + list.add( "\n" ); + con.write( list.toArray() ); + } catch(LuanException e2) { + throw new RuntimeException(e2); + } + } + + public void run() { + try { + while( true ) { + next(); + } + } catch(EOFException e) { + // done + } catch(IOException e) { + e.printStackTrace(); + } + try { + con.close(); + } catch(IOException e) { + throw new RuntimeException(e); + } + } + +}