diff src/luan/modules/BasicLuan.java @ 1563:8fbcc4747091

remove LuanFunction.luan
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 09 Nov 2020 01:37:57 -0700
parents b89212fd04b5
children c922446f53aa
line wrap: on
line diff
--- a/src/luan/modules/BasicLuan.java	Sun Nov 08 16:50:59 2020 -0700
+++ b/src/luan/modules/BasicLuan.java	Mon Nov 09 01:37:57 2020 -0700
@@ -15,6 +15,7 @@
 import luan.LuanFunction;
 import luan.LuanException;
 import luan.LuanCloner;
+import luan.LuanCloneable;
 import luan.LuanImmutabler;
 import luan.modules.parsers.LuanToString;
 
@@ -45,33 +46,39 @@
 		return load(luan,src,fileName,null);
 	}
 */
-	public static LuanFunction pairs(final LuanTable t) throws LuanException {
+	public static LuanFunction pairs(Luan luan,final LuanTable t) throws LuanException {
 		Utils.checkNotNull(t);
-		return t.pairs();
+		return t.pairs(luan);
 	}
 
-	private static class Ipairs extends LuanFunction {
+	private static class Ipairs extends LuanFunction implements LuanCloneable, Cloneable {
 		List<Object> list;
 		int i = 0;
 		final int size;
 
 		Ipairs(LuanTable t) {
-			super(true);
 			list = t.asList();
 			size = list.size();
 		}
 
-		@Override public Object[] call(Object[] args) {
+		@Override public Object[] call(Luan luan,Object[] args) {
 			if( i >= size )
 				return LuanFunction.NOTHING;
 			Object val = list.get(i++);
 			return new Object[]{i,val};
 		}
 
-		@Override protected void completeClone(LuanFunction dc,LuanCloner cloner) {
+		@Override public final Ipairs shallowClone() {
+			try {
+				return (Ipairs)clone();
+			} catch(CloneNotSupportedException e) {
+				throw new RuntimeException(e);
+			}
+		}
+
+		@Override public final void deepenClone(LuanCloneable dc,LuanCloner cloner) {
 			Ipairs clone = (Ipairs)dc;
 			clone.list = (List)cloner.clone(list);
-			super.completeClone(dc,cloner);
 		}
 
 		@Override public void makeImmutable(LuanImmutabler immutabler) throws LuanException {
@@ -124,12 +131,12 @@
 		throw new LuanException( "bad argument #1 to 'raw_len' (table or string expected)" );
 	}
 
-	public static String to_string(Object v) throws LuanException {
-		return Luan.luanToString(v);
+	public static String to_string(Luan luan,Object v) throws LuanException {
+		return luan.luanToString(v);
 	}
 
 	public static LuanTable new_error(Luan luan,Object msg) throws LuanException {
-		String s = Luan.luanToString(msg);
+		String s = luan.luanToString(msg);
 		LuanTable tbl = new LuanException(s).table(luan);
 		tbl.rawPut( "message", msg );
 		return tbl;
@@ -155,10 +162,10 @@
 		final double step = stepV==null ? 1.0 : stepV;
 		if( step == 0.0 )
 			throw new LuanException("bad argument #3 (step may not be zero)");
-		return new LuanFunction(false) {
+		return new LuanFunction() {
 			double v = from;
 
-			@Override public Object call(Object[] args) {
+			@Override public Object call(Luan luan,Object[] args) {
 				if( step > 0.0 && v > to || step < 0.0 && v < to )
 					return LuanFunction.NOTHING;
 				double rtn = v;
@@ -168,26 +175,32 @@
 		};
 	}
 
-	private static class Values extends LuanFunction {
+	private static class Values extends LuanFunction implements LuanCloneable, Cloneable {
 		Object[] args;
 		int i = 0;
 
 		Values(Object[] args) {
-			super(true);
 			this.args = args;
 		}
 
-		@Override public Object[] call(Object[] x) {
+		@Override public Object[] call(Luan luan,Object[] x) {
 			if( i >= args.length )
 				return LuanFunction.NOTHING;
 			Object val = args[i++];
 			return new Object[]{i,val};
 		}
 
-		@Override protected void completeClone(LuanFunction dc,LuanCloner cloner) {
+		@Override public final Values shallowClone() {
+			try {
+				return (Values)clone();
+			} catch(CloneNotSupportedException e) {
+				throw new RuntimeException(e);
+			}
+		}
+
+		@Override public final void deepenClone(LuanCloneable dc,LuanCloner cloner) {
 			Values clone = (Values)dc;
 			clone.args = (Object[])cloner.clone(args);
-			super.completeClone(dc,cloner);
 		}
 
 		@Override public void makeImmutable(LuanImmutabler immutabler) throws LuanException {
@@ -218,8 +231,8 @@
 		}
 	}
 
-	public static String stringify(Luan luan,Object obj,LuanTable options,LuanTable subOptions) throws LuanException {
-		LuanToString lts = new LuanToString(luan,options,subOptions);
+	public static String stringify(Object obj,LuanTable options,LuanTable subOptions) throws LuanException {
+		LuanToString lts = new LuanToString(options,subOptions);
 		return lts.toString(obj);
 	}