comparison src/luan/lib/PickleServer.java @ 147:cc3a0578edac

fix Io.reverse_pickle git-svn-id: https://luan-java.googlecode.com/svn/trunk@148 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 15 Jun 2014 15:41:36 +0000
parents 0517a4a7fcc5
children
comparison
equal deleted inserted replaced
146:0517a4a7fcc5 147:cc3a0578edac
36 for( Object obj : result ) { 36 for( Object obj : result ) {
37 list.add( ", " ); 37 list.add( ", " );
38 list.add( con.pickle(obj) ); 38 list.add( con.pickle(obj) );
39 } 39 }
40 } catch(LuanException e) { 40 } catch(LuanException e) {
41 // System.out.println(e);
41 //e.printStackTrace(); 42 //e.printStackTrace();
42 list.add( "return false, " ); 43 list.add( "return false, " );
43 list.add( con.pickle(e.getMessage()) ); 44 list.add( con.pickle(e.getMessage()) );
44 list.add( ", " ); 45 list.add( ", " );
45 list.add( con.pickle(con.src) ); 46 list.add( con.pickle(con.src) );
52 } 53 }
53 54
54 public void run() { 55 public void run() {
55 LuanTable ioModule = con.ioModule; 56 LuanTable ioModule = con.ioModule;
56 Object old_reverse_pickle = ioModule.get("reverse_pickle"); 57 Object old_reverse_pickle = ioModule.get("reverse_pickle");
57 Object old_close_pickle = ioModule.get("unreverse_pickle"); 58 Object old_unreverse_pickle = ioModule.get("_unreverse_pickle");
58 try { 59 try {
59 try { 60 try {
60 ioModule.put("reverse_pickle", new LuanJavaFunction( 61 ioModule.put("reverse_pickle", new LuanJavaFunction(
61 PickleServer.class.getMethod( "reverse_pickle" ), this 62 PickleServer.class.getMethod( "reverse_pickle", LuanFunction.class ), this
62 ) ); 63 ) );
63 ioModule.put("unreverse_pickle", new LuanJavaFunction( 64 ioModule.put("_unreverse_pickle", new LuanJavaFunction(
64 PickleServer.class.getMethod( "unreverse_pickle" ), this 65 PickleServer.class.getMethod( "_unreverse_pickle" ), this
65 ) ); 66 ) );
66 } catch(NoSuchMethodException e) { 67 } catch(NoSuchMethodException e) {
67 throw new RuntimeException(e); 68 throw new RuntimeException(e);
68 } 69 }
69 isRunning = true; 70 isRunning = true;
83 throw new RuntimeException(e); 84 throw new RuntimeException(e);
84 } 85 }
85 } 86 }
86 } finally { 87 } finally {
87 ioModule.put("reverse_pickle",old_reverse_pickle); 88 ioModule.put("reverse_pickle",old_reverse_pickle);
88 ioModule.put("unreverse_pickle",old_close_pickle); 89 ioModule.put("_unreverse_pickle",old_unreverse_pickle);
89 } 90 }
90 } 91 }
91 92
92 public LuanTable reverse_pickle() throws IOException { 93 public void reverse_pickle(LuanFunction fn) throws IOException, LuanException {
93 try { 94 try {
94 con.write( "return Io._reversed_pickle()\n" ); 95 con.write( "return Io._reversed_pickle()\n" );
95 } catch(LuanException e) { 96 } catch(LuanException e) {
96 throw new RuntimeException(e); 97 throw new RuntimeException(e);
97 } 98 }
98 return new PickleClient(con).table(); 99 PickleClient pc = new PickleClient(con);
100 try {
101 con.luan.call(fn,new Object[]{pc.table()});
102 } finally {
103 try {
104 pc.call( "Io._unreverse_pickle()\n" );
105 } catch(LuanException e) {
106 throw new RuntimeException(e);
107 }
108 }
99 } 109 }
100 110
101 public void unreverse_pickle() { 111 public void _unreverse_pickle() {
102 isRunning = false; 112 isRunning = false;
103 } 113 }
104 114
105 } 115 }