Mercurial Hosting > luan
view 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 |
line wrap: on
line source
package luan.interp; import luan.Lua; import luan.LuaFunction; import luan.LuaException; import luan.LuaSource; // unary minus final class UnmExpr extends UnaryOpExpr { UnmExpr(LuaSource.Element se,Expr op) { super(se,op); } @Override public Object eval(LuaStateImpl lua) throws LuaException { Object o = op.eval(lua); Number n = Lua.toNumber(o); if( n != null ) return -n.doubleValue(); LuaFunction fn = lua.getHandlerFunction(se,"__unm",o); if( fn != null ) { return Lua.first(lua.call(fn,se,"__unm",o)); } throw new LuaException(lua,se,"attempt to perform arithmetic on a "+Lua.type(o)+" value"); } }