comparison core/src/luan/impl/UnmExpr.java @ 404:d55e873e1f0d

metatables now only apply to tables
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 29 Apr 2015 07:04:40 -0600
parents 3dcb0f9bee82
children bbad2d06f728
comparison
equal deleted inserted replaced
403:637f7ad85654 404:d55e873e1f0d
3 import luan.Luan; 3 import luan.Luan;
4 import luan.LuanFunction; 4 import luan.LuanFunction;
5 import luan.LuanException; 5 import luan.LuanException;
6 import luan.LuanSource; 6 import luan.LuanSource;
7 import luan.LuanBit; 7 import luan.LuanBit;
8 import luan.LuanTable;
8 9
9 10
10 // unary minus 11 // unary minus
11 final class UnmExpr extends UnaryOpExpr { 12 final class UnmExpr extends UnaryOpExpr {
12 13
18 Object o = op.eval(luan); 19 Object o = op.eval(luan);
19 Number n = Luan.toNumber(o); 20 Number n = Luan.toNumber(o);
20 if( n != null ) 21 if( n != null )
21 return -n.doubleValue(); 22 return -n.doubleValue();
22 LuanBit bit = luan.bit(se); 23 LuanBit bit = luan.bit(se);
23 LuanFunction fn = bit.getHandlerFunction("__unm",o); 24 if( o instanceof LuanTable ) {
24 if( fn != null ) { 25 LuanFunction fn = bit.getHandlerFunction("__unm",(LuanTable)o);
25 return Luan.first(bit.call(fn,"__unm",new Object[]{o})); 26 if( fn != null ) {
27 return Luan.first(bit.call(fn,"__unm",new Object[]{o}));
28 }
26 } 29 }
27 throw bit.exception("attempt to perform arithmetic on a "+Luan.type(o)+" value"); 30 throw bit.exception("attempt to perform arithmetic on a "+Luan.type(o)+" value");
28 } 31 }
29 } 32 }