changeset 124:f537ff5e511d

minor cleanup git-svn-id: https://luan-java.googlecode.com/svn/trunk@125 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 06 Jun 2014 03:41:04 +0000
parents d7be9b3abf1a
children 0cd559a16758
files src/luan/LuanState.java src/luan/interp/LuanParser.java src/luan/lib/BasicLib.java src/luan/lib/BinaryLib.java src/luan/lib/HtmlLib.java src/luan/lib/HttpLib.java src/luan/lib/IoLib.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 src/luan/tools/WebServlet.java
diffstat 13 files changed, 48 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/LuanState.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/LuanState.java	Fri Jun 06 03:41:04 2014 +0000
@@ -106,16 +106,16 @@
 	public static LuanState newStandard() {
 		try {
 			LuanState luan = LuanCompiler.newLuanState();
-			luan.load(BasicLib.NAME,BasicLib.LOADER);
-			luan.load(PackageLib.NAME,PackageLib.LOADER);
-			luan.load(MathLib.NAME,MathLib.LOADER);
-			luan.load(StringLib.NAME,StringLib.LOADER);
-			luan.load(TableLib.NAME,TableLib.LOADER);
-			luan.load(HtmlLib.NAME,HtmlLib.LOADER);
-			luan.load(BinaryLib.NAME,BinaryLib.LOADER);
-			luan.load(IoLib.NAME,IoLib.LOADER);
-			luan.load(JavaLib.NAME,JavaLib.LOADER);
+			BasicLib.load(luan);
+			PackageLib.load(luan);
+			MathLib.load(luan);
+			StringLib.load(luan);
+			TableLib.load(luan);
+			HtmlLib.load(luan);
+			BinaryLib.load(luan);
+			IoLib.load(luan);
 			BasicLib.do_java_resource(luan,"luan/lib/init.luan");
+			JavaLib.load(luan);
 			return luan;
 		} catch(LuanException e) {
 			throw new RuntimeException(e);
--- a/src/luan/interp/LuanParser.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/interp/LuanParser.java	Fri Jun 06 03:41:04 2014 +0000
@@ -11,7 +11,6 @@
 import luan.LuanSource;
 import luan.parser.Parser;
 import luan.parser.ParseException;
-import luan.lib.PackageLib;
 
 
 final class LuanParser {
@@ -305,7 +304,7 @@
 		int start = parser.begin();
 		if( !Keyword("import") )
 			return parser.failure(null);
-		Expr importExpr = new ConstExpr(se(start),PackageLib.require);
+		Expr importExpr = (Expr)nameVar(start,"require").expr();
 		String modName = StringLiteral(false);
 		if( modName==null )
 			return parser.failure(null);
--- a/src/luan/lib/BasicLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/BasicLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -21,7 +21,9 @@
 
 public final class BasicLib {
 
-	public static final String NAME = "Basic";
+	public static void load(LuanState luan) throws LuanException {
+		luan.load("Basic",LOADER);
+	}
 
 	public static final LuanFunction LOADER = new LuanFunction() {
 		@Override public Object call(LuanState luan,Object[] args) {
--- a/src/luan/lib/BinaryLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/BinaryLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -4,11 +4,14 @@
 import luan.LuanTable;
 import luan.LuanFunction;
 import luan.LuanJavaFunction;
+import luan.LuanException;
 
 
 public final class BinaryLib {
 
-	public static final String NAME = "Binary";
+	public static void load(LuanState luan) throws LuanException {
+		luan.load("Binary",LOADER);
+	}
 
 	public static final LuanFunction LOADER = new LuanFunction() {
 		@Override public Object call(LuanState luan,Object[] args) {
--- a/src/luan/lib/HtmlLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/HtmlLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -4,11 +4,14 @@
 import luan.LuanTable;
 import luan.LuanFunction;
 import luan.LuanJavaFunction;
+import luan.LuanException;
 
 
 public final class HtmlLib {
 
-	public static final String NAME = "Html";
+	public static void load(LuanState luan) throws LuanException {
+		luan.load("Html",LOADER);
+	}
 
 	public static final LuanFunction LOADER = new LuanFunction() {
 		@Override public Object call(LuanState luan,Object[] args) {
--- a/src/luan/lib/HttpLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/HttpLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -21,7 +21,7 @@
 
 public final class HttpLib {
 
-	public static final String NAME = "Http";
+	private static final String NAME = "Http";
 	public static final String FN_NAME = "Http.server";
 
 	public static void load(LuanState luan) throws LuanException {
--- a/src/luan/lib/IoLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/IoLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -24,7 +24,9 @@
 
 public final class IoLib {
 
-	public static final String NAME = "Io";
+	public static void load(LuanState luan) throws LuanException {
+		luan.load("Io",LOADER);
+	}
 
 	public static final LuanFunction LOADER = new LuanFunction() {
 		@Override public Object call(LuanState luan,Object[] args) {
--- a/src/luan/lib/JavaLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/JavaLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -27,7 +27,9 @@
 
 public final class JavaLib {
 
-	public static final String NAME = "Java";
+	public static void load(LuanState luan) throws LuanException {
+		luan.load("Java",LOADER);
+	}
 
 	public static final LuanFunction LOADER = new LuanFunction() {
 		@Override public Object call(LuanState luan,Object[] args) {
--- a/src/luan/lib/MathLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/MathLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -4,11 +4,14 @@
 import luan.LuanTable;
 import luan.LuanFunction;
 import luan.LuanJavaFunction;
+import luan.LuanException;
 
 
 public final class MathLib {
 
-	public static final String NAME = "Math";
+	public static void load(LuanState luan) throws LuanException {
+		luan.load("Math",LOADER);
+	}
 
 	public static final LuanFunction LOADER = new LuanFunction() {
 		@Override public Object call(LuanState luan,Object[] args) {
--- a/src/luan/lib/PackageLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/PackageLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -16,7 +16,9 @@
 
 public final class PackageLib {
 
-	public static final String NAME = "Package";
+	public static void load(LuanState luan) throws LuanException {
+		luan.load("Package",LOADER);
+	}
 
 	public static final LuanFunction LOADER = new LuanFunction() {
 		@Override public Object call(LuanState luan,Object[] args) {
@@ -26,7 +28,7 @@
 			module.put("preload",luan.preload());
 			module.put("path","?.luan");
 			try {
-				global.put("require",require);
+				add( global, "require", LuanState.class, String.class );
 				add( module, "search_path", String.class, String.class );
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
@@ -40,15 +42,6 @@
 		}
 	};
 
-	public static final LuanFunction require;
-	static {
-		try {
-			require = new LuanJavaFunction(PackageLib.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(PackageLib.class.getMethod(method,parameterTypes),null) );
 	}
--- a/src/luan/lib/StringLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/StringLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -14,7 +14,9 @@
 
 public final class StringLib {
 
-	public static final String NAME = "String";
+	public static void load(LuanState luan) throws LuanException {
+		luan.load("String",LOADER);
+	}
 
 	public static final LuanFunction LOADER = new LuanFunction() {
 		@Override public Object call(LuanState luan,Object[] args) {
--- a/src/luan/lib/TableLib.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/lib/TableLib.java	Fri Jun 06 03:41:04 2014 +0000
@@ -16,7 +16,9 @@
 
 public final class TableLib {
 
-	public static final String NAME = "Table";
+	public static void load(LuanState luan) throws LuanException {
+		luan.load("Table",LOADER);
+	}
 
 	public static final LuanFunction LOADER = new LuanFunction() {
 		@Override public Object call(LuanState luan,Object[] args) {
--- a/src/luan/tools/WebServlet.java	Fri Jun 06 01:14:18 2014 +0000
+++ b/src/luan/tools/WebServlet.java	Fri Jun 06 03:41:04 2014 +0000
@@ -27,12 +27,12 @@
 
 	protected LuanState newLuanState() throws LuanException {
 		LuanState luan = LuanCompiler.newLuanState();
-		luan.load(BasicLib.NAME,BasicLib.LOADER);
-		luan.load(PackageLib.NAME,PackageLib.LOADER);
-		luan.load(MathLib.NAME,MathLib.LOADER);
-		luan.load(StringLib.NAME,StringLib.LOADER);
-		luan.load(TableLib.NAME,TableLib.LOADER);
-		luan.load(HtmlLib.NAME,HtmlLib.LOADER);
+		BasicLib.load(luan);
+		PackageLib.load(luan);
+		MathLib.load(luan);
+		StringLib.load(luan);
+		TableLib.load(luan);
+		HtmlLib.load(luan);
 		return luan;
 	}