changeset 112:f5af13062b10

fix previous rev git-svn-id: https://luan-java.googlecode.com/svn/trunk@113 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 23 May 2014 22:52:39 +0000
parents 2428ecfed375
children 8c706d6eb5dc
files src/luan/LuanBit.java src/luan/interp/EqExpr.java src/luan/interp/FnCall.java src/luan/interp/IndexExpr.java src/luan/interp/LeExpr.java src/luan/interp/LenExpr.java src/luan/interp/ReturnStmt.java src/luan/interp/SetTableEntry.java src/luan/interp/UnmExpr.java src/luan/lib/BasicLib.java src/luan/lib/HtmlLib.java src/luan/lib/JavaLib.java src/luan/lib/MathLib.java src/luan/lib/PackageLib.java src/luan/lib/StringLib.java src/luan/lib/TableLib.java
diffstat 16 files changed, 43 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
diff -r 2428ecfed375 -r f5af13062b10 src/luan/LuanBit.java
--- a/src/luan/LuanBit.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/LuanBit.java	Fri May 23 22:52:39 2014 +0000
@@ -16,7 +16,11 @@
 		return new LuanException(this,msg);
 	}
 
-	public Object call(LuanFunction fn,String fnName,Object... args) throws LuanException {
+	public Object call(LuanFunction fn,String fnName) throws LuanException {
+		return call(fn,fnName,LuanFunction.EMPTY);
+	}
+
+	public Object call(LuanFunction fn,String fnName,Object[] args) throws LuanException {
 		List<StackTraceElement> stackTrace = luan.stackTrace;
 		stackTrace.add( new StackTraceElement(el,fnName) );
 		try {
@@ -49,14 +53,14 @@
 	public String toString(Object obj) throws LuanException {
 		LuanFunction fn = getHandlerFunction("__tostring",obj);
 		if( fn != null )
-			return checkString( Luan.first( call(fn,"__tostring",obj) ) );
+			return checkString( Luan.first( call(fn,"__tostring",new Object[]{obj}) ) );
 		return Luan.toString(obj);
 	}
 
 	public String repr(Object obj) throws LuanException {
 		LuanFunction fn = getHandlerFunction("__repr",obj);
 		if( fn != null )
-			return checkString( Luan.first( call(fn,"__repr",obj) ) );
+			return checkString( Luan.first( call(fn,"__repr",new Object[]{obj}) ) );
 		String repr = Luan.repr(obj);
 		if( repr==null )
 			throw exception( "value '" + obj + "' doesn't support repr()" );
@@ -90,14 +94,14 @@
 		}
 		LuanFunction fn = getBinHandler("__lt",o1,o2);
 		if( fn != null )
-			return Luan.toBoolean( Luan.first(call(fn,"__lt",o1,o2)) );
+			return Luan.toBoolean( Luan.first(call(fn,"__lt",new Object[]{o1,o2})) );
 		throw exception( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
 	}
 
 	public Object arithmetic(String op,Object o1,Object o2) throws LuanException {
 		LuanFunction fn = getBinHandler(op,o1,o2);
 		if( fn != null )
-			return Luan.first(call(fn,op,o1,o2));
+			return Luan.first(call(fn,op,new Object[]{o1,o2}));
 		String type = Luan.toNumber(o1)==null ? Luan.type(o1) : Luan.type(o2);
 		throw exception("attempt to perform arithmetic on a "+type+" value");
 	}
diff -r 2428ecfed375 -r f5af13062b10 src/luan/interp/EqExpr.java
--- a/src/luan/interp/EqExpr.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/interp/EqExpr.java	Fri May 23 22:52:39 2014 +0000
@@ -35,6 +35,6 @@
 			return null;
 		LuanBit bit = luan.bit(se);
 		LuanFunction fn = bit.checkFunction(f);
-		return Luan.toBoolean( Luan.first(bit.call(fn,"__eq",o1,o2)) );
+		return Luan.toBoolean( Luan.first(bit.call(fn,"__eq",new Object[]{o1,o2})) );
 	}
 }
diff -r 2428ecfed375 -r f5af13062b10 src/luan/interp/FnCall.java
--- a/src/luan/interp/FnCall.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/interp/FnCall.java	Fri May 23 22:52:39 2014 +0000
@@ -25,7 +25,7 @@
 	private Object call(LuanStateImpl luan,Object o) throws LuanException {
 		if( o instanceof LuanFunction ) {
 			LuanFunction fn = (LuanFunction)o;
-			return luan.bit(se).call( fn, fnName, args.eval(luan) );
+			return luan.bit(se).call( fn, fnName, Luan.array(args.eval(luan)) );
 		}
 		Object h = luan.getHandler("__call",o);
 		if( h != null )
diff -r 2428ecfed375 -r f5af13062b10 src/luan/interp/IndexExpr.java
--- a/src/luan/interp/IndexExpr.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/interp/IndexExpr.java	Fri May 23 22:52:39 2014 +0000
@@ -34,7 +34,7 @@
 		}
 		if( h instanceof LuanFunction ) {
 			LuanFunction fn = (LuanFunction)h;
-			return Luan.first(luan.bit(se).call(fn,"__index",t,key));
+			return Luan.first(luan.bit(se).call(fn,"__index",new Object[]{t,key}));
 		}
 		return index(luan,h,key);
 	}
diff -r 2428ecfed375 -r f5af13062b10 src/luan/interp/LeExpr.java
--- a/src/luan/interp/LeExpr.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/interp/LeExpr.java	Fri May 23 22:52:39 2014 +0000
@@ -29,10 +29,10 @@
 		LuanBit bit = luan.bit(se);
 		LuanFunction fn = bit.getBinHandler("__le",o1,o2);
 		if( fn != null )
-			return Luan.toBoolean( Luan.first(bit.call(fn,"__le",o1,o2)) );
+			return Luan.toBoolean( Luan.first(bit.call(fn,"__le",new Object[]{o1,o2})) );
 		fn = bit.getBinHandler("__lt",o1,o2);
 		if( fn != null )
-			return !Luan.toBoolean( Luan.first(bit.call(fn,"__lt",o2,o1)) );
+			return !Luan.toBoolean( Luan.first(bit.call(fn,"__lt",new Object[]{o2,o1})) );
 		throw bit.exception( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) );
 	}
 }
diff -r 2428ecfed375 -r f5af13062b10 src/luan/interp/LenExpr.java
--- a/src/luan/interp/LenExpr.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/interp/LenExpr.java	Fri May 23 22:52:39 2014 +0000
@@ -23,7 +23,7 @@
 		LuanBit bit = luan.bit(se);
 		LuanFunction fn = bit.getHandlerFunction("__len",o);
 		if( fn != null )
-			return Luan.first(bit.call(fn,"__len",o));
+			return Luan.first(bit.call(fn,"__len",new Object[]{o}));
 		if( o instanceof LuanTable ) {
 			LuanTable t = (LuanTable)o;
 			return t.length();
diff -r 2428ecfed375 -r f5af13062b10 src/luan/interp/ReturnStmt.java
--- a/src/luan/interp/ReturnStmt.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/interp/ReturnStmt.java	Fri May 23 22:52:39 2014 +0000
@@ -30,7 +30,7 @@
 			if( tailFn instanceof Closure ) {
 				luan.tailFn = (Closure)tailFn;
 			} else {
-				luan.returnValues =  luan.bit(tailFnExpr.se()).call(tailFn,tailFnExpr.se().text(),luan.returnValues);
+				luan.returnValues =  luan.bit(tailFnExpr.se()).call(tailFn,tailFnExpr.se().text(),Luan.array(luan.returnValues));
 			}
 		}
 		if( throwReturnException )
diff -r 2428ecfed375 -r f5af13062b10 src/luan/interp/SetTableEntry.java
--- a/src/luan/interp/SetTableEntry.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/interp/SetTableEntry.java	Fri May 23 22:52:39 2014 +0000
@@ -39,7 +39,7 @@
 		}
 		if( h instanceof LuanFunction ) {
 			LuanFunction fn = (LuanFunction)h;
-			luan.bit(se).call(fn,"__newindex",t,key,value);
+			luan.bit(se).call(fn,"__newindex",new Object[]{t,key,value});
 			return;
 		}
 		newindex(luan,h,key,value);
diff -r 2428ecfed375 -r f5af13062b10 src/luan/interp/UnmExpr.java
--- a/src/luan/interp/UnmExpr.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/interp/UnmExpr.java	Fri May 23 22:52:39 2014 +0000
@@ -22,7 +22,7 @@
 		LuanBit bit = luan.bit(se);
 		LuanFunction fn = bit.getHandlerFunction("__unm",o);
 		if( fn != null ) {
-			return Luan.first(bit.call(fn,"__unm",o));
+			return Luan.first(bit.call(fn,"__unm",new Object[]{o}));
 		}
 		throw bit.exception("attempt to perform arithmetic on a "+Luan.type(o)+" value");
 	}
diff -r 2428ecfed375 -r f5af13062b10 src/luan/lib/BasicLib.java
--- a/src/luan/lib/BasicLib.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/lib/BasicLib.java	Fri May 23 22:52:39 2014 +0000
@@ -208,12 +208,12 @@
 		return new LuanFunction() {
 			double v = from;
 
-			@Override public Object[] call(LuanState luan,Object[] args) {
+			@Override public Object call(LuanState luan,Object[] args) {
 				if( step > 0.0 && v > to || step < 0.0 && v < to )
 					return LuanFunction.EMPTY;
 				double rtn = v;
 				v += step;
-				return new Object[]{rtn};
+				return rtn;
 			}
 		};
 	}
diff -r 2428ecfed375 -r f5af13062b10 src/luan/lib/HtmlLib.java
--- a/src/luan/lib/HtmlLib.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/lib/HtmlLib.java	Fri May 23 22:52:39 2014 +0000
@@ -11,14 +11,14 @@
 	public static final String NAME = "Html";
 
 	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object[] call(LuanState luan,Object[] args) {
+		@Override public Object call(LuanState luan,Object[] args) {
 			LuanTable module = new LuanTable();
 			try {
 				add( module, "encode", String.class );
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
 			}
-			return new Object[]{module};
+			return module;
 		}
 	};
 
diff -r 2428ecfed375 -r f5af13062b10 src/luan/lib/JavaLib.java
--- a/src/luan/lib/JavaLib.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/lib/JavaLib.java	Fri May 23 22:52:39 2014 +0000
@@ -30,7 +30,7 @@
 	public static final String NAME = "Java";
 
 	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object[] call(LuanState luan,Object[] args) {
+		@Override public Object call(LuanState luan,Object[] args) {
 			luan.addMetatableGetter(mg);
 			LuanTable module = new LuanTable();
 			LuanTable global = luan.global();
@@ -41,22 +41,22 @@
 				throw new RuntimeException(e);
 			}
 			luan.searchers().add(javaSearcher);
-			return new Object[]{module};
+			return module;
 		}
 	};
 
 	public static final LuanFunction javaSearcher = new LuanFunction() {
-		@Override public Object[] call(LuanState luan,Object[] args) throws LuanException {
+		@Override public Object call(LuanState luan,Object[] args) throws LuanException {
 			String modName = (String)args[0];
 			final Static s = JavaLib.getClass(luan,modName);
 			if( s==null )
-				return LuanFunction.EMPTY;
+				return null;
 			LuanFunction loader = new LuanFunction() {
-				@Override public Object[] call(LuanState luan,Object[] args) {
-					return new Object[]{s};
+				@Override public Object call(LuanState luan,Object[] args) {
+					return s;
 				}
 			};
-			return new Object[]{loader};
+			return loader;
 		}
 	};
 
@@ -368,7 +368,7 @@
 			}
 		}
 
-		@Override public Object[] call(LuanState luan,Object[] args) throws LuanException {
+		@Override public Object call(LuanState luan,Object[] args) throws LuanException {
 			for( LuanJavaFunction fn : fnMap.get(args.length) ) {
 				try {
 					return fn.rawCall(luan,args);
diff -r 2428ecfed375 -r f5af13062b10 src/luan/lib/MathLib.java
--- a/src/luan/lib/MathLib.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/lib/MathLib.java	Fri May 23 22:52:39 2014 +0000
@@ -11,7 +11,7 @@
 	public static final String NAME = "Math";
 
 	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object[] call(LuanState luan,Object[] args) {
+		@Override public Object call(LuanState luan,Object[] args) {
 			LuanTable module = new LuanTable();
 			try {
 				add( module, "abs", Double.TYPE );
@@ -41,7 +41,7 @@
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
 			}
-			return new Object[]{module};
+			return module;
 		}
 	};
 
diff -r 2428ecfed375 -r f5af13062b10 src/luan/lib/PackageLib.java
--- a/src/luan/lib/PackageLib.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/lib/PackageLib.java	Fri May 23 22:52:39 2014 +0000
@@ -62,7 +62,7 @@
 				searchers = new LuanTable(Collections.<Object>singletonList(preloadSearcher));
 			for( Object s : searchers.asList() ) {
 				LuanFunction searcher = (LuanFunction)s;
-				Object[] a = Luan.array(luan.JAVA.call(searcher,"<searcher>",modName));
+				Object[] a = Luan.array(luan.JAVA.call(searcher,"<searcher>",new Object[]{modName}));
 				if( a.length >= 1 && a[0] instanceof LuanFunction ) {
 					LuanFunction loader = (LuanFunction)a[0];
 					a[0] = modName;
@@ -112,10 +112,9 @@
 	};
 
 	public static final LuanFunction preloadSearcher = new LuanFunction() {
-		@Override public Object[] call(LuanState luan,Object[] args) {
+		@Override public Object call(LuanState luan,Object[] args) {
 			String modName = (String)args[0];
-			Object mod = luan.preload().get(modName);
-			return new Object[]{mod};
+			return luan.preload().get(modName);
 		}
 	};
 
diff -r 2428ecfed375 -r f5af13062b10 src/luan/lib/StringLib.java
--- a/src/luan/lib/StringLib.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/lib/StringLib.java	Fri May 23 22:52:39 2014 +0000
@@ -16,7 +16,7 @@
 	public static final String NAME = "String";
 
 	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object[] call(LuanState luan,Object[] args) {
+		@Override public Object call(LuanState luan,Object[] args) {
 			LuanTable module = new LuanTable();
 			try {
 				module.put( "byte", new LuanJavaFunction(StringLib.class.getMethod("byte_",String.class,Integer.class,Integer.class),null) );
@@ -35,7 +35,7 @@
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
 			}
-			return new Object[]{module};
+			return module;
 		}
 	};
 
@@ -131,12 +131,12 @@
 	public static LuanFunction gmatch(String s,String pattern) {
 		final Matcher m = Pattern.compile(pattern).matcher(s);
 		return new LuanFunction() {
-			public Object[] call(LuanState luan,Object[] args) {
+			@Override public Object call(LuanState luan,Object[] args) {
 				if( !m.find() )
-					return LuanFunction.EMPTY;
+					return null;
 				final int n = m.groupCount();
 				if( n == 0 )
-					return new String[]{m.group()};
+					return m.group();
 				String[] rtn = new String[n];
 				for( int i=0; i<n; i++ ) {
 					rtn[i] = m.group(i);
diff -r 2428ecfed375 -r f5af13062b10 src/luan/lib/TableLib.java
--- a/src/luan/lib/TableLib.java	Fri May 23 20:40:05 2014 +0000
+++ b/src/luan/lib/TableLib.java	Fri May 23 22:52:39 2014 +0000
@@ -18,7 +18,7 @@
 	public static final String NAME = "Table";
 
 	public static final LuanFunction LOADER = new LuanFunction() {
-		@Override public Object[] call(LuanState luan,Object[] args) {
+		@Override public Object call(LuanState luan,Object[] args) {
 			LuanTable module = new LuanTable();
 			try {
 				add( module, "concat", LuanState.class, LuanTable.class, String.class, Integer.class, Integer.class );
@@ -31,7 +31,7 @@
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
 			}
-			return new Object[]{module};
+			return module;
 		}
 	};
 
@@ -93,7 +93,7 @@
 			lt = new LessThan() {
 				public boolean isLessThan(Object o1,Object o2) {
 					try {
-						return Luan.toBoolean(Luan.first(luan.JAVA.call(comp,"comp-arg",o1,o2)));
+						return Luan.toBoolean(Luan.first(luan.JAVA.call(comp,"comp-arg",new Object[]{o1,o2})));
 					} catch(LuanException e) {
 						throw new LuanRuntimeException(e);
 					}