diff src/luan/tools/CmdLine.java @ 108:3c404a296995

make Package module more standard; return _ENV by default; add "import" statement; git-svn-id: https://luan-java.googlecode.com/svn/trunk@109 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 23 May 2014 03:21:54 +0000
parents 754e6030c029
children 2428ecfed375
line wrap: on
line diff
--- a/src/luan/tools/CmdLine.java	Mon May 19 09:17:57 2014 +0000
+++ b/src/luan/tools/CmdLine.java	Fri May 23 03:21:54 2014 +0000
@@ -14,14 +14,6 @@
 
 	public static void main(String[] args) {
 		LuanState luan = LuanState.newStandard();
-		LuanTable env;
-		try {
-			env = luan.newEnvironment();
-		} catch(LuanException e) {
-			System.err.println("command line error: "+e.getMessage());
-			System.exit(-1);
-			throw new RuntimeException();  // never
-		}
 		boolean interactive = false;
 		boolean showVersion = false;
 		int i = 0;
@@ -42,7 +34,7 @@
 						error("'-e' needs argument");
 					String cmd = args[i];
 					try {
-						LuanFunction fn = BasicLib.load(luan,cmd,"(command line)",env);
+						LuanFunction fn = BasicLib.load(luan,cmd,"(command line)",false);
 						luan.JAVA.call(fn,null);
 					} catch(LuanException e) {
 						System.err.println("command line error: "+e.getMessage());
@@ -50,7 +42,7 @@
 					}
 				} else if( arg.equals("-") ) {
 					try {
-						BasicLib.do_file(luan,"stdin",env);
+						BasicLib.do_file(luan,"stdin");
 					} catch(LuanException e) {
 						System.err.println(e.getMessage());
 						System.exit(-1);
@@ -72,9 +64,9 @@
 			for( int j=0; j<args.length; j++ ) {
 				argsTable.put( j, args[j] );
 			}
-			env.put("arg",argsTable);
+			luan.global().put("arg",argsTable);
 			try {
-				LuanFunction fn = BasicLib.load_file(luan,file,env);
+				LuanFunction fn = BasicLib.load_file(luan,file);
 				luan.JAVA.call(fn,null,varArgs);
 			} catch(LuanException e) {
 //				System.err.println("error: "+e.getMessage());
@@ -83,7 +75,7 @@
 			}
 		}
 		if( interactive )
-			interactive(luan,env);
+			interactive(luan);
 	}
 
 	private static void error(String msg) {
@@ -100,7 +92,7 @@
 		System.exit(-1);
 	}
 
-	static void interactive(LuanState luan,LuanTable env) {
+	static void interactive(LuanState luan) {
 		try {
 			ConsoleReader console = new ConsoleReader();
 			console.setDefaultPrompt("> ");
@@ -109,7 +101,7 @@
 				if( input==null )
 					break;
 				try {
-					Object[] rtn = luan.eval(input,"stdin",env);
+					Object[] rtn = luan.eval(input,"stdin",true);
 					if( rtn.length > 0 )
 						BasicLib.print(luan,rtn);
 				} catch(LuanException e) {