changeset 443:bf5e62a9090c

remove toBoolean() and to_boolean()
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 May 2015 14:55:51 -0600
parents 75ccb4da803f
children e45bcaf6f5fe
files core/src/luan/Luan.java core/src/luan/LuanBit.java core/src/luan/LuanJavaFunction.java core/src/luan/LuanState.java core/src/luan/impl/AndExpr.java core/src/luan/impl/EqExpr.java core/src/luan/impl/LeExpr.java core/src/luan/impl/OrExpr.java core/src/luan/modules/BasicLuan.java core/src/luan/modules/Luan.luan core/src/luan/modules/StringLuan.java core/src/luan/modules/TableLuan.java web/src/luan/modules/web/HttpServicer.java
diffstat 13 files changed, 18 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/Luan.java
--- a/core/src/luan/Luan.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/Luan.java	Mon May 04 14:55:51 2015 -0600
@@ -47,10 +47,6 @@
 		return "userdata";
 	}
 
-	public static boolean toBoolean(Object obj) {
-		return obj != null && !Boolean.FALSE.equals(obj);
-	}
-
 	public static Number toNumber(Object obj) {
 		return toNumber(obj,null);
 	}
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/LuanBit.java
--- a/core/src/luan/LuanBit.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/LuanBit.java	Mon May 04 14:55:51 2015 -0600
@@ -133,7 +133,7 @@
 		}
 		LuanFunction fn = getBinHandler("__lt",o1,o2);
 		if( fn != null )
-			return Luan.toBoolean( Luan.first(call(fn,"__lt",new Object[]{o1,o2})) );
+			return checkBoolean( Luan.first(call(fn,"__lt",new Object[]{o1,o2})) );
 		throw exception( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
 	}
 
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/LuanJavaFunction.java
--- a/core/src/luan/LuanJavaFunction.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/LuanJavaFunction.java	Mon May 04 14:55:51 2015 -0600
@@ -237,7 +237,7 @@
 			return "ARG_SAME";
 		}
 	};
-
+/*
 	private static final ArgConverter ARG_BOOLEAN = new ArgConverter() {
 		public Object convert(LuanState luan,Object obj) {
 			return Luan.toBoolean(obj);
@@ -255,7 +255,7 @@
 			return "ARG_BOOLEAN_OBJ";
 		}
 	};
-
+*/
 	private static final ArgConverter ARG_DOUBLE = new ArgConverter() {
 		public Object convert(LuanState luan,Object obj) {
 			if( obj instanceof Double )
@@ -516,10 +516,12 @@
 	}
 
 	private static ArgConverter getArgConverter(Class cls) {
+/*
 		if( cls == Boolean.TYPE )
 			return ARG_BOOLEAN;
 		if( cls.equals(Boolean.class) )
 			return ARG_BOOLEAN_OBJ;
+*/
 		if( cls == Double.TYPE || cls.equals(Double.class) )
 			return ARG_DOUBLE;
 		if( cls == Float.TYPE || cls.equals(Float.class) )
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/LuanState.java
--- a/core/src/luan/LuanState.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/LuanState.java	Mon May 04 14:55:51 2015 -0600
@@ -72,6 +72,10 @@
 		return JAVA.call(fn,fnName,args);
 	}
 
+	public Boolean checkBoolean(Object obj) throws LuanException {
+		return JAVA.checkBoolean(obj);
+	}
+
 	public String checkString(Object obj) throws LuanException {
 		return JAVA.checkString(obj);
 	}
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/impl/AndExpr.java
--- a/core/src/luan/impl/AndExpr.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/impl/AndExpr.java	Mon May 04 14:55:51 2015 -0600
@@ -13,6 +13,6 @@
 
 	@Override public Object eval(LuanStateImpl luan) throws LuanException {
 		Object v1 = op1.eval(luan);
-		return !Luan.toBoolean(v1) ? v1 : op2.eval(luan);
+		return v1 == null || Boolean.FALSE.equals(v1) ? v1 : op2.eval(luan);
 	}
 }
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/impl/EqExpr.java
--- a/core/src/luan/impl/EqExpr.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/impl/EqExpr.java	Mon May 04 14:55:51 2015 -0600
@@ -47,7 +47,7 @@
 			return false;
 		LuanBit bit = luan.bit(se);
 		LuanFunction fn = bit.checkFunction(f);
-		return Luan.toBoolean( Luan.first(bit.call(fn,"__eq",new Object[]{o1,o2})) );
+		return bit.checkBoolean( Luan.first(bit.call(fn,"__eq",new Object[]{o1,o2})) );
 	}
 
 	@Override public String toString() {
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/impl/LeExpr.java
--- a/core/src/luan/impl/LeExpr.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/impl/LeExpr.java	Mon May 04 14:55:51 2015 -0600
@@ -33,10 +33,10 @@
 		LuanBit bit = luan.bit(se);
 		LuanFunction fn = bit.getBinHandler("__le",o1,o2);
 		if( fn != null )
-			return Luan.toBoolean( Luan.first(bit.call(fn,"__le",new Object[]{o1,o2})) );
+			return bit.checkBoolean( Luan.first(bit.call(fn,"__le",new Object[]{o1,o2})) );
 		fn = bit.getBinHandler("__lt",o1,o2);
 		if( fn != null )
-			return !Luan.toBoolean( Luan.first(bit.call(fn,"__lt",new Object[]{o2,o1})) );
+			return !bit.checkBoolean( Luan.first(bit.call(fn,"__lt",new Object[]{o2,o1})) );
 		throw bit.exception( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
 	}
 }
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/impl/OrExpr.java
--- a/core/src/luan/impl/OrExpr.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/impl/OrExpr.java	Mon May 04 14:55:51 2015 -0600
@@ -13,6 +13,6 @@
 
 	@Override public Object eval(LuanStateImpl luan) throws LuanException {
 		Object v1 = op1.eval(luan);
-		return Luan.toBoolean(v1) ? v1 : op2.eval(luan);
+		return v1 != null && !Boolean.FALSE.equals(v1) ? v1 : op2.eval(luan);
 	}
 }
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/modules/BasicLuan.java
--- a/core/src/luan/modules/BasicLuan.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/modules/BasicLuan.java	Mon May 04 14:55:51 2015 -0600
@@ -111,10 +111,6 @@
 		return luan.toString(v);
 	}
 
-	public static boolean to_boolean(Object v) throws LuanException {
-		return Luan.toBoolean(v);
-	}
-
 	public static void error(LuanState luan,Object msg) throws LuanException {
 		throw luan.exception(msg);
 	}
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/modules/Luan.luan
--- a/core/src/luan/modules/Luan.luan	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/modules/Luan.luan	Mon May 04 14:55:51 2015 -0600
@@ -22,7 +22,6 @@
 raw_len = BasicLuan.raw_len
 raw_set = BasicLuan.raw_set
 set_metatable = BasicLuan.set_metatable
-to_boolean = BasicLuan.to_boolean
 to_number = BasicLuan.to_number
 to_string = BasicLuan.to_string
 try = BasicLuan.try_
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/modules/StringLuan.java
--- a/core/src/luan/modules/StringLuan.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/modules/StringLuan.java	Mon May 04 14:55:51 2015 -0600
@@ -181,7 +181,7 @@
 			while( i<max && m.find() ) {
 				String match = m.groupCount()==0 ? m.group() : m.group(1);
 				Object val = t.get(luan,match);
-				if( Luan.toBoolean(val) ) {
+				if( val != null ) {
 					String replacement = luan.checkString(val);
 					if( replacement==null )
 						throw luan.exception( "invalid replacement value (a "+Luan.type(val)+")" );
@@ -208,7 +208,7 @@
 					}
 				}
 				Object val = Luan.first( luan.call(fn,"repl-arg",args) );
-				if( Luan.toBoolean(val) ) {
+				if( val != null ) {
 					String replacement = luan.checkString(val);
 					if( replacement==null )
 						throw luan.exception( "invalid replacement value (a "+Luan.type(val)+")" );
diff -r 75ccb4da803f -r bf5e62a9090c core/src/luan/modules/TableLuan.java
--- a/core/src/luan/modules/TableLuan.java	Mon May 04 13:49:12 2015 -0600
+++ b/core/src/luan/modules/TableLuan.java	Mon May 04 14:55:51 2015 -0600
@@ -66,7 +66,7 @@
 			lt = new LessThan() {
 				public boolean isLessThan(Object o1,Object o2) {
 					try {
-						return Luan.toBoolean(Luan.first(luan.call(comp,"comp-arg",new Object[]{o1,o2})));
+						return luan.checkBoolean(Luan.first(luan.call(comp,"comp-arg",new Object[]{o1,o2})));
 					} catch(LuanException e) {
 						throw new LuanRuntimeException(e);
 					}
diff -r 75ccb4da803f -r bf5e62a9090c web/src/luan/modules/web/HttpServicer.java
--- a/web/src/luan/modules/web/HttpServicer.java	Mon May 04 13:49:12 2015 -0600
+++ b/web/src/luan/modules/web/HttpServicer.java	Mon May 04 14:55:51 2015 -0600
@@ -54,7 +54,7 @@
 			if( !(mod instanceof LuanTable) )
 				throw luan.exception( "module '"+modName+"' must return a table" );
 			LuanTable tbl = (LuanTable)mod;
-			if( Luan.toBoolean( tbl.get(luan,"per_session") ) ) {
+			if( Boolean.TRUE.equals(tbl.get(luan,"per_session")) ) {
 				HttpSession session = request.getSession();
 				LuanState sessionLuan  = (LuanState)session.getValue("luan");
 				if( sessionLuan!=null ) {