changeset 58:d6c454b7f58c

make concat work with any type; improve JavaLib.getMembers(); git-svn-id: https://luan-java.googlecode.com/svn/trunk@59 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 07 Jan 2013 00:18:35 +0000
parents 19ca9c4c6c7f
children 5c9cadd0acce
files src/luan/interp/ConcatExpr.java src/luan/lib/JavaLib.java
diffstat 2 files changed, 24 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
diff -r 19ca9c4c6c7f -r d6c454b7f58c src/luan/interp/ConcatExpr.java
--- a/src/luan/interp/ConcatExpr.java	Sun Jan 06 19:17:56 2013 +0000
+++ b/src/luan/interp/ConcatExpr.java	Mon Jan 07 00:18:35 2013 +0000
@@ -15,8 +15,9 @@
 	@Override public Object eval(LuanStateImpl luan) throws LuanException {
 		Object o1 = op1.eval(luan);
 		Object o2 = op2.eval(luan);
-		String s1 = Luan.asString(o1);
-		String s2 = Luan.asString(o2);
+		String s1 = luan.toString(op1.se(),o1);
+		String s2 = luan.toString(op2.se(),o2);
+/*
 		if( s1 != null && s2 != null )
 			return s1 + s2;
 		LuanFunction fn = luan.getBinHandler(se,"__concat",o1,o2);
@@ -24,5 +25,7 @@
 			return Luan.first(luan.call(fn,se,"__concat",o1,o2));
 		String type = s1==null ? Luan.type(o1) : Luan.type(o2);
 		throw new LuanException( luan, se, "attempt to concatenate a " + type + " value" );
+*/
+		return s1 + s2;
 	}
 }
diff -r 19ca9c4c6c7f -r d6c454b7f58c src/luan/lib/JavaLib.java
--- a/src/luan/lib/JavaLib.java	Sun Jan 06 19:17:56 2013 +0000
+++ b/src/luan/lib/JavaLib.java	Mon Jan 07 00:18:35 2013 +0000
@@ -150,6 +150,15 @@
 		Map<String,List<Member>> clsMap = memberMap.get(cls);
 		if( clsMap == null ) {
 			clsMap = new HashMap<String,List<Member>>();
+			for( Method method : cls.getMethods() ) {
+				String s = method.getName();
+				List<Member> list = clsMap.get(s);
+				if( list == null ) {
+					list = new ArrayList<Member>();
+					clsMap.put(s,list);
+				}
+				list.add(method);
+			}
 			for( Class c : cls.getClasses() ) {
 				String s = c.getSimpleName();
 				List<Member> list = clsMap.get(s);
@@ -161,22 +170,19 @@
 			}
 			for( Field field : cls.getFields() ) {
 				String s = field.getName();
+				try {
+					if( !cls.getField(s).equals(field) )
+						continue;  // not accessible
+				} catch(NoSuchFieldException e) {
+					throw new RuntimeException(e);
+				}
 				List<Member> list = clsMap.get(s);
-				if( list == null ) {
-					list = new ArrayList<Member>();
-					clsMap.put(s,list);
-				}
+				if( list != null )
+					throw new RuntimeException("can't add field '"+s+"' to "+cls+" because these are already defined: "+list);
+				list = new ArrayList<Member>();
+				clsMap.put(s,list);
 				list.add(field);
 			}
-			for( Method method : cls.getMethods() ) {
-				String s = method.getName();
-				List<Member> list = clsMap.get(s);
-				if( list == null ) {
-					list = new ArrayList<Member>();
-					clsMap.put(s,list);
-				}
-				list.add(method);
-			}
 			memberMap.put(cls,clsMap);
 		}
 		List<Member> rtn = clsMap.get(name);