comparison src/luan/interp/UnmExpr.java @ 40:e3624b7cd603

implement stack trace git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 21 Dec 2012 10:45:54 +0000
parents 8a57ebfdfd78
children 57054fa43189
comparison
equal deleted inserted replaced
39:e5bcb1eeafc1 40:e3624b7cd603
2 2
3 import luan.Lua; 3 import luan.Lua;
4 import luan.LuaNumber; 4 import luan.LuaNumber;
5 import luan.LuaFunction; 5 import luan.LuaFunction;
6 import luan.LuaException; 6 import luan.LuaException;
7 import luan.LuaSource;
7 8
8 9
9 // unary minus 10 // unary minus
10 final class UnmExpr extends UnaryOpExpr { 11 final class UnmExpr extends UnaryOpExpr {
11 12
12 UnmExpr(Expr op) { 13 UnmExpr(LuaSource.Element se,Expr op) {
13 super(op); 14 super(se,op);
14 } 15 }
15 16
16 @Override public Object eval(LuaStateImpl lua) throws LuaException { 17 @Override public Object eval(LuaStateImpl lua) throws LuaException {
17 Object o = op.eval(lua); 18 Object o = op.eval(lua);
18 LuaNumber n = Lua.toNumber(o); 19 LuaNumber n = Lua.toNumber(o);
19 if( n != null ) 20 if( n != null )
20 return new LuaNumber( -n.value() ); 21 return new LuaNumber( -n.value() );
21 LuaFunction fn = lua.getHandlerFunction("__unm",o); 22 LuaFunction fn = lua.getHandlerFunction(se,"__unm",o);
22 if( fn != null ) 23 if( fn != null ) {
23 return Utils.first(fn.call(lua,o)); 24 return Lua.first(lua.call(fn,se,"__unm",o));
24 throw new LuaException("attempt to perform arithmetic on a "+Lua.type(o)+" value"); 25 }
26 throw new LuaException(lua,se,"attempt to perform arithmetic on a "+Lua.type(o)+" value");
25 } 27 }
26 } 28 }