changeset 1121:4cf541886663

check for too many arguments to java fns
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 11 Aug 2017 17:57:52 -0600
parents e8fc6712b468
children e15be31cee92
files src/luan/LuanException.java src/luan/LuanJavaFunction.java src/luan/modules/IoLuan.java
diffstat 3 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/LuanException.java	Mon Aug 07 23:50:52 2017 -0600
+++ b/src/luan/LuanException.java	Fri Aug 11 17:57:52 2017 -0600
@@ -51,7 +51,7 @@
 					LuanException.class.getMethod( "getJavaStackTraceString" ), this
 				) );
 				metatable.rawPut( "__to_string", new LuanJavaFunction(
-					LuanException.class.getMethod( "getFullMessage" ), this
+					LuanException.class.getMethod( "__to_string", LuanTable.class ), this
 				) );
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
@@ -64,6 +64,10 @@
 		throw this;
 	}
 
+	public String __to_string(LuanTable ignore) {
+		return getFullMessage();
+	}
+
 	public String getFullMessage() {
 		return getLuanStackTraceString();
 //		return getLuanStackTraceString()+"\n"+getJavaStackTraceString();
--- a/src/luan/LuanJavaFunction.java	Mon Aug 07 23:50:52 2017 -0600
+++ b/src/luan/LuanJavaFunction.java	Fri Aug 11 17:57:52 2017 -0600
@@ -160,7 +160,12 @@
 				rtn[start++] = luan;
 			}
 			n = argConverters.length;
-			if( varArgCls != null ) {
+			if( varArgCls == null ) {
+				for( int i=n; i<args.length; i++ ) {
+					if( args[i] !=  null )
+						throw new LuanException("too many arguments");
+				}
+			} else {
 				n--;
 				if( args.length < argConverters.length ) {
 					rtn[rtn.length-1] = Array.newInstance(varArgCls,0);
--- a/src/luan/modules/IoLuan.java	Mon Aug 07 23:50:52 2017 -0600
+++ b/src/luan/modules/IoLuan.java	Fri Aug 11 17:57:52 2017 -0600
@@ -594,7 +594,7 @@
 		}
 	}
 
-	public static LuanTable null_() {
+	public static LuanTable null_(String ignore) {
 		return nullIO.table();
 	}
 
@@ -663,7 +663,7 @@
 	public static LuanTable newSchemes() {
 		LuanTable schemes = new LuanTable();
 		try {
-			schemes.rawPut( "null", new LuanJavaFunction(IoLuan.class.getMethod("null_"),null) );
+			schemes.rawPut( "null", new LuanJavaFunction(IoLuan.class.getMethod("null_",String.class),null) );
 			add( schemes, "string", String.class );
 			add( schemes, "file", LuanState.class, String.class );
 			add( schemes, "classpath", LuanState.class, String.class );