diff src/luan/Luan.java @ 1335:e0cf0d108a77

major cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Feb 2019 03:10:45 -0700
parents c88b486a9511
children 8b61c8c4e07a
line wrap: on
line diff
--- a/src/luan/Luan.java	Tue Feb 12 22:53:57 2019 -0700
+++ b/src/luan/Luan.java	Thu Feb 14 03:10:45 2019 -0700
@@ -23,7 +23,7 @@
 
 	private final List<LuanClosure> stack = new ArrayList<LuanClosure>();
 	private Map registry;
-	public boolean isLocked = false;
+	private boolean isLocked = false;
 
 	public interface OnClose extends Closeable {
 		public void onClose(Closeable c);
@@ -57,6 +57,8 @@
 	}
 
 	void push(LuanClosure closure) {
+		if( isLocked )
+			throw new RuntimeException(this+" is locked "+closure);
 		stack.add(closure);
 	}
 
@@ -74,7 +76,7 @@
 	}
 
 	public Object eval(String cmd,Object... args) throws LuanException {
-		return Luan.load(cmd,"eval").call(this,args);
+		return load(cmd,"eval").call(args);
 	}
 
 	public Object require(String modName) throws LuanException {
@@ -106,7 +108,7 @@
 	}
 
 
-	public boolean isLessThan(Object o1,Object o2) throws LuanException {
+	public static boolean isLessThan(Object o1,Object o2) throws LuanException {
 		if( o1 instanceof Number && o2 instanceof Number ) {
 			Number n1 = (Number)o1;
 			Number n2 = (Number)o2;
@@ -119,7 +121,7 @@
 		}
 		LuanFunction fn = getBinHandler("__lt",o1,o2);
 		if( fn != null )
-			return Luan.checkBoolean( Luan.first(fn.call(this,new Object[]{o1,o2})) );
+			return Luan.checkBoolean( Luan.first(fn.call(o1,o2)) );
 		throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
 	}
 
@@ -181,7 +183,7 @@
 	public static void doFile(String uri,String... args) throws LuanException {
 		Luan luan = new Luan();
 		LuanFunction fn = (LuanFunction)BasicLuan.load_file(luan,uri);
-		fn.call(luan,args);
+		fn.call((Object[])args);
 	}
 
 	public static Object first(Object obj) {
@@ -276,13 +278,13 @@
 		throw new LuanException("attempt to call a " + Luan.type(obj) + " value" );
 	}
 
-	public static LuanFunction load(String text,String sourceName,LuanTable env)
+	public LuanFunction load(String text,String sourceName,LuanTable env)
 		throws LuanException
 	{
-		return LuanCompiler.compile(text,sourceName,env);
+		return LuanCompiler.compile(this,text,sourceName,env);
 	}
 
-	public static LuanFunction load(String text,String sourceName)
+	public LuanFunction load(String text,String sourceName)
 		throws LuanException
 	{
 		return load(text,sourceName,null);