changeset 503:92c3d22745b8

make _ENV optional
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 May 2015 23:24:46 -0600
parents d3183a330ff5
children dbdf4b8193a8
files core/src/luan/LuanState.java core/src/luan/LuanTable.java core/src/luan/impl/ConstExpr.java core/src/luan/impl/LuanCompiler.java core/src/luan/impl/LuanParser.java core/src/luan/impl/LuanStateImpl.java core/src/luan/impl/SetTableEntry.java core/src/luan/modules/Binary.luan core/src/luan/modules/Debug.luan core/src/luan/modules/Html.luan core/src/luan/modules/Io.luan core/src/luan/modules/JavaLuan.java core/src/luan/modules/Luan.luan core/src/luan/modules/Math.luan core/src/luan/modules/Package.luan core/src/luan/modules/PackageLuan.java core/src/luan/modules/String.luan core/src/luan/modules/StringLuan.java core/src/luan/modules/Table.luan core/src/luan/modules/Thread.luan core/src/luan/modules/Time.luan core/src/luan/modules/host/Hosting.luan core/src/luan/modules/mmake.luan http/src/luan/modules/http/Http.luan http/src/luan/modules/http/HttpTest.luan http/src/luan/modules/http/Server.luan http/src/luan/modules/http/run.luan http/src/luan/modules/http/shell.luan logging/src/luan/modules/logging/Logging.luan lucene/src/luan/modules/lucene/Ab_testing.luan lucene/src/luan/modules/lucene/Lucene.luan lucene/src/luan/modules/lucene/Web_search.luan mail/src/luan/modules/mail/Mail.luan scripts/test.luan stripe/src/luan/modules/stripe/Stripe.luan website/src/Shared.luan website/src/diff.html.luan website/src/docs.html.luan website/src/examples/hi.luan website/src/examples/hi2.luan website/src/examples/hi2_simply_html.luan website/src/index.html.luan website/src/manual.html.luan website/src/pil.html.luan website/src/tutorial.html.luan
diffstat 45 files changed, 526 insertions(+), 391 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/LuanState.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/LuanState.java	Wed May 20 23:24:46 2015 -0600
@@ -24,7 +24,8 @@
 		((LuanState)clone).registry = cloner.deepClone(registry);
 	}
 
-	public abstract LuanTable currentEnvironment();
+	public abstract boolean hasJava();
+	public abstract void setJava();
 	public abstract LuanSource currentSource();
 
 	public final Map registry() {
--- a/core/src/luan/LuanTable.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/LuanTable.java	Wed May 20 23:24:46 2015 -0600
@@ -22,7 +22,6 @@
 	private Map map = null;
 	private List list = null;
 	private LuanTable metatable = null;
-	private boolean hasJava = false;
 
 	public LuanTable() {}
 
@@ -81,7 +80,6 @@
 		}
 		if( metatable != null )
 			clone.metatable = (LuanTable)cloner.get(metatable);
-		clone.hasJava = hasJava;
 	}
 
 	public boolean isList() {
@@ -136,7 +134,7 @@
 			return StringLuan.__index(luan,(String)obj,key);
 		if( obj instanceof byte[] )
 			return BinaryLuan.__index(luan,(byte[])obj,key);
-		if( obj != null && luan.currentEnvironment().hasJava() )
+		if( obj != null && luan.hasJava() )
 			return JavaLuan.__index(luan,obj,key);
 		else if( bit.el==null )
 			throw bit.exception( "attempt to index a " + Luan.type(obj) + " value" );
@@ -434,14 +432,6 @@
 		return metatable==null ? null : metatable.rawGet(op);
 	}
 
-	public boolean hasJava() {
-		return hasJava;
-	}
-
-	public void setJava() {
-		hasJava = true;
-	}
-
 	private Map<Object,Object> newMap() {
 		return new LinkedHashMap<Object,Object>();
 	}
--- a/core/src/luan/impl/ConstExpr.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/impl/ConstExpr.java	Wed May 20 23:24:46 2015 -0600
@@ -6,8 +6,8 @@
 final class ConstExpr extends CodeImpl implements Expr {
 	private final Object obj;
 
-	ConstExpr(LuanElement se,Object obj) {
-		super(se);
+	ConstExpr(LuanElement el,Object obj) {
+		super(el);
 		this.obj = obj;
 	}
 
--- a/core/src/luan/impl/LuanCompiler.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/impl/LuanCompiler.java	Wed May 20 23:24:46 2015 -0600
@@ -15,10 +15,7 @@
 	private LuanCompiler() {}  // never
 
 	public static LuanFunction compile(LuanState luan,LuanSource src,LuanTable env,boolean allowExpr) throws LuanException {
-		if( env==null )
-			env = new LuanTable();
-		UpValue.Getter envGetter = new UpValue.ValueGetter(env);
-		LuanParser parser = new LuanParser(src,envGetter);
+		LuanParser parser = new LuanParser(src,env);
 		parser.addVar( "java", JavaLuan.javaFn );
 		parser.addVar( "require", PackageLuan.requireFn );
 		FnDef fnDef = parse(luan,parser,allowExpr);
--- a/core/src/luan/impl/LuanParser.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/impl/LuanParser.java	Wed May 20 23:24:46 2015 -0600
@@ -10,6 +10,7 @@
 import luan.LuanState;
 import luan.LuanSource;
 import luan.LuanElement;
+import luan.LuanTable;
 import luan.modules.PackageLuan;
 
 
@@ -24,15 +25,15 @@
 		final List<String> upValueSymbols = new ArrayList<String>();
 		final List<UpValue.Getter> upValueGetters = new ArrayList<UpValue.Getter>();
 
-		Frame(UpValue.Getter envGetter) {
+		Frame() {
 			this.parent = null;
-			upValueSymbols.add(_ENV);
-			upValueGetters.add(envGetter);
+			upValueSymbols.add(JAVA);
+			upValueGetters.add(new UpValue.ValueGetter(false));
 		}
 
 		Frame(Frame parent) {
 			this.parent = parent;
-			if( upValueIndex(_ENV) != 0 )
+			if( upValueIndex(JAVA) != 0 )
 				throw new RuntimeException();
 		}
 
@@ -92,19 +93,20 @@
 		}
 	}
 
+	private static final String JAVA = "-JAVA-";  // inaccessible from Luan
 	private static final String _ENV = "_ENV";
 	private static final UpValue.Getter[] NO_UP_VALUE_GETTERS = new UpValue.Getter[0];
 
 	final LuanSource source;
 	private Frame frame;
 	private final Parser parser;
-	private final boolean interactive;
 
-	LuanParser(LuanSource source,UpValue.Getter envGetter) {
+	LuanParser(LuanSource source,LuanTable env) {
 		this.source = source;
-		this.frame = new Frame(envGetter);
+		this.frame = new Frame();
 		this.parser = new Parser(source);
-		this.interactive = envGetter instanceof UpValue.ValueGetter;
+		if( env != null )
+			addVar(_ENV,env);
 	}
 
 	void addVar(String name,Object value) {
@@ -860,6 +862,11 @@
 		return parser.failure(null);
 	}
 
+	private interface Var {
+		public Expressions expr() throws ParseException;
+		public Settable settable() throws ParseException;
+	}
+
 	private Expr env() {
 		int index = stackIndex(_ENV);
 		if( index != -1 )
@@ -867,12 +874,7 @@
 		index = upValueIndex(_ENV);
 		if( index != -1 )
 			return new GetUpVar(null,index);
-		throw new RuntimeException("_ENV not found");
-	}
-
-	private interface Var {
-		public Expressions expr();
-		public Settable settable();
+		return null;
 	}
 
 	private Var nameVar(final int start,final String name) {
@@ -882,24 +884,32 @@
 	private Var nameVar(final LuanElement se,final String name) {
 		return new Var() {
 
-			public Expr expr() {
+			public Expr expr() throws ParseException {
 				int index = stackIndex(name);
 				if( index != -1 )
 					return new GetLocalVar(se,index);
 				index = upValueIndex(name);
 				if( index != -1 )
 					return new GetUpVar(se,index);
-				return new IndexExpr( se, env(), new ConstExpr(se,name) );
+				Expr envExpr = env();
+				if( envExpr != null )
+					return new IndexExpr( se, envExpr, new ConstExpr(se,name) );
+				parser.failure(null);
+				throw parser.exception("name '"+name+"' not defined");
 			}
 
-			public Settable settable() {
+			public Settable settable() throws ParseException {
 				int index = stackIndex(name);
 				if( index != -1 )
 					return new SetLocalVar(index);
 				index = upValueIndex(name);
 				if( index != -1 )
 					return new SetUpVar(index);
-				return new SetTableEntry( se, env(), new ConstExpr(se,name) );
+				Expr envExpr = env();
+				if( envExpr != null )
+					return new SetTableEntry( se, envExpr, new ConstExpr(se,name) );
+				parser.failure(null);
+				throw parser.exception("name '"+name+"' not defined");
 			}
 		};
 	}
--- a/core/src/luan/impl/LuanStateImpl.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/impl/LuanStateImpl.java	Wed May 20 23:24:46 2015 -0600
@@ -108,10 +108,14 @@
 		return frame.getUpValue(index);
 	}
 
-	@Override public LuanTable currentEnvironment() {
+	@Override public boolean hasJava() {
 		if( frame==null )
-			return null;
-		return (LuanTable)frame.closure.upValues()[0].get();
+			return false;
+		return (Boolean)frame.closure.upValues()[0].get();
+	}
+
+	@Override public void setJava() {
+		frame.closure.upValues()[0].set(true);
 	}
 
 	@Override public LuanSource currentSource(){
--- a/core/src/luan/impl/SetTableEntry.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/impl/SetTableEntry.java	Wed May 20 23:24:46 2015 -0600
@@ -29,7 +29,7 @@
 			tbl.put(luan,key,value);
 			return;
 		}
-		if( t != null && luan.currentEnvironment().hasJava() )
+		if( t != null && luan.hasJava() )
 			JavaLuan.__new_index(luan,t,key,value);
 		else
 			throw luan.bit(el).exception( "attempt to index '"+tableExpr.el().text()+"' (a " + Luan.type(t) + " value)" );
--- a/core/src/luan/modules/Binary.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Binary.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,6 +1,10 @@
 java()
 local BinaryLuan = require "java:luan.modules.BinaryLuan"
 
-byte = BinaryLuan.byte_
-binary = BinaryLuan.binary
-to_string = BinaryLuan.to_string
+local M = {}
+
+M.byte = BinaryLuan.byte_
+M.binary = BinaryLuan.binary
+M.to_string = BinaryLuan.to_string
+
+return M
--- a/core/src/luan/modules/Debug.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Debug.luan	Wed May 20 23:24:46 2015 -0600
@@ -5,14 +5,15 @@
 local print = Io.print
 local Table = require "luan:Table"
 
+local M = {}
 
-function print_if_something(...)
+function M.print_if_something(...)
 	if Table.pack(...).n > 0 then
 		print(...)
 	end
 end
 
-function debug(prompt)
+function M.debug(prompt)
 	prompt = prompt or "luan_debug> "
 	local function console()
 		return Io.read_console_line(prompt)
@@ -22,7 +23,7 @@
 		try {
 			function()
 				local fn = load(line,"stdin",env,true)
-				print_if_something( fn() )
+				M.print_if_something( fn() )
 			end;
 			catch = function(e)
 				print(e)
@@ -31,3 +32,4 @@
 	end
 end
 
+return M
--- a/core/src/luan/modules/Html.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Html.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,9 +1,11 @@
 java()
 local HtmlLuan = require "java:luan.modules.HtmlLuan"
 
-encode = HtmlLuan.encode
-parse = HtmlLuan.parse
-to_string = HtmlLuan.to_string
+local M = {}
+
+M.encode = HtmlLuan.encode
+M.parse = HtmlLuan.parse
+M.to_string = HtmlLuan.to_string
 
 
 
@@ -15,11 +17,11 @@
 local Io = require "luan:Io"
 local URLEncoder = require "java:java.net.URLEncoder"
 
-function url_encode(s)
+function M.url_encode(s)
 	return URLEncoder.encode(s,"UTF-8")
 end
 
-function process_url_tags(html)
+function M.process_url_tags(html)
 	for i, v in ipairs(html) do
 		if type(v) == "table" and v.type == "tag" then
 			if v.name == "url" then
@@ -34,7 +36,7 @@
 	end
 end
 
-function add_nofollow(html)
+function M.add_nofollow(html)
 	for i, v in ipairs(html) do
 		if type(v) == "table" and v.type == "tag" and v.name == "a" then
 			v.attributes.rel = "nofollow"
@@ -43,7 +45,7 @@
 end
 
 
-function simply_html_head() %>
+function M.simply_html_head() %>
 		<meta charset="utf-8">
 		<meta name="viewport" content="width=device-width, initial-scale=1">
 		
@@ -55,6 +57,8 @@
 		<script src="http://www.simplyhtml.org/assets/simplyhtml/simplyhtml.js"></script>
 <% end
 
-function simply_html_body_bottom() %>
+function M.simply_html_body_bottom() %>
 		<script src="http://www.simplyhtml.org/assets/bootstrap/js/bootstrap.min.js"></script>
 <% end
+
+return M
--- a/core/src/luan/modules/Io.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Io.luan	Wed May 20 23:24:46 2015 -0600
@@ -2,13 +2,15 @@
 local IoLuan = require "java:luan.modules.IoLuan"
 local System = require "java:java.lang.System"
 
-read_console_line = IoLuan.read_console_line
-schemes = IoLuan.newSchemes()
-uri = IoLuan.uri
-stdin = IoLuan.defaultStdin.table()
-socket_server = IoLuan.socket_server
-stdout = IoLuan.textWriter(System.out)
-stderr = IoLuan.textWriter(System.err)
+local M = {}
+
+M.read_console_line = IoLuan.read_console_line
+M.schemes = IoLuan.newSchemes()
+M.uri = IoLuan.uri
+M.stdin = IoLuan.defaultStdin.table()
+M.socket_server = IoLuan.socket_server
+M.stdout = IoLuan.textWriter(System.out)
+M.stderr = IoLuan.textWriter(System.err)
 
 
 local Luan = require "luan:Luan"
@@ -19,7 +21,7 @@
 local pairs = Luan.pairs
 local Table = require "luan:Table"
 
-function print_to(out,...)
+function M.print_to(out,...)
 	local list = {}
 	for v in Luan.values(...) do
 		list[#list+1] = to_string(v)
@@ -33,8 +35,8 @@
 	end
 end
 
-function print(...)
-	print_to(stdout,...)
+function M.print(...)
+	M.print_to(M.stdout,...)
 end
 
 
@@ -79,20 +81,20 @@
 	end
 end
 
-local uri = uri  -- make local
+local uri = M.uri  -- make local
 
-function repr(obj)
-	local old_out = stdout
+function M.repr(obj)
+	local old_out = M.stdout
 	return try {
 		function()
 			local string_uri = uri "string:"
-			stdout = string_uri.text_writer()
+			M.stdout = string_uri.text_writer()
 			do_repr(obj,{})
-			stdout.close()
+			M.stdout.close()
 			return string_uri.read_text()
 		end;
 		finally = function()
-			stdout = old_out
+			M.stdout = old_out
 		end;
 	}
 end
@@ -100,9 +102,10 @@
 
 -- useful for SimplyHTML responsiveness
 
-NO = {}
+local NO = {}
+M.NO = NO
 
-function dont_write_when_no(write_fn)
+function M.dont_write_when_no(write_fn)
 	return function(...)
 		for v in Luan.values(...) do
 			if v == NO then
@@ -112,3 +115,5 @@
 		write_fn(...)
 	end
 end
+
+return M
--- a/core/src/luan/modules/JavaLuan.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/JavaLuan.java	Wed May 20 23:24:46 2015 -0600
@@ -29,7 +29,7 @@
 
 	public static void java(LuanState luan) throws LuanException {
 		check(luan,luan.currentSource().name);
-		luan.currentEnvironment().setJava();
+		luan.setJava();
 	}
 
 	public static final LuanFunction javaFn;
@@ -42,7 +42,7 @@
 	}
 
 	private static void checkJava(LuanState luan) throws LuanException {
-		if( !luan.currentEnvironment().hasJava() )
+		if( !luan.hasJava() )
 			throw luan.exception("Java isn't allowed");
 	}
 
--- a/core/src/luan/modules/Luan.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Luan.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,45 +1,45 @@
 java()
 local BasicLuan = require "java:luan.modules.BasicLuan"
 
-assert_binary = BasicLuan.assert_binary
-assert_boolean = BasicLuan.assert_boolean
-assert_integer = BasicLuan.assert_integer
-assert_long = BasicLuan.assert_long
-assert_number = BasicLuan.assert_number
-assert_string = BasicLuan.assert_string
-assert_table = BasicLuan.assert_table
-get_metatable = BasicLuan.get_metatable
-ipairs = BasicLuan.ipairs
-load = BasicLuan.load
-load_file = BasicLuan.load_file
-new_error = BasicLuan.new_error
-pairs = BasicLuan.pairs
-pcall = BasicLuan.pcall
-range = BasicLuan.range
-raw_equal = BasicLuan.raw_equal
-raw_get = BasicLuan.raw_get
-raw_len = BasicLuan.raw_len
-raw_set = BasicLuan.raw_set
-set_metatable = BasicLuan.set_metatable
-to_string = BasicLuan.to_string
-try = BasicLuan.try_
-type = BasicLuan.type
-values = BasicLuan.values
+local M = {}
 
-function do_file(uri)
-	return load_file(uri)()
+M.assert_binary = BasicLuan.assert_binary
+M.assert_boolean = BasicLuan.assert_boolean
+M.assert_integer = BasicLuan.assert_integer
+M.assert_long = BasicLuan.assert_long
+M.assert_number = BasicLuan.assert_number
+M.assert_string = BasicLuan.assert_string
+M.assert_table = BasicLuan.assert_table
+M.get_metatable = BasicLuan.get_metatable
+M.ipairs = BasicLuan.ipairs
+M.load = BasicLuan.load
+M.load_file = BasicLuan.load_file
+M.new_error = BasicLuan.new_error
+M.pairs = BasicLuan.pairs
+M.pcall = BasicLuan.pcall
+M.range = BasicLuan.range
+M.raw_equal = BasicLuan.raw_equal
+M.raw_get = BasicLuan.raw_get
+M.raw_len = BasicLuan.raw_len
+M.raw_set = BasicLuan.raw_set
+M.set_metatable = BasicLuan.set_metatable
+M.to_string = BasicLuan.to_string
+M.try = BasicLuan.try_
+M.type = BasicLuan.type
+M.values = BasicLuan.values
+
+function M.do_file(uri)
+	return M.load_file(uri)()
 end
 
-VERSION = do_file "classpath:luan/version.luan"
+M.VERSION = M.do_file "classpath:luan/version.luan"
 
-local new_error = new_error
-
-function error(message)
-	new_error(message).throw()
+function M.error(message)
+	M.new_error(message).throw()
 end
 
-local error = error
+function M.assert(v,message)
+	return v or M.error(message or "assertion failed!")
+end
 
-function assert(v,message)
-	return v or error(message or "assertion failed!")
-end
+return M
--- a/core/src/luan/modules/Math.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Math.luan	Wed May 20 23:24:46 2015 -0600
@@ -3,30 +3,34 @@
 local JavaMath = require "java:java.lang.Math"
 local Integer = require "java:java.lang.Integer"
 
-abs = MathLuan.abs
-acos = MathLuan.acos
-asin = MathLuan.asin
-atan = MathLuan.atan
-atan2 = MathLuan.atan2
-ceil = MathLuan.ceil
-cos = MathLuan.cos
-cosh = MathLuan.cosh
-deg = MathLuan.deg
-exp = MathLuan.exp
-floor = MathLuan.floor
-log = MathLuan.log
-min = MathLuan.min
-min_integer = Integer.MIN_VALUE
-max = MathLuan.max
-max_integer = Integer.MAX_VALUE
-modf = MathLuan.modf
-pi = JavaMath.PI
-pow = MathLuan.pow
-rad = MathLuan.rad
-random = MathLuan.random
-sin = MathLuan.sin
-sinh = MathLuan.sinh
-sqrt = MathLuan.sqrt
-tan = MathLuan.tan
-tanh = MathLuan.tanh
-to_string = MathLuan.to_string
+local M = {}
+
+M.abs = MathLuan.abs
+M.acos = MathLuan.acos
+M.asin = MathLuan.asin
+M.atan = MathLuan.atan
+M.atan2 = MathLuan.atan2
+M.ceil = MathLuan.ceil
+M.cos = MathLuan.cos
+M.cosh = MathLuan.cosh
+M.deg = MathLuan.deg
+M.exp = MathLuan.exp
+M.floor = MathLuan.floor
+M.log = MathLuan.log
+M.min = MathLuan.min
+M.min_integer = Integer.MIN_VALUE
+M.max = MathLuan.max
+M.max_integer = Integer.MAX_VALUE
+M.modf = MathLuan.modf
+M.pi = JavaMath.PI
+M.pow = MathLuan.pow
+M.rad = MathLuan.rad
+M.random = MathLuan.random
+M.sin = MathLuan.sin
+M.sinh = MathLuan.sinh
+M.sqrt = MathLuan.sqrt
+M.tan = MathLuan.tan
+M.tanh = MathLuan.tanh
+M.to_string = MathLuan.to_string
+
+return M
--- a/core/src/luan/modules/Package.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Package.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,5 +1,9 @@
 java()
 local PackageLuan = require "java:luan.modules.PackageLuan"
 
-loaded = PackageLuan.loaded()
-load = PackageLuan.load
+local M = {}
+
+M.loaded = PackageLuan.loaded()
+M.load = PackageLuan.load
+
+return M
--- a/core/src/luan/modules/PackageLuan.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/PackageLuan.java	Wed May 20 23:24:46 2015 -0600
@@ -49,12 +49,16 @@
 				String src = read(luan,modName,true);
 				if( src == null )
 					return null;
-				LuanTable env = new LuanTable();
-				LuanFunction loader = BasicLuan.load(luan,src,modName,env,false);
-				Object result = Luan.first(
+				LuanFunction loader = BasicLuan.load(luan,src,modName,null,false);
+				mod = Luan.first(
 					luan.call(loader,"<require \""+modName+"\">",new Object[]{modName})
 				);
-				mod = result!=null ? result : env;
+				if( mod == null ) {
+					mod = loaded.rawGet(modName);
+					if( mod != null )
+						return mod;
+					throw luan.exception( "module '"+modName+"' returned nil" );
+				}
 			}
 			loaded.rawPut(modName,mod);
 		}
--- a/core/src/luan/modules/String.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/String.luan	Wed May 20 23:24:46 2015 -0600
@@ -2,23 +2,27 @@
 local StringLuan = require "java:luan.modules.StringLuan"
 local Pattern = require "java:java.util.regex.Pattern"
 
-unicode = StringLuan.unicode
-char = StringLuan.char_
-concat = StringLuan.concat
-encode = StringLuan.encode
-find = StringLuan.find
-format = StringLuan.format
-gmatch = StringLuan.gmatch
-gsub = StringLuan.gsub
-len = StringLuan.len
-literal = Pattern.quote
-lower = StringLuan.lower
-match = StringLuan.match
-matches = StringLuan.matches
-rep = StringLuan.rep
-reverse = StringLuan.reverse
-sub = StringLuan.sub
-to_binary = StringLuan.to_binary
-to_number = StringLuan.to_number
-trim = StringLuan.trim
-upper = StringLuan.upper
+local M = {}
+
+M.unicode = StringLuan.unicode
+M.char = StringLuan.char_
+M.concat = StringLuan.concat
+M.encode = StringLuan.encode
+M.find = StringLuan.find
+M.format = StringLuan.format
+M.gmatch = StringLuan.gmatch
+M.gsub = StringLuan.gsub
+M.len = StringLuan.len
+M.literal = Pattern.quote
+M.lower = StringLuan.lower
+M.match = StringLuan.match
+M.matches = StringLuan.matches
+M.rep = StringLuan.rep
+M.reverse = StringLuan.reverse
+M.sub = StringLuan.sub
+M.to_binary = StringLuan.to_binary
+M.to_number = StringLuan.to_number
+M.trim = StringLuan.trim
+M.upper = StringLuan.upper
+
+return M
--- a/core/src/luan/modules/StringLuan.java	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/StringLuan.java	Wed May 20 23:24:46 2015 -0600
@@ -28,7 +28,7 @@
 				}
 			};
 		}
-		if( luan.currentEnvironment().hasJava() )
+		if( luan.hasJava() )
 			return JavaLuan.__index(luan,s,key);
 		return null;
 	}
--- a/core/src/luan/modules/Table.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Table.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,20 +1,24 @@
 java()
 local TableLuan = require "java:luan.modules.TableLuan"
 
-clone = TableLuan.clone
-concat = TableLuan.concat
-insert = TableLuan.insert
-new_property_table = TableLuan.new_property_table
-pack = TableLuan.pack
-remove = TableLuan.remove
-sort = TableLuan.sort
-sub_list = TableLuan.sub_list
-unpack = TableLuan.unpack
+local M = {}
+
+M.clone = TableLuan.clone
+M.concat = TableLuan.concat
+M.insert = TableLuan.insert
+M.new_property_table = TableLuan.new_property_table
+M.pack = TableLuan.pack
+M.remove = TableLuan.remove
+M.sort = TableLuan.sort
+M.sub_list = TableLuan.sub_list
+M.unpack = TableLuan.unpack
 
 
 local Luan = require "luan:Luan"
 local pairs = Luan.pairs
 
-function is_empty(t)
+function M.is_empty(t)
 	return pairs(t)() == nil
 end
+
+return M
--- a/core/src/luan/modules/Thread.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Thread.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,4 +1,8 @@
 java()
 local ThreadLuan = require "java:luan.modules.ThreadLuan"
 
-fork = ThreadLuan.fork
+local M = {}
+
+M.fork = ThreadLuan.fork
+
+return M
--- a/core/src/luan/modules/Time.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/Time.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,7 +1,9 @@
 -- incomplete, will add as needed
 
 java()
-require "luan:String"
+local Luan = require "luan:Luan"
+local ipairs = Luan.ipairs
+local error = Luan.error
 local Table = require "luan:Table"
 local System = require "java:java.lang.System"
 local Calendar = require "java:java.util.Calendar"
@@ -9,8 +11,9 @@
 local TimeZone = require "java:java.util.TimeZone"
 local SimpleDateFormat = require "java:java.text.SimpleDateFormat"
 
+local M = {}
 
-function now()
+function M.now()
 	return System.currentTimeMillis()
 end
 
@@ -21,7 +24,7 @@
 	day_of_month = Calendar.DAY_OF_MONTH;
 }
 
-function get( time, ... )
+function M.get( time, ... )
 	local cal = Calendar.getInstance()
 	cal.setTimeInMillis(time)
 	local rtn = {}
@@ -37,12 +40,12 @@
 	return Table.unpack(rtn)
 end
 
-function format(time,pattern)
+function M.format(time,pattern)
 	pattern = pattern or "yyyy-MM-dd HH:m:ss"
 	return SimpleDateFormat.new(pattern).format(Date.new(time))
 end
 
-function on( year, month, day, hour, minute, second, millis )
+function M.on( year, month, day, hour, minute, second, millis )
 	month = month - 1
 	local cal = Calendar.getInstance()
 	cal.setLenient(false)
@@ -51,7 +54,7 @@
 	return cal.getTimeInMillis()
 end
 
-function period( days, hours, minutes, seconds, millis )
+function M.period( days, hours, minutes, seconds, millis )
 	local cal = Calendar.getInstance()
 	cal.setTimeZone(TimeZone.getTimeZone("GMT"))
 	days = days + 1
@@ -60,6 +63,8 @@
 	return cal.getTimeInMillis()
 end
 
-function parse( pattern, source )
+function M.parse( pattern, source )
 	return SimpleDateFormat.new(pattern).parse(source).getTime()
 end
+
+return M
--- a/core/src/luan/modules/host/Hosting.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/host/Hosting.luan	Wed May 20 23:24:46 2015 -0600
@@ -4,14 +4,15 @@
 local Luan = require "luan:Luan"
 local error = Luan.error
 
+local M = {}
 
-port = 9101
+M.port = 9101
 
-function push(domain,password,dir)
+function M.push(domain,password,dir)
 	local f = Io.uri("file:"..dir)
 	f.exists() or error("directory '"..dir.."' not found")
 	f.is_directory() or error("'"..dir.."' is not a directory")
-	local socket = "socket:" .. domain .. ":" .. port
+	local socket = "socket:" .. domain .. ":" .. M.port
 	local pc = Io.uri(socket).pickle_client()
 	local pickle = pc.pickle
 	pc.call(%>
@@ -21,8 +22,8 @@
 	pc.close()
 end
 
-function delete(domain,password)
-	local socket = "socket:" .. domain .. ":" .. port
+function M.delete(domain,password)
+	local socket = "socket:" .. domain .. ":" .. M.port
 	local pc = Io.uri(socket).pickle_client()
 	local pickle = pc.pickle
 	pc.call(%>
@@ -31,3 +32,5 @@
 	<%)
 	pc.close()
 end
+
+return M
--- a/core/src/luan/modules/mmake.luan	Tue May 19 17:57:20 2015 -0600
+++ b/core/src/luan/modules/mmake.luan	Wed May 20 23:24:46 2015 -0600
@@ -7,9 +7,23 @@
 local Time = require "luan:Time"
 
 
-compiler = Table.concat( { "javac -g -encoding UTF8", ... }, " " )
+local compiler = Table.concat( { "javac -g -encoding UTF8", ... }, " " )
+
+
+local function header()
+	return 	%>
+# Makefile created on <%=Time.format(Time.now())%> by Mmake
+
+.SUFFIXES: .java .class
 
-function mmake(dir)
+.java.class:
+	<%=compiler%> $<
+
+all: <%
+end
+
+
+local function mmake(dir)
 	local javas = {}
 	local dirs = {}
 	for _, file in ipairs(dir.children()) do
@@ -41,17 +55,4 @@
 	return true
 end
 
-
-function header()
-	return 	%>
-# Makefile created on <%=Time.format(Time.now())%> by Mmake
-
-.SUFFIXES: .java .class
-
-.java.class:
-	<%=compiler%> $<
-
-all: <%
-end
-
 mmake(Io.schemes.file ".")
--- a/http/src/luan/modules/http/Http.luan	Tue May 19 17:57:20 2015 -0600
+++ b/http/src/luan/modules/http/Http.luan	Wed May 20 23:24:46 2015 -0600
@@ -9,6 +9,7 @@
 local HttpServicer = require "java:luan.modules.http.HttpServicer"
 local IoLuan = require "java:luan.modules.IoLuan"
 
+local M = {}
 
 local singular_metatable = {}
 
@@ -39,7 +40,7 @@
 end
 
 
-function new_request(this)
+function M.new_request(this)
 	this = new_common(this)
 	this.method = "GET"  -- default
 	-- this.path
@@ -79,12 +80,13 @@
 	return this
 end
 
-STATUS = {
+local STATUS = {
 	OK = 200;
 	-- add more as needed
 }
+M.STATUS = STATUS
 
-function new_response(this)
+function M.new_response(this)
 	this = new_common(this)
 	this.status = STATUS.OK
 	if this.java ~= nil then
@@ -92,11 +94,11 @@
 		this.send_error = this.java.sendError
 
 		function this.set_cookie(name,value,is_persistent,domain)
-			HttpServicer.setCookie(this.java,response.java,name,value,is_persistent,domain)
+			HttpServicer.setCookie(this.java,M.response.java,name,value,is_persistent,domain)
 		end
 
 		function this.remove_cookie(name,domain)
-			HttpServicer.removeCookie(this.java,response.java,name,domain)
+			HttpServicer.removeCookie(this.java,M.response.java,name,domain)
 		end
 
 		function this.text_writer()
@@ -113,51 +115,4 @@
 -- request = new_request{}  -- filled in by HttpServicer
 -- response = new_response{}  -- filled in by HttpServicer
 
-
-
-function init_for_test()
-
-	test = test or {}
-
-	test.welcome_file = "index.html"
-
-	function get_page(path)
-		if test.welcome_file ~= nil and path.matches ".*/" then
-			path = path .. test.welcome_file
-		end
-		local old_out = Io.stdout
-		local mod = require("site:"..path)
-		mod.respond()
-		test.text_writer.close()
-		Io.stdout = old_out
-		return result.read_text()
-	end
-
-	test.cookies = test.cookies or {}
-
-	request = new_request{}
-	request.cookies = test.cookies
-
-	response = new_response{
-
-		text_writer = function()
-			result = Io.uri "string:"
-			test.text_writer = result.text_writer()
-			return test.text_writer
-		end;
-
-		set_cookie = function(name,value)
-			test.cookies[name] = value
-		end;
-
-		remove_cookie = function(name)
-			test.cookies[name] = nil
-		end;
-
-		send_redirect = function(url)
-			response.redirect = url
-		end;
-
-	}
-
-end
+return M
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/http/src/luan/modules/http/HttpTest.luan	Wed May 20 23:24:46 2015 -0600
@@ -0,0 +1,49 @@
+local Io = require "luan:Io"
+local Http = require "luan:http/Http"
+
+local M = {}
+
+M.welcome_file = "index.html"
+M.cookies = {}
+
+function M.get_page(path)
+	if M.welcome_file ~= nil and path.matches ".*/" then
+		path = path .. M.welcome_file
+	end
+	local old_out = Io.stdout
+	local mod = require("site:"..path)
+	mod.respond()
+	M.text_writer.close()
+	Io.stdout = old_out
+	return M.result.read_text()
+end
+
+function M.init()
+	Http.request = Http.new_request{}
+	Http.request.cookies = M.cookies
+
+	Http.response = Http.new_response{
+
+		text_writer = function()
+			M.result = Io.uri "string:"
+			M.text_writer = M.result.text_writer()
+			return M.text_writer
+		end;
+
+		set_cookie = function(name,value)
+			M.cookies[name] = value
+		end;
+
+		remove_cookie = function(name)
+			M.cookies[name] = nil
+		end;
+
+		send_redirect = function(url)
+			Http.response.redirect = url
+		end;
+
+	}
+
+end
+
+return M
--- a/http/src/luan/modules/http/Server.luan	Tue May 19 17:57:20 2015 -0600
+++ b/http/src/luan/modules/http/Server.luan	Wed May 20 23:24:46 2015 -0600
@@ -20,81 +20,84 @@
 local LuanHandler = require "java:luan.modules.http.LuanHandler"
 local NotFound = require "java:luan.modules.http.NotFound"
 
+local M = {}
 
-port = 8080
+M.port = 8080
 
-private_password = "password"
+M.private_password = "password"
 
-welcome_file = "index.html"
+M.welcome_file = "index.html"
 
 
-authentication_handler = AuthenticationHandler.new("/private/")
+M.authentication_handler = AuthenticationHandler.new("/private/")
 
-luan_handler = LuanHandler.new()
+M.luan_handler = LuanHandler.new()
 
-resource_handler = ResourceHandler.new()
-resource_handler.setDirectoriesListed(true)
+M.resource_handler = ResourceHandler.new()
+M.resource_handler.setDirectoriesListed(true)
 
-handlers = HandlerList.new()
-handlers.setHandlers { authentication_handler, luan_handler, resource_handler }
+M.handlers = HandlerList.new()
+M.handlers.setHandlers { M.authentication_handler, M.luan_handler, M.resource_handler }
 
-function add_folder(context,dir)
+function M.add_folder(context,dir)
 	local rh = ResourceHandler.new()
 	rh.setResourceBase(dir)
 	rh.setDirectoriesListed(true)
 	local ch = ContextHandler.new(context)
 	ch.setHandler(rh)
-	handlers.addHandler(ch)
+	M.handlers.addHandler(ch)
 	return rh
 end
 
-handler_wrapper = HandlerWrapper.new()
-handler_wrapper.setHandler(handlers)
+M.handler_wrapper = HandlerWrapper.new()
+M.handler_wrapper.setHandler(M.handlers)
 
-function zip()
+function M.zip()
 	local h = GzipHandler.new()
-	h.setHandler(handler_wrapper.getHandler())
-	handler_wrapper.setHandler(h)
+	h.setHandler(M.handler_wrapper.getHandler())
+	M.handler_wrapper.setHandler(h)
 end
 
-log = NCSARequestLog.new()
-log.setExtended(false)
-log_handler = RequestLogHandler.new()
-log_handler.setRequestLog(log)
+M.log = NCSARequestLog.new()
+M.log.setExtended(false)
+M.log_handler = RequestLogHandler.new()
+M.log_handler.setRequestLog(M.log)
 
-function set_log_file(file_name)
-	log.setFilename(file_name)
+function M.set_log_file(file_name)
+	M.log.setFilename(file_name)
 end
 
 local hc = HandlerCollection.new()
-hc.setHandlers { SessionHandler.new(), handler_wrapper, DefaultHandler.new(), log_handler }
+hc.setHandlers { SessionHandler.new(), M.handler_wrapper, DefaultHandler.new(), M.log_handler }
 
 
-function init(dir)
+function M.init(dir)
 	dir = dir.gsub("/$","")  -- remove trailing '/' if any
 	Http.dir = dir
 	function Io.schemes.site(path,add_extension)
 		return Io.uri( dir..path, add_extension )
 	end
-	authentication_handler.setPassword(private_password)
+	M.authentication_handler.setPassword(M.private_password)
 	local base = dir
 	if base.match("^classpath:") ~= nil then
-		base = dir.."#"..welcome_file.."#"..welcome_file..".luan"
+		base = dir.."#"..M.welcome_file.."#"..M.welcome_file..".luan"
 	end
-	resource_handler.setResourceBase(Io.uri(base).to_string())
-	resource_handler.setWelcomeFiles {welcome_file}
-	luan_handler.setWelcomeFile(welcome_file)
-	handlers.addHandler(NotFound.new())
-	server = Server.new(port)
-	server.setHandler(hc)
+	M.resource_handler.setResourceBase(Io.uri(base).to_string())
+	M.resource_handler.setWelcomeFiles {M.welcome_file}
+	M.luan_handler.setWelcomeFile(M.welcome_file)
+	M.handlers.addHandler(NotFound.new())
+	M.server = Server.new(M.port)
+	M.server.setHandler(hc)
 	Package.load("site:/init")
 end
 
-function start()
-	server.start()
+function M.start()
+	M.server.start()
 end
 
-function serve(dir)
-	init(dir)
-	start()
+function M.serve(dir)
+	M.init(dir)
+	M.start()
 end
+
+return M
--- a/http/src/luan/modules/http/run.luan	Tue May 19 17:57:20 2015 -0600
+++ b/http/src/luan/modules/http/run.luan	Wed May 20 23:24:46 2015 -0600
@@ -7,6 +7,8 @@
 local String = require "luan:String"
 local Html = require "luan:Html"
 
+local M = {}
+
 local function lines(s)
 	local matcher = s.gmatch "([^\n]*)\n|([^\n])+$"
 	return function()
@@ -16,7 +18,7 @@
 end
 
 local function print_with_line_numbers(s)
-	i = 1
+	local i = 1
 	for line in lines(s) do
 		print(i,line)
 		i = i + 1
@@ -47,7 +49,7 @@
 </html>
 <% end
 
-function respond()
+function M.respond()
 	Io.stdout = Http.response.text_writer()
 	local code = Http.request.parameter.code
 	if code == nil then
@@ -76,3 +78,5 @@
 		end;
 	}
 end
+
+return M
--- a/http/src/luan/modules/http/shell.luan	Tue May 19 17:57:20 2015 -0600
+++ b/http/src/luan/modules/http/shell.luan	Wed May 20 23:24:46 2015 -0600
@@ -8,12 +8,14 @@
 local Http = require "luan:http/Http"
 local Html = require "luan:Html"
 
-per_session = true
+local M = {}
+
+M.per_session = true
 
 local history = {}
-env = {}
+M.env = {}
 
-function respond()
+function M.respond()
 	if Http.request.parameter.clear ~= nil then
 		history = {}
 	else
@@ -28,7 +30,7 @@
 			print( "% "..cmd )
 			try {
 				function()
-					local line = load(cmd,"<web_shell>",env,true)
+					local line = load(cmd,"<web_shell>",M.env,true)
 					Debug.print_if_something( line() )
 				end;
 				catch = function(e)
@@ -66,3 +68,5 @@
 </html>
 <%
 end
+
+return M
--- a/logging/src/luan/modules/logging/Logging.luan	Tue May 19 17:57:20 2015 -0600
+++ b/logging/src/luan/modules/logging/Logging.luan	Wed May 20 23:24:46 2015 -0600
@@ -6,52 +6,53 @@
 local RollingFileAppender = require "java:org.apache.log4j.RollingFileAppender"
 local LuanLogger = require "java:luan.modules.logging.LuanLogger"
 
+local M = {}
 
-layout = "%d %-5p %c - %m%n"
+M.layout = "%d %-5p %c - %m%n"
 
-level = "INFO"
+M.level = "INFO"
 
-console = "System.err"  -- or "System.out" or set to nil for no console
+M.console = "System.err"  -- or "System.out" or set to nil for no console
 
-file = nil  -- set to file name if you want logging to a file
+M.file = nil  -- set to file name if you want logging to a file
 
-max_file_size = nil  -- by default is "10MB"
+M.max_file_size = nil  -- by default is "10MB"
 
 
-log4j_root_logger = Logger.getRootLogger()
+M.log4j_root_logger = Logger.getRootLogger()
 
 local function to_level(level)
 	return level and Level.toLevel(level)
 end
 
-function log_to_file(file,logger_name)  -- logger_name is optional, defaults to root logger
-	local appender = RollingFileAppender.new(ptn_layout, file)
-	appender.setMaxFileSize(max_file_size)
-	local logger = logger_name and Logger.getLogger(logger_name) or log4j_root_logger
+function M.log_to_file(file,logger_name)  -- logger_name is optional, defaults to root logger
+	local appender = RollingFileAppender.new(M.ptn_layout, file)
+	appender.setMaxFileSize(M.max_file_size)
+	local logger = logger_name and Logger.getLogger(logger_name) or M.log4j_root_logger
 	logger.addAppender(appender)
 	return appender
 end
 
-function init()
-	log4j_root_logger.removeAllAppenders()
-	log4j_root_logger.setLevel( to_level(level) )
-	ptn_layout = EnhancedPatternLayout.new(layout)
+function M.init()
+	M.log4j_root_logger.removeAllAppenders()
+	M.log4j_root_logger.setLevel( to_level(M.level) )
+	M.ptn_layout = EnhancedPatternLayout.new(M.layout)
 
-	if console ~= nil then
-		console_appender = ConsoleAppender.new(ptn_layout,console)
-		log4j_root_logger.addAppender(console_appender)
+	if M.console ~= nil then
+		M.console_appender = ConsoleAppender.new(M.ptn_layout,M.console)
+		M.log4j_root_logger.addAppender(M.console_appender)
 	else
-		console_appender = nil
+		M.console_appender = nil
 	end
 
-	if file ~= nil then
-		file_appender = log_to_file(file)
+	if M.file ~= nil then
+		M.file_appender = M.log_to_file(M.file)
 	else
-		file_appender = nil
+		M.file_appender = nil
 	end
 end
 
-init()
+M.init()
 
 
 local function to_luan_logger(log4j_logger)
@@ -80,10 +81,12 @@
 	return tbl
 end
 
-function logger(name)
+function M.logger(name)
 	return to_luan_logger( Logger.getLogger(name) )
 end
 
-function root_logger()
+function M.root_logger()
 	return to_luan_logger( Logger.getRootLogger() )
 end
+
+return M
--- a/lucene/src/luan/modules/lucene/Ab_testing.luan	Tue May 19 17:57:20 2015 -0600
+++ b/lucene/src/luan/modules/lucene/Ab_testing.luan	Wed May 20 23:24:46 2015 -0600
@@ -9,10 +9,11 @@
 local Http = require "luan:http/Http"
 local Logging = require "luan:logging/Logging"
 
+local M = {}
 
 local logger = Logging.logger "Ab_testing"
 
-function of(index)
+function M.of(index)
 
 	local ab_testing = {}
 
@@ -91,8 +92,8 @@
 				for value, count in pairs(results[event]) do
 					fancy[event][value] = {}
 					fancy[event][value].count = count
-					fancy[event][value].pct_of_total = percent(count,all[value])
-					fancy[event][value].pct_of_prev = percent(count,prev[value])
+					fancy[event][value].pct_of_total = M.percent(count,all[value])
+					fancy[event][value].pct_of_prev = M.percent(count,prev[value])
 				end
 				prev = results[event]
 			end
@@ -140,7 +141,7 @@
 				results[name] = test.fancy_results()
 			end
 			Io.stdout = Http.response.text_writer()
-			html(test_names,ab_testing.test_map,results)
+			M.html(test_names,ab_testing.test_map,results)
 		end }
 	end
 
@@ -151,7 +152,7 @@
 -- aggregator factories
 
 -- fn(doc) should return boolean whether doc should be counted
-function count(fn)
+function M.count(fn)
 	return function()
 		local aggregator = {}
 		aggregator.result = 0
@@ -164,10 +165,10 @@
 	end
 end
 
-count_all = count( function(doc) return true end )
+M.count_all = M.count( function(doc) return true end )
 
 -- fn(doc) should return number to add to result, return 0 for nothing
-function sum(fn)
+function M.sum(fn)
 	return function()
 		local aggregator = {}
 		aggregator.result = 0
@@ -180,7 +181,7 @@
 
 
 
-function percent(x,total)
+function M.percent(x,total)
 	if total==0 then
 		return 0
 	else
@@ -204,7 +205,7 @@
 	return v.gsub([[(\d+\.\d{1})\d+]],'$1')
 end
 
-function html(test_names,tests,results) %>
+function M.html(test_names,tests,results) %>
 <!DOCTYPE html>
 <html lang="en">
 	<head>
@@ -265,3 +266,5 @@
 	</body>
 </html>
 <% end
+
+return M
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Tue May 19 17:57:20 2015 -0600
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,7 +1,9 @@
 java()
 local Luan = require "luan:Luan"
 local pairs = Luan.pairs
+local ipairs = Luan.ipairs
 local type = Luan.type
+local error = Luan.error
 local Table = require "luan:Table"
 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
 local Term = require "java:org.apache.lucene.index.Term"
@@ -12,8 +14,9 @@
 local Sort = require "java:org.apache.lucene.search.Sort"
 local SortField = require "java:org.apache.lucene.search.SortField"
 
+local M = {}
 
-function index(indexDir)
+function M.index(indexDir)
 	local index = {}
 	local java_index = LuceneIndex.new(indexDir)
 	index.fields = java_index.fields.newTable()
@@ -127,3 +130,5 @@
 
 	return index
 end
+
+return M
--- a/lucene/src/luan/modules/lucene/Web_search.luan	Tue May 19 17:57:20 2015 -0600
+++ b/lucene/src/luan/modules/lucene/Web_search.luan	Wed May 20 23:24:46 2015 -0600
@@ -8,6 +8,7 @@
 local String = require "luan:String"
 local Html = require "luan:Html"
 
+local M = {}
 
 local function form() %>
 <html>
@@ -119,7 +120,7 @@
 end
 
 
-function of(index)
+function M.of(index)
 
 	return { respond = function()
 		Io.stdout = Http.response.text_writer()
@@ -147,3 +148,5 @@
 	end }
 
 end
+
+return M
--- a/mail/src/luan/modules/mail/Mail.luan	Tue May 19 17:57:20 2015 -0600
+++ b/mail/src/luan/modules/mail/Mail.luan	Wed May 20 23:24:46 2015 -0600
@@ -4,12 +4,14 @@
 local System = require "java:java.lang.System"
 local SmtpCon = require "java:luan.modules.mail.SmtpCon"
 
+local M = {}
 
 System.setProperty( "mail.mime.charset", "UTF-8" )
 
-
-function Sender(params)
+function M.Sender(params)
 	assert_table(params)
 	local smtpCon = SmtpCon.new(params)
 	return { send = smtpCon.send }
 end
+
+return M
--- a/scripts/test.luan	Tue May 19 17:57:20 2015 -0600
+++ b/scripts/test.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,10 +1,26 @@
+local Binary = require "luan:Binary"
+local Debug = require "luan:Debug"
+local Html = require "luan:Html"
+local Io = require "luan:Io"
 local Luan = require "luan:Luan"
+local Math = require "luan:Math"
+local Package = require "luan:Package"
+local String = require "luan:String"
+local Table = require "luan:Table"
+local Thread = require "luan:Thread"
+local Time = require "luan:Time"
+local Hosting = require "luan:host/Hosting"
+local Http = require "luan:http/Http"
+local HttpTest = require "luan:http/HttpTest"
+local Server = require "luan:http/Server"
+local Lucene = require "luan:lucene/Lucene"
+local Mail = require "luan:mail/Mail"
+local Stripe = require "luan:stripe/Stripe"
+
 local error = Luan.error
 local range = Luan.range
-local Io = require "luan:Io"
-local Http = require "luan:http/Http"
-local init_for_test = Http.init_for_test
-local Lucene = require "luan:lucene/Lucene"
+local init = HttpTest.init
+local get_page = HttpTest.get_page
 local Ab_testing = require "luan:lucene/Ab_testing"
 
 
@@ -16,30 +32,31 @@
 	return Io.uri( "luan:http"..path, add_extension )
 end
 
+local page
 
-init_for_test()
+init()
 Http.request.parameter.code = "require('luan:Io').print 'hi'"
-page = Http.get_page "/run"
+page = get_page "/run"
 page.trim() == "hi" or error "failed"
 
-init_for_test()
+init()
 Http.request.parameter.cmd = "'ab'..'cd'"
-page = Http.get_page "/shell"
+page = get_page "/shell"
 page.find "abcd" or error "failed"
 
 
 -- lucene
 
-this_file = Io.schemes.file(Luan.arg[0])
-this_dir = this_file.parent()
-lucene_dir = this_dir.parent().child("build").child("lucene_test")
+local this_file = Io.schemes.file(Luan.arg[0])
+local this_dir = this_file.parent()
+local lucene_dir = this_dir.parent().child("build").child("lucene_test")
 --print(lucene_dir.to_string())
-db = Lucene.index(lucene_dir.to_string())
+local db = Lucene.index(lucene_dir.to_string())
 db.delete_all()
 
-ab_testing = Ab_testing.of(db)
-test_events = {"all"}
-aggregator_factories = {
+local ab_testing = Ab_testing.of(db)
+local test_events = {"all"}
+local aggregator_factories = {
 	all = Ab_testing.count_all;
 }
 ab_testing.test{ name="All", values={"all"}, events=test_events, aggregator_factories=aggregator_factories }
@@ -51,16 +68,16 @@
 	db.save_document(doc)
 end
 
-init_for_test()
+init()
 ab_testing.web_page{"All","null"}.respond()
 
 local Web_search = require "luan:lucene/Web_search"
 local web_search = Web_search.of(db)
 
-init_for_test()
+init()
 web_search.respond()
 
-init_for_test()
+init()
 Http.request.parameter.query = "Query.all_docs"
 Http.request.parameter.rows = "100"
 Http.request.parameter.sort = ""
@@ -73,25 +90,25 @@
 	return Io.uri( "file:../website/src"..path, add_extension )
 end
 
-init_for_test(); Http.get_page "/"
-init_for_test(); Http.get_page "/docs.html"
-init_for_test(); Http.get_page "/tutorial.html"
-init_for_test(); Http.get_page "/pil.html"
-init_for_test(); Http.get_page "/manual.html"
-init_for_test(); Http.get_page "/diff.html"
-init_for_test(); Http.get_page "/examples/hi"
-init_for_test(); Http.get_page "/examples/hi2"
-init_for_test(); Http.get_page "/examples/hi2_simply_html"
-init_for_test(); Http.get_page "/examples/shell"
+init(); get_page "/"
+init(); get_page "/docs.html"
+init(); get_page "/tutorial.html"
+init(); get_page "/pil.html"
+init(); get_page "/manual.html"
+init(); get_page "/diff.html"
+init(); get_page "/examples/hi"
+init(); get_page "/examples/hi2"
+init(); get_page "/examples/hi2_simply_html"
+init(); get_page "/examples/shell"
 
-init_for_test()
+init()
 Http.request.parameter.name = "bob"
-page = Http.get_page "/examples/hi2"
+page = get_page "/examples/hi2"
 page.find "bob" or error "failed"
 
-init_for_test()
+init()
 Http.request.parameter.name = "bob"
-page = Http.get_page "/examples/hi2_simply_html"
+page = get_page "/examples/hi2_simply_html"
 page.find "bob" or error "failed"
 
 
--- a/stripe/src/luan/modules/stripe/Stripe.luan	Tue May 19 17:57:20 2015 -0600
+++ b/stripe/src/luan/modules/stripe/Stripe.luan	Wed May 20 23:24:46 2015 -0600
@@ -7,9 +7,11 @@
 local Customer = require "java:com.stripe.model.Customer"
 local Charge = require "java:com.stripe.model.Charge"
 
-currency = "usd"
+local M = {}
 
-function init(api_key)
+M.currency = "usd"
+
+function M.init(api_key)
 	Stripe.apiKey = api_key
 end
 
@@ -53,22 +55,24 @@
 end
 
 
-function create_customer(params)
+function M.create_customer(params)
 	local java_customer = Customer.create(params)
 	return customer_table(java_customer)
 end
 
-function retrieve_customer(id)
+function M.retrieve_customer(id)
 	local java_customer = Customer.retrieve(id)
 	return customer_table(java_customer)
 end
 
-function create_charge(params)
+function M.create_charge(params)
 	params.amount or error "missing parameter 'amount'"
 	params.amount = assert_integer(params.amount)
-	params.currency = params.currency or currency
+	params.currency = params.currency or M.currency
 	local java_charge = Charge.create(params)
 	return charge_table(java_charge)
 end
 
+return M
+
 -- http://javadox.com/com.stripe/stripe-java/1.2.1/overview-summary.html
--- a/website/src/Shared.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/Shared.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,4 +1,7 @@
+local M = {}
 
-function header() %>
+function M.header() %>
 	<div><small><a href="/">Luan</a></small></div>
 <% end
+
+return M
--- a/website/src/diff.html.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/diff.html.luan	Wed May 20 23:24:46 2015 -0600
@@ -4,9 +4,11 @@
 local Shared = require "site:/Shared"
 local Manual = require "site:/manual.html"
 
-heading_options = Manual.heading_options
+local M = {}
 
-function respond()
+local heading_options = Manual.heading_options
+
+function M.respond()
 	Io.stdout = Http.response.text_writer()
 %>
 <html>
@@ -206,3 +208,5 @@
 </html>
 <%
 end
+
+return M
--- a/website/src/docs.html.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/docs.html.luan	Wed May 20 23:24:46 2015 -0600
@@ -3,8 +3,9 @@
 local Http = require "luan:http/Http"
 local Shared = require "site:/Shared"
 
+local M = {}
 
-function respond()
+function M.respond()
 	Io.stdout = Http.response.text_writer()
 %>
 <html>
@@ -32,3 +33,5 @@
 </html>
 <%
 end
+
+return M
--- a/website/src/examples/hi.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/examples/hi.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,8 +1,9 @@
 local Io = require "luan:Io"
 local Http = require "luan:http/Http"
 
+local M = {}
 
-function respond()
+function M.respond()
 	Io.stdout = Http.response.text_writer()
 	%>
 	<html>
@@ -12,3 +13,5 @@
 	</html>
 	<%
 end
+
+return M
--- a/website/src/examples/hi2.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/examples/hi2.luan	Wed May 20 23:24:46 2015 -0600
@@ -1,6 +1,7 @@
 local Io = require "luan:Io"
 local Http = require "luan:http/Http"
 
+local M = {}
 
 local function form()
 %>
@@ -17,7 +18,7 @@
 <%
 end
 
-local function hello()
+local function hello(name)
 %>
 <html>
 	<body>
@@ -28,12 +29,14 @@
 <%
 end
 
-function respond()
+function M.respond()
 	Io.stdout = Http.response.text_writer()
-	name = Http.request.parameter.name
+	local name = Http.request.parameter.name
 	if name == nil then
 		form()
 	else
-		hello()
+		hello(name)
 	end
 end
+
+return M
--- a/website/src/examples/hi2_simply_html.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/examples/hi2_simply_html.luan	Wed May 20 23:24:46 2015 -0600
@@ -2,6 +2,7 @@
 local Html = require "luan:Html"
 local Http = require "luan:http/Http"
 
+local M = {}
 
 local function form() %>
 			<form>
@@ -12,14 +13,14 @@
 <% end
 
 
-local function hello() %>
+local function hello(name) %>
 			<p>Hi <%= name %>!</p>
 <% end
 
 
-function respond()
+function M.respond()
 	Io.stdout = Http.response.text_writer()
-	name = Http.request.parameter.name
+	local name = Http.request.parameter.name
 %>
 <html>
 	<head>
@@ -32,7 +33,7 @@
 			if name == nil then
 				form()
 			else
-				hello()
+				hello(name)
 			end
 			%>
 			<p margin-top="2em"><small>This page was made with <a href="http://www.simplyhtml.org/">SimplyHTML</a>.</small></p>
@@ -42,3 +43,5 @@
 </html>
 <%
 end
+
+return M
--- a/website/src/index.html.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/index.html.luan	Wed May 20 23:24:46 2015 -0600
@@ -2,8 +2,9 @@
 local Html = require "luan:Html"
 local Http = require "luan:http/Http"
 
+local M = {}
 
-function respond()
+function M.respond()
 	Io.stdout = Http.response.text_writer()
 %>
 <html>
@@ -31,3 +32,5 @@
 </html>
 <%
 end
+
+return M
--- a/website/src/manual.html.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/manual.html.luan	Wed May 20 23:24:46 2015 -0600
@@ -4,9 +4,12 @@
 local Http = require "luan:http/Http"
 local Shared = require "site:/Shared"
 
-heading_options = [[margin-top="2em" margin-bottom=".6em" textcolor="#233E93"]]
-
-function respond()
+local M = {}
+
+local heading_options = [[margin-top="2em" margin-bottom=".6em" textcolor="#233E93"]]
+M.heading_options = heading_options
+
+function M.respond()
 	Io.stdout = Http.response.text_writer()
 %>
 <html>
@@ -5129,3 +5132,5 @@
 </html>
 <%
 end
+
+return M
--- a/website/src/pil.html.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/pil.html.luan	Wed May 20 23:24:46 2015 -0600
@@ -3,8 +3,9 @@
 local Http = require "luan:http/Http"
 local Shared = require "site:/Shared"
 
+local M = {}
 
-function respond()
+function M.respond()
 	Io.stdout = Http.response.text_writer()
 %>
 <html>
@@ -25,3 +26,5 @@
 </html>
 <%
 end
+
+return M
--- a/website/src/tutorial.html.luan	Tue May 19 17:57:20 2015 -0600
+++ b/website/src/tutorial.html.luan	Wed May 20 23:24:46 2015 -0600
@@ -3,8 +3,9 @@
 local Http = require "luan:http/Http"
 local Shared = require "site:/Shared"
 
+local M = {}
 
-function respond()
+function M.respond()
 	Io.stdout = Http.response.text_writer()
 %>
 <html>
@@ -109,3 +110,5 @@
 </html>
 <%
 end
+
+return M