diff src/luan/LuanState.java @ 1166:7ef40e1923b7

add back Thread.global allow metatables to have metatables
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 08 Feb 2018 02:22:51 -0700
parents ba4daf107e07
children d3a3ca116e42
line wrap: on
line diff
--- a/src/luan/LuanState.java	Wed Feb 07 23:16:12 2018 -0700
+++ b/src/luan/LuanState.java	Thu Feb 08 02:22:51 2018 -0700
@@ -96,4 +96,38 @@
 		throw new LuanException( "attempt to perform arithmetic on '"+context()+"' (a " + Luan.type(obj) + " value)" );
 	}
 */
+
+
+	public boolean isLessThan(Object o1,Object o2) throws LuanException {
+		if( o1 instanceof Number && o2 instanceof Number ) {
+			Number n1 = (Number)o1;
+			Number n2 = (Number)o2;
+			return n1.doubleValue() < n2.doubleValue();
+		}
+		if( o1 instanceof String && o2 instanceof String ) {
+			String s1 = (String)o1;
+			String s2 = (String)o2;
+			return s1.compareTo(s2) < 0;
+		}
+		LuanFunction fn = getBinHandler("__lt",o1,o2);
+		if( fn != null )
+			return Luan.checkBoolean( Luan.first(fn.call(this,new Object[]{o1,o2})) );
+		throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
+	}
+
+	public LuanFunction getBinHandler(String op,Object o1,Object o2) throws LuanException {
+		if( o1 instanceof LuanTable ) {
+			LuanFunction f1 = getHandlerFunction(op,(LuanTable)o1);
+			if( f1 != null )
+				return f1;
+		}
+		return o2 instanceof LuanTable ? getHandlerFunction(op,(LuanTable)o2) : null;
+	}
+
+	public LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException {
+		Object f = t.getHandler(this,op);
+		if( f == null )
+			return null;
+		return Luan.checkFunction(f);
+	}
 }