comparison src/luan/impl/UnmExpr.java @ 166:4eaee12f6c65

move luan/interp to impl git-svn-id: https://luan-java.googlecode.com/svn/trunk@167 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 22 Jun 2014 04:17:38 +0000
parents src/luan/interp/UnmExpr.java@f5af13062b10
children
comparison
equal deleted inserted replaced
165:94bbc4cbc106 166:4eaee12f6c65
1 package luan.impl;
2
3 import luan.Luan;
4 import luan.LuanFunction;
5 import luan.LuanException;
6 import luan.LuanSource;
7 import luan.LuanBit;
8
9
10 // unary minus
11 final class UnmExpr extends UnaryOpExpr {
12
13 UnmExpr(LuanSource.Element se,Expr op) {
14 super(se,op);
15 }
16
17 @Override public Object eval(LuanStateImpl luan) throws LuanException {
18 Object o = op.eval(luan);
19 Number n = Luan.toNumber(o);
20 if( n != null )
21 return -n.doubleValue();
22 LuanBit bit = luan.bit(se);
23 LuanFunction fn = bit.getHandlerFunction("__unm",o);
24 if( fn != null ) {
25 return Luan.first(bit.call(fn,"__unm",new Object[]{o}));
26 }
27 throw bit.exception("attempt to perform arithmetic on a "+Luan.type(o)+" value");
28 }
29 }