changeset 510:2da0bcb979b5

better error messages
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 22 May 2015 02:28:15 -0600
parents e3b0846dc2ef
children e3fb9768dbb3
files core/src/luan/LuanTable.java core/src/luan/impl/IndexExpr.java core/src/luan/modules/BinaryLuan.java core/src/luan/modules/JavaLuan.java core/src/luan/modules/StringLuan.java
diffstat 5 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/LuanTable.java	Fri May 22 02:02:49 2015 -0600
+++ b/core/src/luan/LuanTable.java	Fri May 22 02:28:15 2015 -0600
@@ -139,7 +139,7 @@
 		else if( bit.el==null )
 			throw bit.exception( "attempt to index a " + Luan.type(obj) + " value" );
 		else
-			throw bit.exception( "attempt to index '"+bit.el.text()+"' (a " + Luan.type(obj) + " value)" );
+			throw bit.exception( "attempt to index a " + Luan.type(obj) + " value in '"+bit.el.text()+"'" );
 	}
 
 	public Object rawGet(Object key) {
--- a/core/src/luan/impl/IndexExpr.java	Fri May 22 02:02:49 2015 -0600
+++ b/core/src/luan/impl/IndexExpr.java	Fri May 22 02:28:15 2015 -0600
@@ -12,7 +12,7 @@
 	}
 
 	@Override public Object eval(LuanStateImpl luan) throws LuanException {
-		return LuanTable.index( luan.bit(op1.el()), op1.eval(luan), op2.eval(luan) );
+		return LuanTable.index( luan.bit(el()), op1.eval(luan), op2.eval(luan) );
 	}
 
 }
--- a/core/src/luan/modules/BinaryLuan.java	Fri May 22 02:02:49 2015 -0600
+++ b/core/src/luan/modules/BinaryLuan.java	Fri May 22 02:28:15 2015 -0600
@@ -27,9 +27,9 @@
 			};
 		}
 		if( bit.el != null )
-			throw bit.exception( "invalid index ["+luan.toString(key)+"] for binary ("+bit.el.text()+")" ) ;
+			throw bit.exception( "invalid index for binary in '"+bit.el.text()+"'" ) ;
 		else
-			throw bit.exception( "invalid index ["+luan.toString(key)+"] for binary") ;
+			throw bit.exception( "invalid index for binary") ;
 	}
 
 	static int start(byte[] binary,int i) {
--- a/core/src/luan/modules/JavaLuan.java	Fri May 22 02:02:49 2015 -0600
+++ b/core/src/luan/modules/JavaLuan.java	Fri May 22 02:28:15 2015 -0600
@@ -55,9 +55,9 @@
 		if( rtn != FAIL )
 			return rtn;
 		if( bit.el != null )
-			throw bit.exception( "invalid index ["+luan.toString(key)+"] for ("+bit.el.text()+") java: "+obj.getClass() );
+			throw bit.exception( "invalid index for java "+obj.getClass()+" in '"+bit.el.text()+"'" );
 		else
-			throw bit.exception( "invalid index ["+luan.toString(key)+"] for java: "+obj.getClass() );
+			throw bit.exception( "invalid index for java "+obj.getClass() );
 	}
 
 	public static Object __index(LuanState luan,Object obj,Object key) throws LuanException {
@@ -105,9 +105,8 @@
 				if( i != null ) {
 					return Array.get(obj,i);
 				}
-				throw luan.exception("invalid member '"+key+"' for java array: "+obj);
-			}
-			if( key instanceof String ) {
+//				throw luan.exception("invalid member '"+key+"' for java array: "+obj);
+			} else if( key instanceof String ) {
 				String name = (String)key;
 				if( "instanceof".equals(name) ) {
 					return new LuanJavaFunction(instanceOf,new InstanceOf(obj));
--- a/core/src/luan/modules/StringLuan.java	Fri May 22 02:02:49 2015 -0600
+++ b/core/src/luan/modules/StringLuan.java	Fri May 22 02:28:15 2015 -0600
@@ -36,9 +36,9 @@
 				return rtn;
 		}
 		if( bit.el != null )
-			throw bit.exception( "invalid index ["+luan.toString(key)+"] for string ("+bit.el.text()+")" ) ;
+			throw bit.exception( "invalid index for string in '"+bit.el.text()+"'" ) ;
 		else
-			throw bit.exception( "invalid index ["+luan.toString(key)+"] for string") ;
+			throw bit.exception( "invalid index for string") ;
 	}
 
 	static int start(String s,int i) {