changeset 759:ae612dfc57cb 0.21

better handling of longs in rpc and json
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 19 Jul 2016 09:09:41 -0600
parents c29d11d675fd
children 2a91bde4e1e1
files core/src/luan/modules/IoLuan.java core/src/luan/modules/RpcLuan.java core/src/luan/modules/parsers/Json.java
diffstat 3 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
diff -r c29d11d675fd -r ae612dfc57cb core/src/luan/modules/IoLuan.java
--- a/core/src/luan/modules/IoLuan.java	Tue Jul 19 00:57:37 2016 -0600
+++ b/core/src/luan/modules/IoLuan.java	Tue Jul 19 09:09:41 2016 -0600
@@ -619,6 +619,9 @@
 				tbl.rawPut( "last_modified", new LuanJavaFunction(
 					File.class.getMethod( "lastModified" ), file
 				) );
+				tbl.rawPut( "length", new LuanJavaFunction(
+					File.class.getMethod( "length" ), file
+				) );
 				tbl.rawPut( "child", new LuanJavaFunction(
 					LuanFile.class.getMethod( "child", LuanState.class, String.class ), this
 				) );
diff -r c29d11d675fd -r ae612dfc57cb core/src/luan/modules/RpcLuan.java
--- a/core/src/luan/modules/RpcLuan.java	Tue Jul 19 00:57:37 2016 -0600
+++ b/core/src/luan/modules/RpcLuan.java	Tue Jul 19 09:09:41 2016 -0600
@@ -32,6 +32,7 @@
 	private static final int BINARY = 4;
 	private static final int TABLE = 5;
 	private static final int IO = 6;
+	private static final int LONG = 7;
 
 	@LuanMethod public static Object[] call(LuanState luan,LuanTable socketTbl,String fnName,Object... args)
 		throws LuanException, IOException
@@ -134,6 +135,10 @@
 			out.write(BOOLEAN);
 			writeBoolean(out,(Boolean)obj);
 		}
+		else if( obj instanceof Long ) {
+			out.write(LONG);
+			writeString(out,obj.toString());
+		}
 		else if( obj instanceof Number ) {
 			out.write(NUMBER);
 			writeString(out,obj.toString());
@@ -163,6 +168,8 @@
 			return readString(in);
 		case BOOLEAN:
 			return readBoolean(in);
+		case LONG:
+			return Long.valueOf(readString(in));
 		case NUMBER:
 			return Double.valueOf(readString(in));
 		case BINARY:
diff -r c29d11d675fd -r ae612dfc57cb core/src/luan/modules/parsers/Json.java
--- a/core/src/luan/modules/parsers/Json.java	Tue Jul 19 00:57:37 2016 -0600
+++ b/core/src/luan/modules/parsers/Json.java	Tue Jul 19 09:09:41 2016 -0600
@@ -120,6 +120,7 @@
 
 	private Number number() {
 		int start = parser.begin();
+		boolean isFloat = false;
 		parser.match('-');
 		if( !parser.match('0') ) {
 			if( !parser.inCharRange('1','9') )
@@ -130,15 +131,22 @@
 			if( !parser.inCharRange('0','9') )
 				return parser.failure(null);
 			while( parser.inCharRange('0','9') );
+			isFloat = true;
 		}
 		if( parser.anyOf("eE") ) {
 			parser.anyOf("+-");
 			if( !parser.inCharRange('0','9') )
 				return parser.failure(null);
 			while( parser.inCharRange('0','9') );
+			isFloat = true;
 		}
 		String s = parser.textFrom(start);
-		return parser.success(Double.valueOf(s));
+		Number n;
+		if(isFloat)
+			n = Double.valueOf(s);
+		else
+			n = Long.valueOf(s);
+		return parser.success(n);
 	}
 
 	private LuanTable array() throws ParseException {