Mercurial Hosting > luan
diff src/luan/impl/LuanImpl.java @ 1335:e0cf0d108a77
major cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 14 Feb 2019 03:10:45 -0700 |
parents | c88b486a9511 |
children | 465b4a0dae4a |
line wrap: on
line diff
--- a/src/luan/impl/LuanImpl.java Tue Feb 12 22:53:57 2019 -0700 +++ b/src/luan/impl/LuanImpl.java Thu Feb 14 03:10:45 2019 -0700 @@ -29,75 +29,75 @@ throw new LuanException( "attempt to get length of a " + Luan.type(o) + " value" ); } - public static Object unm(Luan luan,Object o) throws LuanException { + public static Object unm(Object o) throws LuanException { if( o instanceof Number ) return -((Number)o).doubleValue(); if( o instanceof LuanTable ) { LuanFunction fn = Luan.getHandlerFunction("__unm",(LuanTable)o); if( fn != null ) { - return Luan.first(fn.call(luan,new Object[]{o})); + return Luan.first(fn.call(o)); } } throw new LuanException("attempt to perform arithmetic on a "+Luan.type(o)+" value"); } - private static Object arithmetic(Luan luan,String op,Object o1,Object o2) throws LuanException { + private static Object arithmetic(String op,Object o1,Object o2) throws LuanException { LuanFunction fn = Luan.getBinHandler(op,o1,o2); if( fn != null ) - return Luan.first(fn.call(luan,new Object[]{o1,o2})); + return Luan.first(fn.call(o1,o2)); String type = !(o1 instanceof Number) ? Luan.type(o1) : Luan.type(o2); throw new LuanException("attempt to perform arithmetic on a "+type+" value"); } - public static Object pow(Luan luan,Object o1,Object o2) throws LuanException { + public static Object pow(Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return Math.pow( ((Number)o1).doubleValue(), ((Number)o2).doubleValue() ); - return arithmetic(luan,"__pow",o1,o2); + return arithmetic("__pow",o1,o2); } - public static Object mul(Luan luan,Object o1,Object o2) throws LuanException { + public static Object mul(Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return ((Number)o1).doubleValue() * ((Number)o2).doubleValue(); - return arithmetic(luan,"__mul",o1,o2); + return arithmetic("__mul",o1,o2); } - public static Object div(Luan luan,Object o1,Object o2) throws LuanException { + public static Object div(Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return ((Number)o1).doubleValue() / ((Number)o2).doubleValue(); - return arithmetic(luan,"__div",o1,o2); + return arithmetic("__div",o1,o2); } - public static Object mod(Luan luan,Object o1,Object o2) throws LuanException { + public static Object mod(Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) { double d1 = ((Number)o1).doubleValue(); double d2 = ((Number)o2).doubleValue(); return d1 - Math.floor(d1/d2)*d2; } - return arithmetic(luan,"__mod",o1,o2); + return arithmetic("__mod",o1,o2); } - public static Object add(Luan luan,Object o1,Object o2) throws LuanException { + public static Object add(Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return ((Number)o1).doubleValue() + ((Number)o2).doubleValue(); - return arithmetic(luan,"__add",o1,o2); + return arithmetic("__add",o1,o2); } - public static Object sub(Luan luan,Object o1,Object o2) throws LuanException { + public static Object sub(Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return ((Number)o1).doubleValue() - ((Number)o2).doubleValue(); - return arithmetic(luan,"__sub",o1,o2); + return arithmetic("__sub",o1,o2); } - public static Object concat(Luan luan,Object o1,Object o2) throws LuanException { + public static Object concat(Object o1,Object o2) throws LuanException { LuanFunction fn = Luan.getBinHandler("__concat",o1,o2); if( fn != null ) - return Luan.first(fn.call(luan,new Object[]{o1,o2})); + return Luan.first(fn.call(o1,o2)); String s1 = Luan.luanToString(o1); String s2 = Luan.luanToString(o2); return s1 + s2; } - public static boolean eq(Luan luan,Object o1,Object o2) throws LuanException { + public static boolean eq(Object o1,Object o2) throws LuanException { if( o1 == o2 || o1 != null && o1.equals(o2) ) return true; if( o1 instanceof Number && o2 instanceof Number ) { @@ -122,10 +122,10 @@ if( f == null || !f.equals(mt2.rawGet("__eq")) ) return false; LuanFunction fn = Luan.checkFunction(f); - return Luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) ); + return Luan.checkBoolean( Luan.first(fn.call(o1,o2)) ); } - public static boolean le(Luan luan,Object o1,Object o2) throws LuanException { + public static boolean le(Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) { Number n1 = (Number)o1; Number n2 = (Number)o2; @@ -138,15 +138,15 @@ } LuanFunction fn = Luan.getBinHandler("__le",o1,o2); if( fn != null ) - return Luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) ); + return Luan.checkBoolean( Luan.first(fn.call(o1,o2)) ); fn = Luan.getBinHandler("__lt",o1,o2); if( fn != null ) - return !Luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o2,o1})) ); + return !Luan.checkBoolean( Luan.first(fn.call(o2,o1)) ); throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); } - public static boolean lt(Luan luan,Object o1,Object o2) throws LuanException { - return luan.isLessThan(o1,o2); + public static boolean lt(Object o1,Object o2) throws LuanException { + return Luan.isLessThan(o1,o2); } public static boolean cnd(Object o) throws LuanException {