comparison src/luan/interp/UnmExpr.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 64ecb7a3aad7
comparison
equal deleted inserted replaced
45:b1b14d09fc98 46:a443637829c1
1 package luan.interp; 1 package luan.interp;
2 2
3 import luan.Lua; 3 import luan.Lua;
4 import luan.LuaNumber;
5 import luan.LuaFunction; 4 import luan.LuaFunction;
6 import luan.LuaException; 5 import luan.LuaException;
7 import luan.LuaSource; 6 import luan.LuaSource;
8 7
9 8
14 super(se,op); 13 super(se,op);
15 } 14 }
16 15
17 @Override public Object eval(LuaStateImpl lua) throws LuaException { 16 @Override public Object eval(LuaStateImpl lua) throws LuaException {
18 Object o = op.eval(lua); 17 Object o = op.eval(lua);
19 LuaNumber n = Lua.toNumber(o); 18 Number n = Lua.toNumber(o);
20 if( n != null ) 19 if( n != null )
21 return LuaNumber.of( -n.value() ); 20 return -n.doubleValue();
22 LuaFunction fn = lua.getHandlerFunction(se,"__unm",o); 21 LuaFunction fn = lua.getHandlerFunction(se,"__unm",o);
23 if( fn != null ) { 22 if( fn != null ) {
24 return Lua.first(lua.call(fn,se,"__unm",o)); 23 return Lua.first(lua.call(fn,se,"__unm",o));
25 } 24 }
26 throw new LuaException(lua,se,"attempt to perform arithmetic on a "+Lua.type(o)+" value"); 25 throw new LuaException(lua,se,"attempt to perform arithmetic on a "+Lua.type(o)+" value");