diff core/src/luan/modules/RpcLuan.java @ 758:c29d11d675fd

added Json.toString() and rpc now sends tables as json
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 19 Jul 2016 00:57:37 -0600
parents 1a101ac9ea46
children ae612dfc57cb
line wrap: on
line diff
--- a/core/src/luan/modules/RpcLuan.java	Mon Jul 18 20:18:02 2016 -0600
+++ b/core/src/luan/modules/RpcLuan.java	Tue Jul 19 00:57:37 2016 -0600
@@ -20,6 +20,8 @@
 import luan.LuanFunction;
 import luan.LuanException;
 import luan.LuanMethod;
+import luan.modules.parsers.Json;
+import luan.modules.parsers.ParseException;
 
 
 public final class RpcLuan {
@@ -144,7 +146,8 @@
 		}
 		else if( obj instanceof LuanTable ) {
 			out.write(TABLE);
-			String s = pickle( luan, obj, Collections.newSetFromMap(new IdentityHashMap<LuanTable,Boolean>()) );
+//			String s = pickle( luan, obj, Collections.newSetFromMap(new IdentityHashMap<LuanTable,Boolean>()) );
+			String s = Json.toString(obj);
 			writeString(out,s);
 		}
 		else
@@ -166,8 +169,15 @@
 			return readBinary(in,readInt(in));
 		case TABLE:
 			String s = readString(in);
+/*
 			LuanFunction fn = Luan.load("return "+s,"rpc-reader");
 			return fn.call(luan);
+*/
+			try {
+				return Json.parse(s);
+			} catch(ParseException e) {
+				throw new LuanException(e);
+			}
 		case IO:
 			return new LuanInputStream(in,close).table();
 		default:
@@ -224,7 +234,7 @@
         out.write((v >>>  0) & 0xFF);
 	}
 
-
+/*
 	private static String pickle(LuanState luan,Object obj,Set<LuanTable> set) throws LuanException {
 		if( obj == null )
 			return "nil";
@@ -253,7 +263,7 @@
 		}
 		throw new LuanException( "invalid type: " + obj.getClass() );
 	}
-
+*/
 
 	private static class Close {
 		boolean b = true;