Mercurial Hosting > luan
view core/src/luan/impl/BinaryOpExpr.java @ 609:24b05963ba62
shell "clear" button now clears the session
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 09 Dec 2015 18:12:16 -0700 |
parents | 60c549d43988 |
children | 859c0dedc8b6 |
line wrap: on
line source
package luan.impl; import luan.Luan; import luan.LuanTable; import luan.LuanFunction; import luan.LuanException; import luan.LuanElement; abstract class BinaryOpExpr extends CodeImpl implements Expr { final Expr op1; final Expr op2; BinaryOpExpr(LuanElement el,Expr op1,Expr op2) { super(el); this.op1 = op1; this.op2 = op2; } Object arithmetic(LuanStateImpl luan,String op,Object o1,Object o2) throws LuanException { luan.push(el,null); try { LuanFunction fn = luan.getBinHandler(op,o1,o2); if( fn != null ) return Luan.first(fn.call(luan,new Object[]{o1,o2})); String type = !(o1 instanceof Number) ? Luan.type(o1) : Luan.type(o2); throw new LuanException(luan,"attempt to perform arithmetic on a "+type+" value"); } finally { luan.pop(); } } }