changeset 90:b1e87f1bcc13

make module names uppercase; WebServlet improvements; git-svn-id: https://luan-java.googlecode.com/svn/trunk@91 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Sat, 02 Mar 2013 05:02:56 +0000
parents 8ef2d6701541
children 1f8b6edc2b08
files src/luan/Luan.java src/luan/lib/BasicLib.java src/luan/lib/HtmlLib.java src/luan/lib/HttpLib.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 10 files changed, 35 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/Luan.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/Luan.java	Sat Mar 02 05:02:56 2013 +0000
@@ -6,18 +6,18 @@
 
 	public static String type(Object obj) {
 		if( obj == null )
-			return "nil";
+			return "Nil";
 		if( obj instanceof String )
-			return "string";
+			return "String";
 		if( obj instanceof Boolean )
-			return "boolean";
+			return "Boolean";
 		if( obj instanceof Number )
-			return "number";
+			return "Number";
 		if( obj instanceof LuanTable )
-			return "table";
+			return "Table";
 		if( obj instanceof LuanFunction )
-			return "function";
-		return "userdata";
+			return "Function";
+		return "Userdata";
 	}
 
 	public static boolean toBoolean(Object obj) {
--- a/src/luan/lib/BasicLib.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/lib/BasicLib.java	Sat Mar 02 05:02:56 2013 +0000
@@ -20,7 +20,7 @@
 
 public final class BasicLib {
 
-	public static final String NAME = "basic";
+	public static final String NAME = "Basic";
 
 	public static final LuanLoader LOADER = new LuanLoader() {
 		@Override protected void load(LuanState luan) {
--- a/src/luan/lib/HtmlLib.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/lib/HtmlLib.java	Sat Mar 02 05:02:56 2013 +0000
@@ -9,7 +9,7 @@
 
 public final class HtmlLib {
 
-	public static final String NAME = "html";
+	public static final String NAME = "Html";
 
 	public static final LuanLoader LOADER = new LuanLoader() {
 		@Override protected void load(LuanState luan) {
--- a/src/luan/lib/HttpLib.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/lib/HttpLib.java	Sat Mar 02 05:02:56 2013 +0000
@@ -21,8 +21,8 @@
 
 public final class HttpLib {
 
-	public static final String NAME = "http";
-	public static final String FN_NAME = "http.server";
+	public static final String NAME = "Http";
+	public static final String FN_NAME = "Http.server";
 
 	public static void load(LuanState luan) throws LuanException {
 		PackageLib.require(luan,NAME);
--- a/src/luan/lib/JavaLib.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/lib/JavaLib.java	Sat Mar 02 05:02:56 2013 +0000
@@ -28,7 +28,7 @@
 
 public final class JavaLib {
 
-	public static final String NAME = "java";
+	public static final String NAME = "Java";
 
 	public static final LuanLoader LOADER = new LuanLoader() {
 		@Override protected void load(LuanState luan) {
--- a/src/luan/lib/MathLib.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/lib/MathLib.java	Sat Mar 02 05:02:56 2013 +0000
@@ -9,7 +9,7 @@
 
 public final class MathLib {
 
-	public static final String NAME = "math";
+	public static final String NAME = "Math";
 
 	public static final LuanLoader LOADER = new LuanLoader() {
 		@Override protected void load(LuanState luan) {
--- a/src/luan/lib/PackageLib.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/lib/PackageLib.java	Sat Mar 02 05:02:56 2013 +0000
@@ -17,7 +17,7 @@
 
 public final class PackageLib {
 
-	public static final String NAME = "package";
+	public static final String NAME = "Package";
 
 	public static final LuanLoader LOADER = new LuanLoader() {
 		@Override protected void load(LuanState luan) {
@@ -56,7 +56,7 @@
 	public static void require(LuanState luan,String modName,LuanTable env) throws LuanException {
 		LuanTable mod = (LuanTable)luan.loaded().get(modName);
 		if( mod == null ) {
-			LuanTable searchers = (LuanTable)luan.get("package.searchers");
+			LuanTable searchers = (LuanTable)luan.get("Package.searchers");
 			if( searchers == null )
 				searchers = new LuanTable(Collections.<Object>singletonList(preloadSearcher));
 			for( Object s : searchers.asList() ) {
@@ -103,7 +103,7 @@
 	public static final LuanFunction fileSearcher = new LuanFunction() {
 		public Object[] call(LuanState luan,Object[] args) throws LuanException {
 			String modName = (String)args[0];
-			String path = (String)luan.get("package.path");
+			String path = (String)luan.get("Package.path");
 			if( path==null )
 				return LuanFunction.EMPTY;
 			String file = search_path(modName,path);
@@ -143,7 +143,7 @@
 	public static final LuanFunction javaFileSearcher = new LuanFunction() {
 		public Object[] call(LuanState luan,Object[] args) throws LuanException {
 			String modName = (String)args[0];
-			String path = (String)luan.get("package.jpath");
+			String path = (String)luan.get("Package.jpath");
 			if( path==null )
 				return LuanFunction.EMPTY;
 			for( String s : path.split(";") ) {
--- a/src/luan/lib/StringLib.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/lib/StringLib.java	Sat Mar 02 05:02:56 2013 +0000
@@ -14,7 +14,7 @@
 
 public final class StringLib {
 
-	public static final String NAME = "string";
+	public static final String NAME = "String";
 
 	public static final LuanLoader LOADER = new LuanLoader() {
 		@Override protected void load(LuanState luan) {
--- a/src/luan/lib/TableLib.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/lib/TableLib.java	Sat Mar 02 05:02:56 2013 +0000
@@ -16,7 +16,7 @@
 
 public final class TableLib {
 
-	public static final String NAME = "table";
+	public static final String NAME = "Table";
 
 	public static final LuanLoader LOADER = new LuanLoader() {
 		@Override protected void load(LuanState luan) {
--- a/src/luan/tools/WebServlet.java	Thu Feb 28 09:47:38 2013 +0000
+++ b/src/luan/tools/WebServlet.java	Sat Mar 02 05:02:56 2013 +0000
@@ -25,39 +25,38 @@
 
 	protected LuanState luanState = null;
 
-	protected void loadLibs(LuanState luan) throws LuanException {
+	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);
-	}
-
-	protected LuanState newLuanState() throws LuanException {
-		LuanState luan = LuanCompiler.newLuanState();
-		loadLibs(luan);
-		HttpLib.load(luan);
 		return luan;
 	}
 
-	protected  LuanState getLuanState(HttpServletRequest request) throws LuanException {
-		synchronized(this) {
-			if( luanState == null )
-				luanState = newLuanState();
-		}
-		return luanState.deepClone();
-	}
-
 	@Override protected void service(HttpServletRequest request,HttpServletResponse response)
 		throws ServletException, IOException
 	{
 		try {
-			LuanState luan = getLuanState(request);
-			HttpLib.service(luan,request,response);
+			synchronized(this) {
+				if( luanState == null ) {
+					luanState = newLuanState();
+					HttpLib.load(luanState);
+				}
+			}
+			LuanState luan = luanState.deepClone();
+			service(request,response,luan);
 		} catch(LuanException e) {
 			throw new LuanRuntimeException(e);
 		}
 	}
 
+	protected void service(HttpServletRequest request,HttpServletResponse response,LuanState luan)
+		throws ServletException, IOException, LuanException
+	{
+		HttpLib.service(luan,request,response);
+	}
+
 }