changeset 244:0a8e6fdb62f0

fix Math.random() git-svn-id: https://luan-java.googlecode.com/svn/trunk@245 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 09 Oct 2014 22:44:07 +0000
parents c912f6de2053
children 2ed8465a9d62
files core/src/luan/LuanJavaFunction.java core/src/luan/modules/MathLuan.java dist/jars/luan-core-trunk.jar dist/jars/luan-logging-trunk.jar dist/jars/luan-lucene-trunk.jar dist/jars/luan-mail-trunk.jar dist/jars/luan-web-trunk.jar
diffstat 7 files changed, 46 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/LuanJavaFunction.java	Wed Oct 08 06:22:04 2014 +0000
+++ b/core/src/luan/LuanJavaFunction.java	Thu Oct 09 22:44:07 2014 +0000
@@ -232,18 +232,27 @@
 		public Object convert(Object obj) {
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_SAME";
+		}
 	};
 
 	private static final ArgConverter ARG_BOOLEAN = new ArgConverter() {
 		public Object convert(Object obj) {
 			return Luan.toBoolean(obj);
 		}
+		@Override public String toString() {
+			return "ARG_BOOLEAN";
+		}
 	};
 
 	private static final ArgConverter ARG_BOOLEAN_OBJ = new ArgConverter() {
 		public Object convert(Object obj) {
 			return obj==null ? null : Luan.toBoolean(obj);
 		}
+		@Override public String toString() {
+			return "ARG_BOOLEAN_OBJ";
+		}
 	};
 
 	private static final ArgConverter ARG_DOUBLE = new ArgConverter() {
@@ -262,6 +271,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_DOUBLE";
+		}
 	};
 
 	private static final ArgConverter ARG_FLOAT = new ArgConverter() {
@@ -280,6 +292,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_FLOAT";
+		}
 	};
 
 	private static final ArgConverter ARG_LONG = new ArgConverter() {
@@ -300,6 +315,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_LONG";
+		}
 	};
 
 	private static final ArgConverter ARG_INTEGER = new ArgConverter() {
@@ -320,6 +338,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_INTEGER";
+		}
 	};
 
 	private static final ArgConverter ARG_SHORT = new ArgConverter() {
@@ -340,6 +361,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_SHORT";
+		}
 	};
 
 	private static final ArgConverter ARG_BYTE = new ArgConverter() {
@@ -360,6 +384,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_BYTE";
+		}
 	};
 
 	private static final ArgConverter ARG_TABLE = new ArgConverter() {
@@ -388,6 +415,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_TABLE";
+		}
 	};
 
 	private static final ArgConverter ARG_MAP = new ArgConverter() {
@@ -398,6 +428,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_MAP";
+		}
 	};
 
 	private static final ArgConverter ARG_LIST = new ArgConverter() {
@@ -409,6 +442,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_LIST";
+		}
 	};
 
 	private static final ArgConverter ARG_SET = new ArgConverter() {
@@ -420,6 +456,9 @@
 			}
 			return obj;
 		}
+		@Override public String toString() {
+			return "ARG_SET";
+		}
 	};
 
 	private static class ArgArray implements ArgConverter {
--- a/core/src/luan/modules/MathLuan.java	Wed Oct 08 06:22:04 2014 +0000
+++ b/core/src/luan/modules/MathLuan.java	Thu Oct 09 22:44:07 2014 +0000
@@ -32,7 +32,7 @@
 				module.put("pi",Math.PI);
 				add( module, "pow", Double.TYPE, Double.TYPE );
 				add( module, "rad", Double.TYPE );
-				add( module, "random" );
+				add( module, "random", Integer.class, Integer.class );
 				add( module, "sin", Double.TYPE );
 				add( module, "sinh", Double.TYPE );
 				add( module, "sqrt", Double.TYPE );
@@ -126,8 +126,12 @@
 		return Math.toRadians(x);
 	}
 
-	public static double random() {
-		return Math.random();
+	public static double random(Integer m,Integer n) {
+		if( m==null )
+			return Math.random();
+		if( n==null )
+			return Math.floor(m*Math.random()) + 1;
+		return Math.floor((n-m)*Math.random()) + m;
 	}
 
 	public static double sin(double x) {
Binary file dist/jars/luan-core-trunk.jar has changed
Binary file dist/jars/luan-logging-trunk.jar has changed
Binary file dist/jars/luan-lucene-trunk.jar has changed
Binary file dist/jars/luan-mail-trunk.jar has changed
Binary file dist/jars/luan-web-trunk.jar has changed