comparison core/src/luan/modules/PickleServer.java @ 202:75750ceb45ee

add LuanState.registry git-svn-id: https://luan-java.googlecode.com/svn/trunk@203 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 04 Jul 2014 17:18:39 +0000
parents 3dcb0f9bee82
children 340656b18b74
comparison
equal deleted inserted replaced
201:27abb3746917 202:75750ceb45ee
51 throw new RuntimeException(e2); 51 throw new RuntimeException(e2);
52 } 52 }
53 } 53 }
54 54
55 public void run() { 55 public void run() {
56 LuanTable ioModule = con.ioModule; 56 LuanTable io = (LuanTable)PackageLuan.loaded(con.luan).get("Io");
57 Object old_reverse_pickle = ioModule.get("reverse_pickle"); 57 LuanTable env = con.env;
58 Object old_unreverse_pickle = ioModule.get("_unreverse_pickle"); 58 Object old_reverse_pickle = io.get("reverse_pickle");
59 Object old_unreverse_pickle = env.get("_unreverse_pickle");
59 try { 60 try {
60 try { 61 try {
61 ioModule.put("reverse_pickle", new LuanJavaFunction( 62 io.put("reverse_pickle", new LuanJavaFunction(
62 PickleServer.class.getMethod( "reverse_pickle", LuanFunction.class ), this 63 PickleServer.class.getMethod( "reverse_pickle", LuanFunction.class ), this
63 ) ); 64 ) );
64 ioModule.put("_unreverse_pickle", new LuanJavaFunction( 65 env.put("_unreverse_pickle", new LuanJavaFunction(
65 PickleServer.class.getMethod( "_unreverse_pickle" ), this 66 PickleServer.class.getMethod( "_unreverse_pickle" ), this
66 ) ); 67 ) );
67 } catch(NoSuchMethodException e) { 68 } catch(NoSuchMethodException e) {
68 throw new RuntimeException(e); 69 throw new RuntimeException(e);
69 } 70 }
83 } catch(IOException e) { 84 } catch(IOException e) {
84 throw new RuntimeException(e); 85 throw new RuntimeException(e);
85 } 86 }
86 } 87 }
87 } finally { 88 } finally {
88 ioModule.put("reverse_pickle",old_reverse_pickle); 89 io.put("reverse_pickle",old_reverse_pickle);
89 ioModule.put("_unreverse_pickle",old_unreverse_pickle); 90 env.put("_unreverse_pickle",old_unreverse_pickle);
90 } 91 }
91 } 92 }
92 93
93 public void reverse_pickle(LuanFunction fn) throws IOException, LuanException { 94 public void reverse_pickle(LuanFunction fn) throws IOException, LuanException {
94 try { 95 try {
95 con.write( "return Io._reversed_pickle()\n" ); 96 con.write( "return _reversed_pickle()\n" );
96 } catch(LuanException e) { 97 } catch(LuanException e) {
97 throw new RuntimeException(e); 98 throw new RuntimeException(e);
98 } 99 }
99 PickleClient pc = new PickleClient(con); 100 PickleClient pc = new PickleClient(con);
100 try { 101 try {
101 con.luan.call(fn,new Object[]{pc.table()}); 102 con.luan.call(fn,new Object[]{pc.table()});
102 } finally { 103 } finally {
103 try { 104 try {
104 pc.call( "Io._unreverse_pickle()\n" ); 105 pc.call( "_unreverse_pickle()\n" );
105 } catch(LuanException e) { 106 } catch(LuanException e) {
106 throw new RuntimeException(e); 107 throw new RuntimeException(e);
107 } 108 }
108 } 109 }
109 } 110 }