Mercurial Hosting > luan
view core/src/luan/impl/UnmExpr.java @ 498:ee55be414a34
Http.response is now mostly luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 May 2015 00:25:35 -0600 |
parents | b48cfa14ba60 |
children | 4723d22062ce |
line wrap: on
line source
package luan.impl; import luan.Luan; import luan.LuanFunction; import luan.LuanException; import luan.LuanElement; import luan.LuanBit; import luan.LuanTable; // unary minus final class UnmExpr extends UnaryOpExpr { UnmExpr(LuanElement el,Expr op) { super(el,op); } @Override public Object eval(LuanStateImpl luan) throws LuanException { Object o = op.eval(luan); if( o instanceof Number ) return -((Number)o).doubleValue(); LuanBit bit = luan.bit(el); if( o instanceof LuanTable ) { LuanFunction fn = bit.getHandlerFunction("__unm",(LuanTable)o); if( fn != null ) { return Luan.first(bit.call(fn,"__unm",new Object[]{o})); } } throw bit.exception("attempt to perform arithmetic on a "+Luan.type(o)+" value"); } }