changeset 236:1fada5587469

add Basic.to_boolean and change "not" operator to require a boolean git-svn-id: https://luan-java.googlecode.com/svn/trunk@237 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sun, 05 Oct 2014 09:11:10 +0000
parents f247c2ea9eef
children 97d175772fed
files core/src/luan/impl/NotExpr.java core/src/luan/init.luan core/src/luan/modules/BasicLuan.java
diffstat 3 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/impl/NotExpr.java	Sun Oct 05 04:42:04 2014 +0000
+++ b/core/src/luan/impl/NotExpr.java	Sun Oct 05 09:11:10 2014 +0000
@@ -12,7 +12,7 @@
 	}
 
 	@Override public Object eval(LuanStateImpl luan) throws LuanException {
-		return !Luan.toBoolean(op.eval(luan));
+		return !luan.bit(op.se()).checkBoolean( op.eval(luan) );
 	}
 
 	@Override public String toString() {
--- a/core/src/luan/init.luan	Sun Oct 05 04:42:04 2014 +0000
+++ b/core/src/luan/init.luan	Sun Oct 05 09:11:10 2014 +0000
@@ -33,6 +33,7 @@
 Package.global(Basic,"raw_set")
 Package.global(Basic,"repr")
 Package.global(Basic,"set_metatable")
+Package.global(Basic,"to_boolean")
 Package.global(Basic,"to_number")
 local to_string = Package.global(Basic,"to_string")
 Package.global(Basic,"type")
--- a/core/src/luan/modules/BasicLuan.java	Sun Oct 05 04:42:04 2014 +0000
+++ b/core/src/luan/modules/BasicLuan.java	Sun Oct 05 09:11:10 2014 +0000
@@ -45,6 +45,7 @@
 				add( module, "raw_set", LuanTable.class, Object.class, Object.class );
 				add( module, "repr", LuanState.class, Object.class );
 				add( module, "set_metatable", LuanTable.class, LuanTable.class );
+				add( module, "to_boolean", Object.class );
 				add( module, "to_number", Object.class, Integer.class );
 				add( module, "to_string", LuanState.class, Object.class );
 				add( module, "type", Object.class );
@@ -158,6 +159,10 @@
 		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);
 	}