comparison src/luan/LuaState.java @ 46:a443637829c1

remove LuaNumber git-svn-id: https://luan-java.googlecode.com/svn/trunk@47 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 27 Dec 2012 01:48:36 +0000
parents 57054fa43189
children
comparison
equal deleted inserted replaced
45:b1b14d09fc98 46:a443637829c1
44 if( s == null ) 44 if( s == null )
45 throw new LuaException( this, el, "attempt to use a " + Lua.type(obj) + " as a string" ); 45 throw new LuaException( this, el, "attempt to use a " + Lua.type(obj) + " as a string" );
46 return s; 46 return s;
47 } 47 }
48 48
49 public final LuaNumber checkNumber(LuaElement el,Object obj) throws LuaException { 49 public final Number checkNumber(LuaElement el,Object obj) throws LuaException {
50 LuaNumber n = Lua.toNumber(obj); 50 Number n = Lua.toNumber(obj);
51 if( n == null ) 51 if( n == null )
52 throw new LuaException( this, el, "attempt to perform arithmetic on a " + Lua.type(obj) + " value" ); 52 throw new LuaException( this, el, "attempt to perform arithmetic on a " + Lua.type(obj) + " value" );
53 return n; 53 return n;
54 } 54 }
55 55
63 LuaFunction fn = getHandlerFunction(el,"__tostring",obj); 63 LuaFunction fn = getHandlerFunction(el,"__tostring",obj);
64 if( fn != null ) 64 if( fn != null )
65 return checkString( el, Lua.first( call(fn,el,"__tostring",obj) ) ); 65 return checkString( el, Lua.first( call(fn,el,"__tostring",obj) ) );
66 if( obj == null ) 66 if( obj == null )
67 return "nil"; 67 return "nil";
68 if( obj instanceof Number )
69 return Lua.toString((Number)obj);
68 if( obj instanceof LuaException ) { 70 if( obj instanceof LuaException ) {
69 LuaException le = (LuaException)obj; 71 LuaException le = (LuaException)obj;
70 return le.getMessage(); 72 return le.getMessage();
71 } 73 }
72 return obj.toString(); 74 return obj.toString();
91 return f1; 93 return f1;
92 return getHandlerFunction(el,op,o2); 94 return getHandlerFunction(el,op,o2);
93 } 95 }
94 96
95 public final boolean isLessThan(LuaElement el,Object o1,Object o2) throws LuaException { 97 public final boolean isLessThan(LuaElement el,Object o1,Object o2) throws LuaException {
96 if( o1 instanceof LuaNumber && o2 instanceof LuaNumber ) { 98 if( o1 instanceof Number && o2 instanceof Number ) {
97 LuaNumber n1 = (LuaNumber)o1; 99 Number n1 = (Number)o1;
98 LuaNumber n2 = (LuaNumber)o2; 100 Number n2 = (Number)o2;
99 return n1.compareTo(n2) < 0; 101 return n1.doubleValue() < n2.doubleValue();
100 } 102 }
101 if( o1 instanceof String && o2 instanceof String ) { 103 if( o1 instanceof String && o2 instanceof String ) {
102 String s1 = (String)o1; 104 String s1 = (String)o1;
103 String s2 = (String)o2; 105 String s2 = (String)o2;
104 return s1.compareTo(s2) < 0; 106 return s1.compareTo(s2) < 0;