Mercurial Hosting > luan
comparison src/luan/lib/PickleClient.java @ 146:0517a4a7fcc5
add Io.reverse_pickle
git-svn-id: https://luan-java.googlecode.com/svn/trunk@147 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 15 Jun 2014 13:35:33 +0000 |
parents | 0594c132888b |
children | 138b9baee80b |
comparison
equal
deleted
inserted
replaced
145:90f38a5d0e0a | 146:0517a4a7fcc5 |
---|---|
6 import luan.Luan; | 6 import luan.Luan; |
7 import luan.LuanState; | 7 import luan.LuanState; |
8 import luan.LuanException; | 8 import luan.LuanException; |
9 import luan.LuanTable; | 9 import luan.LuanTable; |
10 import luan.LuanJavaFunction; | 10 import luan.LuanJavaFunction; |
11 import luan.LuanFunction; | |
11 | 12 |
12 | 13 |
13 public final class PickleClient { | 14 public final class PickleClient { |
14 | 15 |
15 private final PickleCon con; | 16 private final PickleCon con; |
17 private final LuanFunction _reversed_pickle; | |
16 | 18 |
17 PickleClient(LuanState luan,DataInputStream in,DataOutputStream out) { | 19 PickleClient(LuanState luan,DataInputStream in,DataOutputStream out) { |
18 con = new PickleCon(luan,in,out); | 20 this(new PickleCon(luan,in,out)); |
21 } | |
22 | |
23 PickleClient(PickleCon con) { | |
24 this.con = con; | |
25 try { | |
26 this._reversed_pickle = new LuanJavaFunction( | |
27 PickleClient.class.getMethod( "_reversed_pickle" ), this | |
28 ); | |
29 } catch(NoSuchMethodException e) { | |
30 throw new RuntimeException(e); | |
31 } | |
32 } | |
33 | |
34 public Object _reversed_pickle() throws LuanException, IOException { | |
35 new PickleServer(con).run(); | |
36 return con.read(); | |
19 } | 37 } |
20 | 38 |
21 public Object call(Object... args) throws LuanException, IOException { | 39 public Object call(Object... args) throws LuanException, IOException { |
22 con.write(args); | 40 con.write(args); |
23 Object[] result = Luan.array(con.read()); | 41 Object[] result; |
42 con.ioModule.put("_reversed_pickle",_reversed_pickle); | |
43 try { | |
44 result = Luan.array(con.read()); | |
45 } finally { | |
46 con.ioModule.put("_reversed_pickle",null); | |
47 } | |
24 boolean ok = (boolean)result[0]; | 48 boolean ok = (boolean)result[0]; |
25 if( ok ) { | 49 if( ok ) { |
26 Object[] rtn = new Object[result.length-1]; | 50 Object[] rtn = new Object[result.length-1]; |
27 System.arraycopy(result,1,rtn,0,rtn.length); | 51 System.arraycopy(result,1,rtn,0,rtn.length); |
28 return rtn; | 52 return rtn; |