diff core/src/luan/impl/$Luan.java @ 648:e387e4021afe

start compiler with len operator
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 30 Mar 2016 19:40:48 -0600
parents
children 37f0cf43f191
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/src/luan/impl/$Luan.java	Wed Mar 30 19:40:48 2016 -0600
@@ -0,0 +1,46 @@
+package luan.impl;
+
+import java.util.List;
+import java.util.ArrayList;
+import luan.Luan;
+import luan.LuanTable;
+import luan.LuanException;
+
+
+public final class $Luan {
+	private $Luan() {}  // never
+
+
+	private static List<Expressions> listExpressions = new ArrayList<Expressions>();
+
+	static int addExpressions(Expressions exp) {
+		int i = listExpressions.size();
+		listExpressions.add(exp);
+		return i;
+	}
+
+	public static Expressions getExpressions(int i) {
+		return listExpressions.get(i);
+	}
+
+
+	public static Object first(Object obj) {
+		return Luan.first(obj);
+	}
+
+	public static int len(LuanStateImpl luan,Object o) throws LuanException {
+		if( o instanceof String ) {
+			String s = (String)o;
+			return s.length();
+		}
+		if( o instanceof byte[] ) {
+			byte[] a = (byte[])o;
+			return a.length;
+		}
+		if( o instanceof LuanTable ) {
+			LuanTable t = (LuanTable)o;
+			return t.length(luan);
+		}
+		throw new LuanException( "attempt to get length of a " + Luan.type(o) + " value" );
+	}
+}