diff core/src/luan/LuanBit.java @ 191:2456ef7ada02

minor git-svn-id: https://luan-java.googlecode.com/svn/trunk@192 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Tue, 01 Jul 2014 06:40:48 +0000
parents 3dcb0f9bee82
children d55e873e1f0d
line wrap: on
line diff
--- a/core/src/luan/LuanBit.java	Thu Jun 26 18:20:54 2014 +0000
+++ b/core/src/luan/LuanBit.java	Tue Jul 01 06:40:48 2014 +0000
@@ -43,28 +43,48 @@
 
 	public String checkString(Object obj) throws LuanException {
 		String s = Luan.asString(obj);
-		if( s == null )
+		if( s != null )
+			return s;
+		if( el instanceof LuanSource.Element ) {
+			LuanSource.Element se = (LuanSource.Element)el;
+			throw exception( "attempt to use '"+se.text()+"' (a " + Luan.type(obj) + " value) as a string" );
+		} else {
 			throw exception( "attempt to use a " + Luan.type(obj) + " as a string" );
-		return s;
+		}
 	}
 
 	public Number checkNumber(Object obj) throws LuanException {
 		Number n = Luan.toNumber(obj);
-		if( n == null )
+		if( n != null )
+			return n;
+		if( el instanceof LuanSource.Element ) {
+			LuanSource.Element se = (LuanSource.Element)el;
+			throw exception( "attempt to perform arithmetic on '"+se.text()+"' (a " + Luan.type(obj) + " value)" );
+		} else {
 			throw exception( "attempt to perform arithmetic on a " + Luan.type(obj) + " value" );
-		return n;
+		}
 	}
 
 	public LuanFunction checkFunction(Object obj) throws LuanException {
 		if( obj instanceof LuanFunction )
 			return (LuanFunction)obj;
-		throw exception( "attempt to call a " + Luan.type(obj) + " value" );
+		if( el instanceof LuanSource.Element ) {
+			LuanSource.Element se = (LuanSource.Element)el;
+			throw exception( "attempt to call '"+se.text()+"' (a " + Luan.type(obj) + " value)" );
+		} else {
+			throw exception( "attempt to call a " + Luan.type(obj) + " value" );
+		}
 	}
 
 	public Boolean checkBoolean(Object obj) throws LuanException {
 		if( obj instanceof Boolean )
 			return (Boolean)obj;
-		throw exception( "attempt to use a " + Luan.type(obj) + " as a boolean" );
+		if( el instanceof LuanSource.Element ) {
+			LuanSource.Element se = (LuanSource.Element)el;
+			throw exception( "attempt to use '"+se.text()+"' (a " + Luan.type(obj) + " value) as a boolean" );
+		} else {
+			throw exception( "attempt to use a " + Luan.type(obj) + " as a boolean" );
+		}
 	}
 
 	public String toString(Object obj) throws LuanException {