diff core/src/luan/impl/$Luan.java @ 649:37f0cf43f191

UnaryExpr now compiled
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 30 Mar 2016 22:42:27 -0600
parents e387e4021afe
children d658eab7bf4c
line wrap: on
line diff
--- a/core/src/luan/impl/$Luan.java	Wed Mar 30 19:40:48 2016 -0600
+++ b/core/src/luan/impl/$Luan.java	Wed Mar 30 22:42:27 2016 -0600
@@ -3,7 +3,9 @@
 import java.util.List;
 import java.util.ArrayList;
 import luan.Luan;
+import luan.LuanState;
 import luan.LuanTable;
+import luan.LuanFunction;
 import luan.LuanException;
 
 
@@ -28,7 +30,7 @@
 		return Luan.first(obj);
 	}
 
-	public static int len(LuanStateImpl luan,Object o) throws LuanException {
+	public static int len(LuanState luan,Object o) throws LuanException {
 		if( o instanceof String ) {
 			String s = (String)o;
 			return s.length();
@@ -43,4 +45,21 @@
 		}
 		throw new LuanException( "attempt to get length of a " + Luan.type(o) + " value" );
 	}
+
+	public static Object unm(LuanState 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(luan,new Object[]{o}));
+			}
+		}
+		throw new LuanException("attempt to perform arithmetic on a "+Luan.type(o)+" value");
+	}
+
+	public static Boolean not(Object o) throws LuanException {
+		return !Luan.checkBoolean(o);
+	}
+
 }