changeset 1334:c88b486a9511

make some Luan methods static
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 12 Feb 2019 22:53:57 -0700
parents 25746915a241
children e0cf0d108a77
files src/luan/Luan.java src/luan/impl/LuanImpl.java src/luan/modules/BasicLuan.java src/luan/modules/IoLuan.java src/luan/modules/StringLuan.java src/luan/modules/TableLuan.java src/luan/modules/logging/LuanLogger.java
diffstat 7 files changed, 34 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
diff -r 25746915a241 -r c88b486a9511 src/luan/Luan.java
--- a/src/luan/Luan.java	Tue Feb 12 22:33:40 2019 -0700
+++ b/src/luan/Luan.java	Tue Feb 12 22:53:57 2019 -0700
@@ -81,7 +81,7 @@
 		return PackageLuan.require(this,modName);
 	}
 
-	public String toString(Object obj) throws LuanException {
+	public static String luanToString(Object obj) throws LuanException {
 		if( obj instanceof LuanTable ) {
 			LuanTable tbl = (LuanTable)obj;
 			return tbl.toStringLuan();
@@ -123,7 +123,7 @@
 		throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
 	}
 
-	public LuanFunction getBinHandler(String op,Object o1,Object o2) throws LuanException {
+	public static LuanFunction getBinHandler(String op,Object o1,Object o2) throws LuanException {
 		if( o1 instanceof LuanTable ) {
 			LuanFunction f1 = getHandlerFunction(op,(LuanTable)o1);
 			if( f1 != null )
@@ -132,7 +132,7 @@
 		return o2 instanceof LuanTable ? getHandlerFunction(op,(LuanTable)o2) : null;
 	}
 
-	public LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException {
+	public static LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException {
 		Object f = t.getHandler(op);
 		if( f == null )
 			return null;
diff -r 25746915a241 -r c88b486a9511 src/luan/impl/LuanImpl.java
--- a/src/luan/impl/LuanImpl.java	Tue Feb 12 22:33:40 2019 -0700
+++ b/src/luan/impl/LuanImpl.java	Tue Feb 12 22:53:57 2019 -0700
@@ -33,7 +33,7 @@
 		if( o instanceof Number )
 			return -((Number)o).doubleValue();
 		if( o instanceof LuanTable ) {
-			LuanFunction fn = luan.getHandlerFunction("__unm",(LuanTable)o);
+			LuanFunction fn = Luan.getHandlerFunction("__unm",(LuanTable)o);
 			if( fn != null ) {
 				return Luan.first(fn.call(luan,new Object[]{o}));
 			}
@@ -42,7 +42,7 @@
 	}
 
 	private static Object arithmetic(Luan luan,String op,Object o1,Object o2) throws LuanException {
-		LuanFunction fn = luan.getBinHandler(op,o1,o2);
+		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);
@@ -89,11 +89,11 @@
 	}
 
 	public static Object concat(Luan luan,Object o1,Object o2) throws LuanException {
-		LuanFunction fn = luan.getBinHandler("__concat",o1,o2);
+		LuanFunction fn = Luan.getBinHandler("__concat",o1,o2);
 		if( fn != null )
 			return Luan.first(fn.call(luan,new Object[]{o1,o2}));
-		String s1 = luan.toString(o1);
-		String s2 = luan.toString(o2);
+		String s1 = Luan.luanToString(o1);
+		String s2 = Luan.luanToString(o2);
 		return s1 + s2;
 	}
 
@@ -136,10 +136,10 @@
 			String s2 = (String)o2;
 			return s1.compareTo(s2) <= 0;
 		}
-		LuanFunction fn = luan.getBinHandler("__le",o1,o2);
+		LuanFunction fn = Luan.getBinHandler("__le",o1,o2);
 		if( fn != null )
 			return Luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) );
-		fn = luan.getBinHandler("__lt",o1,o2);
+		fn = Luan.getBinHandler("__lt",o1,o2);
 		if( fn != null )
 			return !Luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o2,o1})) );
 		throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
diff -r 25746915a241 -r c88b486a9511 src/luan/modules/BasicLuan.java
--- a/src/luan/modules/BasicLuan.java	Tue Feb 12 22:33:40 2019 -0700
+++ b/src/luan/modules/BasicLuan.java	Tue Feb 12 22:53:57 2019 -0700
@@ -103,12 +103,12 @@
 		throw new LuanException( "bad argument #1 to 'raw_len' (table or string expected)" );
 	}
 
-	public static String to_string(Luan luan,Object v) throws LuanException {
-		return luan.toString(v);
+	public static String to_string(Object v) throws LuanException {
+		return Luan.luanToString(v);
 	}
 
 	public static LuanTable new_error(Luan luan,Object msg) throws LuanException {
-		String s = luan.toString(msg);
+		String s = Luan.luanToString(msg);
 		LuanTable tbl = new LuanException(s).table(luan);
 		tbl.rawPut( "message", msg );
 		return tbl;
diff -r 25746915a241 -r c88b486a9511 src/luan/modules/IoLuan.java
--- a/src/luan/modules/IoLuan.java	Tue Feb 12 22:33:40 2019 -0700
+++ b/src/luan/modules/IoLuan.java	Tue Feb 12 22:53:57 2019 -0700
@@ -46,7 +46,7 @@
 
 	public interface LuanWriter {
 		public Object out();
-		public void write(Luan luan,Object... args) throws LuanException, IOException;
+		public void write(Object... args) throws LuanException, IOException;
 		public void close() throws IOException;
 	}
 
@@ -57,9 +57,9 @@
 				return out;
 			}
 
-			public void write(Luan luan,Object... args) throws LuanException {
+			public void write(Object... args) throws LuanException {
 				for( Object obj : args ) {
-					out.print( luan.toString(obj) );
+					out.print( Luan.luanToString(obj) );
 				}
 			}
 
@@ -76,9 +76,9 @@
 				return out;
 			}
 
-			public void write(Luan luan,Object... args) throws LuanException, IOException {
+			public void write(Object... args) throws LuanException, IOException {
 				for( Object obj : args ) {
-					out.write( luan.toString(obj) );
+					out.write( Luan.luanToString(obj) );
 				}
 			}
 
@@ -369,9 +369,9 @@
 					return out;
 				}
 	
-				public void write(Luan luan,Object... args) throws LuanException, IOException {
+				public void write(Object... args) throws LuanException, IOException {
 					for( Object obj : args ) {
-						out.write( luan.toString(obj) );
+						out.write( Luan.luanToString(obj) );
 					}
 				}
 	
diff -r 25746915a241 -r c88b486a9511 src/luan/modules/StringLuan.java
--- a/src/luan/modules/StringLuan.java	Tue Feb 12 22:33:40 2019 -0700
+++ b/src/luan/modules/StringLuan.java	Tue Feb 12 22:53:57 2019 -0700
@@ -168,7 +168,7 @@
 				String match = m.groupCount()==0 ? m.group() : m.group(1);
 				Object val = t.get(match);
 				if( val != null ) {
-					String replacement = luan.toString(val);
+					String replacement = Luan.luanToString(val);
 					m.appendReplacement(sb,replacement);
 				}
 				i++;
@@ -193,7 +193,7 @@
 				}
 				Object val = Luan.first( fn.call(luan,args) );
 				if( val != null ) {
-					String replacement = luan.toString(val);
+					String replacement = Luan.luanToString(val);
 					m.appendReplacement(sb,replacement);
 				}
 				i++;
@@ -209,10 +209,10 @@
 		return String.format(format,args);
 	}
 
-	public static String concat(Luan luan,Object... args) throws LuanException {
+	public static String concat(Object... args) throws LuanException {
 		StringBuilder sb = new StringBuilder();
 		for( Object arg : args ) {
-			sb.append( luan.toString(arg) );
+			sb.append( Luan.luanToString(arg) );
 		}
 		return sb.toString();
 	}
diff -r 25746915a241 -r c88b486a9511 src/luan/modules/TableLuan.java
--- a/src/luan/modules/TableLuan.java	Tue Feb 12 22:33:40 2019 -0700
+++ b/src/luan/modules/TableLuan.java	Tue Feb 12 22:53:57 2019 -0700
@@ -14,7 +14,7 @@
 
 public final class TableLuan {
 
-	public static String concat(Luan luan,LuanTable list,String sep,Integer i,Integer j) throws LuanException {
+	public static String concat(LuanTable list,String sep,Integer i,Integer j) throws LuanException {
 		int first = i==null ? 1 : i;
 		int last = j==null ? list.length() : j;
 		StringBuilder buf = new StringBuilder();
@@ -24,7 +24,7 @@
 				break;
 			if( sep!=null && k > first )
 				buf.append(sep);
-			String s = luan.toString(val);
+			String s = Luan.luanToString(val);
 			buf.append(s);
 		}
 		return buf.toString();
diff -r 25746915a241 -r c88b486a9511 src/luan/modules/logging/LuanLogger.java
--- a/src/luan/modules/logging/LuanLogger.java	Tue Feb 12 22:33:40 2019 -0700
+++ b/src/luan/modules/logging/LuanLogger.java	Tue Feb 12 22:53:57 2019 -0700
@@ -13,20 +13,20 @@
 		this.logger = getLogger(luan,name);
 	}
 
-	public void error(Luan luan,Object obj) throws LuanException {
-		logger.error( luan.toString(obj) );
+	public void error(Object obj) throws LuanException {
+		logger.error( Luan.luanToString(obj) );
 	}
 
-	public void warn(Luan luan,Object obj) throws LuanException {
-		logger.warn( luan.toString(obj) );
+	public void warn(Object obj) throws LuanException {
+		logger.warn( Luan.luanToString(obj) );
 	}
 
-	public void info(Luan luan,Object obj) throws LuanException {
-		logger.info( luan.toString(obj) );
+	public void info(Object obj) throws LuanException {
+		logger.info( Luan.luanToString(obj) );
 	}
 
-	public void debug(Luan luan,Object obj) throws LuanException {
-		logger.debug( luan.toString(obj) );
+	public void debug(Object obj) throws LuanException {
+		logger.debug( Luan.luanToString(obj) );
 	}