changeset 100:6c827f7275df

fix JavaLib.setMember() for int conversion git-svn-id: https://luan-java.googlecode.com/svn/trunk@101 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 11 Apr 2013 21:03:54 +0000
parents b19988270d74
children 8ebcccca13ab
files src/luan/lib/JavaLib.java
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
diff -r b19988270d74 -r 6c827f7275df src/luan/lib/JavaLib.java
--- a/src/luan/lib/JavaLib.java	Fri Mar 29 01:40:41 2013 +0000
+++ b/src/luan/lib/JavaLib.java	Thu Apr 11 21:03:54 2013 +0000
@@ -193,7 +193,22 @@
 	private static void setMember(Object obj,List<Member> members,Object value) {
 		Field field = (Field)members.get(0);
 		try {
-			field.set(obj,value);
+			try {
+				field.set(obj,value);
+			} catch(IllegalArgumentException e) {
+				Class cls = field.getType();
+				if( value instanceof Number ) {
+					Number n = (Number)value;
+					if( cls.equals(Integer.TYPE) || cls.equals(Integer.class) ) {
+						int r = n.intValue();
+						if( r==n.doubleValue() ) {
+							field.setInt(obj,r);
+							return;
+						}
+					}
+				}
+				throw e;
+			}
 		} catch(IllegalAccessException e) {
 			throw new RuntimeException(e);
 		}