diff src/luan/modules/BasicLuan.java @ 1520:d9a5405a3102

try statement
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 21 Jun 2020 18:14:13 -0600
parents 56fb5cd8228d
children 0dc3be25ad20
line wrap: on
line diff
--- a/src/luan/modules/BasicLuan.java	Fri Jun 19 20:10:47 2020 -0600
+++ b/src/luan/modules/BasicLuan.java	Sun Jun 21 18:14:13 2020 -0600
@@ -193,54 +193,6 @@
 		return obj instanceof LuanFunction ? (LuanFunction)obj : null;
 	}
 
-	public static Object try_(LuanTable blocks,Object... args) throws LuanException {
-		Utils.checkNotNull(blocks);
-		Object obj = blocks.get(1);
-		if( obj == null )
-			throw new LuanException("missing 'try' value");
-		if( !(obj instanceof LuanFunction) )
-			throw new LuanException("bad 'try' value (function expected, got "+Luan.type(obj)+")");
-		LuanFunction tryFn = (LuanFunction)obj;
-		LuanFunction catchFn = null;
-		obj = blocks.get("catch");
-		if( obj != null ) {
-			if( !(obj instanceof LuanFunction) )
-				throw new LuanException("bad 'catch' value (function expected, got "+Luan.type(obj)+")");
-			catchFn = (LuanFunction)obj;
-		}
-		LuanFunction finallyFn = null;
-		obj = blocks.get("finally");
-		if( obj != null ) {
-			if( !(obj instanceof LuanFunction) )
-				throw new LuanException("bad 'finally' value (function expected, got "+Luan.type(obj)+")");
-			finallyFn = (LuanFunction)obj;
-		}
-		try {
-			return tryFn.call(args);
-		} catch(LuanException e) {
-			if( catchFn == null )
-				throw e;
-			return catchFn.call(e.table(blocks.luan()));
-		} finally {
-			if( finallyFn != null )
-				finallyFn.call();
-		}
-	}
-
-	public static Object[] pcall(LuanFunction f,Object... args) {
-		try {
-			Object[] r = Luan.array(f.call(args));
-			Object[] rtn = new Object[r.length+1];
-			rtn[0] = true;
-			for( int i=0; i<r.length; i++ ) {
-				rtn[i+1] = r[i];
-			}
-			return rtn;
-		} catch(LuanException e) {
-			return new Object[]{false,e.table(f.luan())};
-		}
-	}
-
 	public static String number_type(Number v) throws LuanException {
 		Utils.checkNotNull(v);
 		return v.getClass().getSimpleName().toLowerCase();