changeset 26:409871b33355

CmdLine varArgs git-svn-id: https://luan-java.googlecode.com/svn/trunk@27 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 06 Dec 2012 10:17:27 +0000
parents 0e406bd9ac7b
children 9de9be530625
files src/luan/CmdLine.java src/luan/interp/LuaParser.java
diffstat 2 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
diff -r 0e406bd9ac7b -r 409871b33355 src/luan/CmdLine.java
--- a/src/luan/CmdLine.java	Thu Dec 06 09:36:24 2012 +0000
+++ b/src/luan/CmdLine.java	Thu Dec 06 10:17:27 2012 +0000
@@ -1,5 +1,6 @@
 package luan;
 
+import java.util.Arrays;
 import java.util.Scanner;
 import luan.lib.BasicLib;
 
@@ -26,9 +27,16 @@
 			interactive = true;
 		} else {
 			String file = args[i++];
+			Object[] varArgs = new Object[args.length-1];
+			System.arraycopy(args,1,varArgs,0,varArgs.length);
+			LuaTable argsTable = new LuaTable();
+			for( int j=0; j<args.length; j++ ) {
+				argsTable.set( new LuaNumber(j), args[j] );
+			}
+			lua.env().set("arg",argsTable);
 			try {
 				LuaFunction fn = BasicLib.loadFile(lua,file);
-				fn.call(lua);
+				fn.call(lua,varArgs);
 			} catch(LuaException e) {
 //				System.out.println(e.getMessage());
 				e.printStackTrace();
diff -r 0e406bd9ac7b -r 409871b33355 src/luan/interp/LuaParser.java
--- a/src/luan/interp/LuaParser.java	Thu Dec 06 09:36:24 2012 +0000
+++ b/src/luan/interp/LuaParser.java	Thu Dec 06 10:17:27 2012 +0000
@@ -104,9 +104,10 @@
 			FirstOf(
 				Sequence( ExpList(), EOI ),
 				Sequence(
+					action( frame.isVarArg = true ),
 					Block(),
 					EOI,
-					push( new Chunk( (Stmt)pop(), frame.stackSize, 0, false ) )
+					push( new Chunk( (Stmt)pop(), frame.stackSize, 0, frame.isVarArg ) )
 				)
 			)
 		);