Mercurial Hosting > luan
comparison src/luan/interp/UnmExpr.java @ 48:64ecb7a3aad7
rename Lua to Luan
git-svn-id: https://luan-java.googlecode.com/svn/trunk@49 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 28 Dec 2012 03:29:12 +0000 |
parents | a443637829c1 |
children | 8ede219cd111 |
comparison
equal
deleted
inserted
replaced
47:659c7139e903 | 48:64ecb7a3aad7 |
---|---|
1 package luan.interp; | 1 package luan.interp; |
2 | 2 |
3 import luan.Lua; | 3 import luan.Luan; |
4 import luan.LuaFunction; | 4 import luan.LuanFunction; |
5 import luan.LuaException; | 5 import luan.LuanException; |
6 import luan.LuaSource; | 6 import luan.LuanSource; |
7 | 7 |
8 | 8 |
9 // unary minus | 9 // unary minus |
10 final class UnmExpr extends UnaryOpExpr { | 10 final class UnmExpr extends UnaryOpExpr { |
11 | 11 |
12 UnmExpr(LuaSource.Element se,Expr op) { | 12 UnmExpr(LuanSource.Element se,Expr op) { |
13 super(se,op); | 13 super(se,op); |
14 } | 14 } |
15 | 15 |
16 @Override public Object eval(LuaStateImpl lua) throws LuaException { | 16 @Override public Object eval(LuanStateImpl lua) throws LuanException { |
17 Object o = op.eval(lua); | 17 Object o = op.eval(lua); |
18 Number n = Lua.toNumber(o); | 18 Number n = Luan.toNumber(o); |
19 if( n != null ) | 19 if( n != null ) |
20 return -n.doubleValue(); | 20 return -n.doubleValue(); |
21 LuaFunction fn = lua.getHandlerFunction(se,"__unm",o); | 21 LuanFunction fn = lua.getHandlerFunction(se,"__unm",o); |
22 if( fn != null ) { | 22 if( fn != null ) { |
23 return Lua.first(lua.call(fn,se,"__unm",o)); | 23 return Luan.first(lua.call(fn,se,"__unm",o)); |
24 } | 24 } |
25 throw new LuaException(lua,se,"attempt to perform arithmetic on a "+Lua.type(o)+" value"); | 25 throw new LuanException(lua,se,"attempt to perform arithmetic on a "+Luan.type(o)+" value"); |
26 } | 26 } |
27 } | 27 } |