Mercurial Hosting > luan
comparison core/src/luan/LuanBit.java @ 446:bbad2d06f728
remove automatic conversion from string to number
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 04 May 2015 16:21:17 -0600 |
parents | bf5e62a9090c |
children | 30544d1a9cbf |
comparison
equal
deleted
inserted
replaced
445:cc7d246bda2a | 446:bbad2d06f728 |
---|---|
51 throw exception( "attempt to use a " + Luan.type(obj) + " as a string" ); | 51 throw exception( "attempt to use a " + Luan.type(obj) + " as a string" ); |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 public Number checkNumber(Object obj) throws LuanException { | 55 public Number checkNumber(Object obj) throws LuanException { |
56 Number n = Luan.toNumber(obj); | 56 if( obj instanceof Number ) |
57 if( n != null ) | 57 return (Number)obj; |
58 return n; | |
59 if( el instanceof LuanSource.Element ) { | 58 if( el instanceof LuanSource.Element ) { |
60 LuanSource.Element se = (LuanSource.Element)el; | 59 LuanSource.Element se = (LuanSource.Element)el; |
61 throw exception( "attempt to perform arithmetic on '"+se.text()+"' (a " + Luan.type(obj) + " value)" ); | 60 throw exception( "attempt to perform arithmetic on '"+se.text()+"' (a " + Luan.type(obj) + " value)" ); |
62 } else { | 61 } else { |
63 throw exception( "attempt to perform arithmetic on a " + Luan.type(obj) + " value" ); | 62 throw exception( "attempt to perform arithmetic on a " + Luan.type(obj) + " value" ); |
139 | 138 |
140 public Object arithmetic(String op,Object o1,Object o2) throws LuanException { | 139 public Object arithmetic(String op,Object o1,Object o2) throws LuanException { |
141 LuanFunction fn = getBinHandler(op,o1,o2); | 140 LuanFunction fn = getBinHandler(op,o1,o2); |
142 if( fn != null ) | 141 if( fn != null ) |
143 return Luan.first(call(fn,op,new Object[]{o1,o2})); | 142 return Luan.first(call(fn,op,new Object[]{o1,o2})); |
144 String type = Luan.toNumber(o1)==null ? Luan.type(o1) : Luan.type(o2); | 143 String type = !(o1 instanceof Number) ? Luan.type(o1) : Luan.type(o2); |
145 throw exception("attempt to perform arithmetic on a "+type+" value"); | 144 throw exception("attempt to perform arithmetic on a "+type+" value"); |
146 } | 145 } |
147 | 146 |
148 } | 147 } |