comparison src/luan/modules/RpcLuan.java @ 1113:22652f4020fb

add JsonToString
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 02 Aug 2017 19:00:24 -0600
parents 490f77bb2ad1
children
comparison
equal deleted inserted replaced
1112:490f77bb2ad1 1113:22652f4020fb
18 import luan.LuanState; 18 import luan.LuanState;
19 import luan.LuanTable; 19 import luan.LuanTable;
20 import luan.LuanFunction; 20 import luan.LuanFunction;
21 import luan.LuanException; 21 import luan.LuanException;
22 import luan.LuanMethod; 22 import luan.LuanMethod;
23 import luan.modules.parsers.Json; 23 import luan.lib.json.JsonToString;
24 import luan.lib.json.JsonParser; 24 import luan.lib.json.JsonParser;
25 import luan.lib.parser.ParseException; 25 import luan.lib.parser.ParseException;
26 26
27 27
28 public final class RpcLuan { 28 public final class RpcLuan {
151 out.write(a); 151 out.write(a);
152 } 152 }
153 else if( obj instanceof LuanTable ) { 153 else if( obj instanceof LuanTable ) {
154 out.write(TABLE); 154 out.write(TABLE);
155 // String s = pickle( luan, obj, Collections.newSetFromMap(new IdentityHashMap<LuanTable,Boolean>()) ); 155 // String s = pickle( luan, obj, Collections.newSetFromMap(new IdentityHashMap<LuanTable,Boolean>()) );
156 String s = Json.toString(obj); 156 String s = JsonToString.toString(Luan.toJava(obj));
157 writeString(out,s); 157 writeString(out,s);
158 } 158 }
159 else 159 else
160 throw new LuanException( "invalid type: " + obj.getClass() ); 160 throw new LuanException( "invalid type: " + obj.getClass() );
161 } 161 }
180 /* 180 /*
181 LuanFunction fn = Luan.load("return "+s,"rpc-reader"); 181 LuanFunction fn = Luan.load("return "+s,"rpc-reader");
182 return fn.call(luan); 182 return fn.call(luan);
183 */ 183 */
184 try { 184 try {
185 return BasicLuan.to_luan(JsonParser.parse(s)); 185 return Luan.toLuan(JsonParser.parse(s));
186 } catch(ParseException e) { 186 } catch(ParseException e) {
187 throw new LuanException(e); 187 throw new LuanException(e);
188 } 188 }
189 case IO: 189 case IO:
190 return new LuanInputStream(in,close).table(); 190 return new LuanInputStream(in,close).table();