comparison 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
comparison
equal deleted inserted replaced
190:04b86428dc50 191:2456ef7ada02
41 } 41 }
42 } 42 }
43 43
44 public String checkString(Object obj) throws LuanException { 44 public String checkString(Object obj) throws LuanException {
45 String s = Luan.asString(obj); 45 String s = Luan.asString(obj);
46 if( s == null ) 46 if( s != null )
47 return s;
48 if( el instanceof LuanSource.Element ) {
49 LuanSource.Element se = (LuanSource.Element)el;
50 throw exception( "attempt to use '"+se.text()+"' (a " + Luan.type(obj) + " value) as a string" );
51 } else {
47 throw exception( "attempt to use a " + Luan.type(obj) + " as a string" ); 52 throw exception( "attempt to use a " + Luan.type(obj) + " as a string" );
48 return s; 53 }
49 } 54 }
50 55
51 public Number checkNumber(Object obj) throws LuanException { 56 public Number checkNumber(Object obj) throws LuanException {
52 Number n = Luan.toNumber(obj); 57 Number n = Luan.toNumber(obj);
53 if( n == null ) 58 if( n != null )
59 return n;
60 if( el instanceof LuanSource.Element ) {
61 LuanSource.Element se = (LuanSource.Element)el;
62 throw exception( "attempt to perform arithmetic on '"+se.text()+"' (a " + Luan.type(obj) + " value)" );
63 } else {
54 throw exception( "attempt to perform arithmetic on a " + Luan.type(obj) + " value" ); 64 throw exception( "attempt to perform arithmetic on a " + Luan.type(obj) + " value" );
55 return n; 65 }
56 } 66 }
57 67
58 public LuanFunction checkFunction(Object obj) throws LuanException { 68 public LuanFunction checkFunction(Object obj) throws LuanException {
59 if( obj instanceof LuanFunction ) 69 if( obj instanceof LuanFunction )
60 return (LuanFunction)obj; 70 return (LuanFunction)obj;
61 throw exception( "attempt to call a " + Luan.type(obj) + " value" ); 71 if( el instanceof LuanSource.Element ) {
72 LuanSource.Element se = (LuanSource.Element)el;
73 throw exception( "attempt to call '"+se.text()+"' (a " + Luan.type(obj) + " value)" );
74 } else {
75 throw exception( "attempt to call a " + Luan.type(obj) + " value" );
76 }
62 } 77 }
63 78
64 public Boolean checkBoolean(Object obj) throws LuanException { 79 public Boolean checkBoolean(Object obj) throws LuanException {
65 if( obj instanceof Boolean ) 80 if( obj instanceof Boolean )
66 return (Boolean)obj; 81 return (Boolean)obj;
67 throw exception( "attempt to use a " + Luan.type(obj) + " as a boolean" ); 82 if( el instanceof LuanSource.Element ) {
83 LuanSource.Element se = (LuanSource.Element)el;
84 throw exception( "attempt to use '"+se.text()+"' (a " + Luan.type(obj) + " value) as a boolean" );
85 } else {
86 throw exception( "attempt to use a " + Luan.type(obj) + " as a boolean" );
87 }
68 } 88 }
69 89
70 public String toString(Object obj) throws LuanException { 90 public String toString(Object obj) throws LuanException {
71 LuanFunction fn = getHandlerFunction("__tostring",obj); 91 LuanFunction fn = getHandlerFunction("__tostring",obj);
72 if( fn != null ) 92 if( fn != null )