diff src/luan/impl/LuanImpl.java @ 1563:8fbcc4747091

remove LuanFunction.luan
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 09 Nov 2020 01:37:57 -0700
parents b89212fd04b5
children 364859d29ff5
line wrap: on
line diff
--- a/src/luan/impl/LuanImpl.java	Sun Nov 08 16:50:59 2020 -0700
+++ b/src/luan/impl/LuanImpl.java	Mon Nov 09 01:37:57 2020 -0700
@@ -13,7 +13,7 @@
 public final class LuanImpl {
 	private LuanImpl() {}  // never
 
-	public static int len(Object o) throws LuanException {
+	public static int len(Luan luan,Object o) throws LuanException {
 		if( o instanceof String ) {
 			String s = (String)o;
 			return s.length();
@@ -24,80 +24,80 @@
 		}
 		if( o instanceof LuanTable ) {
 			LuanTable t = (LuanTable)o;
-			return t.length();
+			return t.length(luan);
 		}
 		throw new LuanException( "attempt to get length of a " + Luan.type(o) + " value" );
 	}
 
-	public static Object unm(Object o) throws LuanException {
+	public static Object unm(Luan luan,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(o));
+				return Luan.first(fn.call(luan,o));
 			}
 		}
 		throw new LuanException("attempt to perform arithmetic on a "+Luan.type(o)+" value");
 	}
 
-	private static Object arithmetic(String op,Object o1,Object o2) throws LuanException {
+	private static Object arithmetic(Luan luan,String op,Object o1,Object o2) throws LuanException {
 		LuanFunction fn = Luan.getBinHandler(op,o1,o2);
 		if( fn != null )
-			return Luan.first(fn.call(o1,o2));
+			return Luan.first(fn.call(luan,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(Object o1,Object o2) throws LuanException {
+	public static Object pow(Luan luan,Object o1,Object o2) throws LuanException {
 		if( o1 instanceof Number && o2 instanceof Number )
 			return Math.pow( ((Number)o1).doubleValue(), ((Number)o2).doubleValue() );
-		return arithmetic("__pow",o1,o2);
+		return arithmetic(luan,"__pow",o1,o2);
 	}
 
-	public static Object mul(Object o1,Object o2) throws LuanException {
+	public static Object mul(Luan luan,Object o1,Object o2) throws LuanException {
 		if( o1 instanceof Number && o2 instanceof Number )
 			return ((Number)o1).doubleValue() * ((Number)o2).doubleValue();
-		return arithmetic("__mul",o1,o2);
+		return arithmetic(luan,"__mul",o1,o2);
 	}
 
-	public static Object div(Object o1,Object o2) throws LuanException {
+	public static Object div(Luan luan,Object o1,Object o2) throws LuanException {
 		if( o1 instanceof Number && o2 instanceof Number )
 			return ((Number)o1).doubleValue() / ((Number)o2).doubleValue();
-		return arithmetic("__div",o1,o2);
+		return arithmetic(luan,"__div",o1,o2);
 	}
 
-	public static Object mod(Object o1,Object o2) throws LuanException {
+	public static Object mod(Luan luan,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("__mod",o1,o2);
+		return arithmetic(luan,"__mod",o1,o2);
 	}
 
-	public static Object add(Object o1,Object o2) throws LuanException {
+	public static Object add(Luan luan,Object o1,Object o2) throws LuanException {
 		if( o1 instanceof Number && o2 instanceof Number )
 			return ((Number)o1).doubleValue() + ((Number)o2).doubleValue();
-		return arithmetic("__add",o1,o2);
+		return arithmetic(luan,"__add",o1,o2);
 	}
 
-	public static Object sub(Object o1,Object o2) throws LuanException {
+	public static Object sub(Luan luan,Object o1,Object o2) throws LuanException {
 		if( o1 instanceof Number && o2 instanceof Number )
 			return ((Number)o1).doubleValue() - ((Number)o2).doubleValue();
-		return arithmetic("__sub",o1,o2);
+		return arithmetic(luan,"__sub",o1,o2);
 	}
 
-	public static Object concat(Object o1,Object o2) throws LuanException {
+	public static Object concat(Luan luan,Object o1,Object o2) throws LuanException {
 		LuanFunction fn = Luan.getBinHandler("__concat",o1,o2);
 		if( fn != null )
-			return Luan.first(fn.call(o1,o2));
-		String s1 = Luan.luanToString(o1);
-		String s2 = Luan.luanToString(o2);
+			return Luan.first(fn.call(luan,o1,o2));
+		String s1 = luan.luanToString(o1);
+		String s2 = luan.luanToString(o2);
 		return s1 + s2;
 	}
 
-	public static boolean eq(Object o1,Object o2) throws LuanException {
+	public static boolean eq(Luan luan,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(o1,o2)) );
+		return Luan.checkBoolean( Luan.first(fn.call(luan,o1,o2)) );
 	}
 
-	public static boolean le(Object o1,Object o2) throws LuanException {
+	public static boolean le(Luan luan,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(o1,o2)) );
+			return Luan.checkBoolean( Luan.first(fn.call(luan,o1,o2)) );
 		fn = Luan.getBinHandler("__lt",o1,o2);
 		if( fn != null )
-			return !Luan.checkBoolean( Luan.first(fn.call(o2,o1)) );
+			return !Luan.checkBoolean( Luan.first(fn.call(luan,o2,o1)) );
 		throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
 	}
 
-	public static boolean lt(Object o1,Object o2) throws LuanException {
-		return Luan.isLessThan(o1,o2);
+	public static boolean lt(Luan luan,Object o1,Object o2) throws LuanException {
+		return luan.isLessThan(o1,o2);
 	}
 
 	public static boolean cnd(Object o) throws LuanException {