changeset 186:cf939124461a

don't import modules by default git-svn-id: https://luan-java.googlecode.com/svn/trunk@187 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 26 Jun 2014 00:36:50 +0000
parents 5f50dba8ac7d
children 1cb298d918b2
files core/src/luan/LuanState.java core/src/luan/cmd_line.luan core/src/luan/impl/LuanParser.java core/src/luan/impl/SetTableEntry.java core/src/luan/init.luan core/src/luan/modules/PackageLuan.java web/src/luan/modules/web/Web_server.luan
diffstat 7 files changed, 23 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/LuanState.java	Wed Jun 25 07:06:16 2014 +0000
+++ b/core/src/luan/LuanState.java	Thu Jun 26 00:36:50 2014 +0000
@@ -122,19 +122,9 @@
 		return t.put(a[a.length-1],value);
 	}
 
-	public final void globalImport(String modName) {
-		try {
-			Object mod = PackageLuan.require(this,modName);
-			global.put(modName,mod);
-		} catch(LuanException e) {
-			throw new RuntimeException(e);
-		}
-	}
-
 	public static LuanState newStandard() {
 		try {
 			LuanState luan = LuanCompiler.newLuanState();
-			luan.globalImport("Package");
 			BasicLuan.do_file(luan,"java:luan/init.luan");
 			return luan;
 		} catch(LuanException e) {
--- a/core/src/luan/cmd_line.luan	Wed Jun 25 07:06:16 2014 +0000
+++ b/core/src/luan/cmd_line.luan	Thu Jun 26 00:36:50 2014 +0000
@@ -1,3 +1,6 @@
+import "String"
+import "Table"
+
 
 local standalone_usage = [=[
 usage: java luan.CmdLine [options] [script [args]]
--- a/core/src/luan/impl/LuanParser.java	Wed Jun 25 07:06:16 2014 +0000
+++ b/core/src/luan/impl/LuanParser.java	Thu Jun 26 00:36:50 2014 +0000
@@ -9,6 +9,7 @@
 import luan.Luan;
 import luan.LuanState;
 import luan.LuanSource;
+import luan.modules.PackageLuan;
 
 
 final class LuanParser {
@@ -345,21 +346,6 @@
 		int start = parser.begin();
 		if( !Keyword("import",In.NOTHING) )
 			return parser.failure(null);
-		Expr importExpr;
-		{
-			LuanSource.Element se = se(start);
-			int index = stackIndex("require");
-			if( index != -1 ) {
-				importExpr = new GetLocalVar(se,index);
-			} else {
-				index = upValueIndex("require");
-				if( index != -1 ) {
-					importExpr = new GetUpVar(se,index);
-				} else {
-					throw parser.exception("no local 'require' function, needed for import");
-				}
-			}
-		}
 		String modName = StringLiteral(In.NOTHING);
 		if( modName==null )
 			return parser.failure(null);
@@ -370,7 +356,7 @@
 		if( !isValidName(varName) )
 			throw parser.exception("invalid variable name '"+varName+"' in import");
 		LuanSource.Element se = se(start);
-		FnCall require = new FnCall( se, importExpr, new ConstExpr(modName) );
+		FnCall require = new FnCall( se, new ConstExpr(se,PackageLuan.requireFn), new ConstExpr(modName) );
 		Settable settable;
 		if( interactive ) {
 			settable = nameVar(se,varName).settable();
--- a/core/src/luan/impl/SetTableEntry.java	Wed Jun 25 07:06:16 2014 +0000
+++ b/core/src/luan/impl/SetTableEntry.java	Thu Jun 26 00:36:50 2014 +0000
@@ -35,7 +35,7 @@
 		} else {
 			h = luan.getHandler("__newindex",t);
 			if( h==null )
-				throw luan.bit(se).exception( "attempt to index a " + Luan.type(t) + " value" );
+				throw luan.bit(se).exception( "attempt to index '"+tableExpr.se().text()+"' (a " + Luan.type(t) + " value)" );
 		}
 		if( h instanceof LuanFunction ) {
 			LuanFunction fn = (LuanFunction)h;
--- a/core/src/luan/init.luan	Wed Jun 25 07:06:16 2014 +0000
+++ b/core/src/luan/init.luan	Thu Jun 26 00:36:50 2014 +0000
@@ -1,3 +1,8 @@
+import "Package"
+import "Basic"
+import "Table"
+import "Io"
+
 function Package.global(module,fn_name)
 	local function fn(...)
 		return module[fn_name](...)
@@ -7,17 +12,6 @@
 end
 
 local require = Package.global(Package,"require")
-
-import "Basic"; _G.Basic = Basic
-import "String"; _G.String = String
-import "Table"; _G.Table = Table
-import "Io"; _G.Io = Io
-import "Math"; _G.Math = Basic
-import "Html"; _G.Html = Html
-import "Thread"; _G.Thread = Thread
-import "Binary"; _G.Binary = Binary
-
-
 Package.global(Basic,"assert")
 Package.global(Basic,"assert_boolean")
 Package.global(Basic,"assert_nil")
--- a/core/src/luan/modules/PackageLuan.java	Wed Jun 25 07:06:16 2014 +0000
+++ b/core/src/luan/modules/PackageLuan.java	Thu Jun 26 00:36:50 2014 +0000
@@ -25,7 +25,7 @@
 			module.put("path","?.luan;java:luan/modules/?.luan");
 			module.put("jpath",jpath);
 			try {
-				add( module, "require", LuanState.class, String.class );
+				module.put("require",requireFn);
 				add( module, "load", LuanState.class, String.class );
 				add( module, "load_lib", String.class );
 				add( module, "search_path", String.class, String.class );
@@ -42,6 +42,15 @@
 		}
 	};
 
+	public static final LuanFunction requireFn;
+	static {
+		try {
+			requireFn = new LuanJavaFunction(PackageLuan.class.getMethod("require",LuanState.class,String.class),null);
+		} catch(NoSuchMethodException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
 	private static void add(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException {
 		t.put( method, new LuanJavaFunction(PackageLuan.class.getMethod(method,parameterTypes),null) );
 	}
--- a/web/src/luan/modules/web/Web_server.luan	Wed Jun 25 07:06:16 2014 +0000
+++ b/web/src/luan/modules/web/Web_server.luan	Thu Jun 26 00:36:50 2014 +0000
@@ -1,4 +1,6 @@
 import "Java"
+import "Package"
+import "web/Http"
 
 import "org.eclipse.jetty.server.Server"
 import "org.eclipse.jetty.server.NCSARequestLog"
@@ -11,7 +13,6 @@
 import "org.eclipse.jetty.server.handler.GzipHandler"
 import "org.eclipse.jetty.server.handler.HandlerWrapper"
 import "org.eclipse.jetty.server.session.SessionHandler"
-import "web/Http"
 
 
 port = 8080