changeset 1685:46cf5137cb6b

misc fixes
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 08 Jun 2022 20:13:54 -0600
parents cfbecf7af56f
children e34b73678a4f
files src/luan/Luan.java src/luan/LuanException.java src/luan/LuanRuntimeException.java src/luan/cmd_line.luan src/luan/modules/Boot.luan src/luan/modules/Luan.luan src/luan/modules/http/LuanDomainHandler.java src/luan/modules/http/Server.luan src/luan/modules/lucene/Lucene.luan src/luan/modules/lucene/LuceneIndex.java src/luan/modules/lucene/SupplementingConfig.java
diffstat 11 files changed, 58 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/Luan.java
--- a/src/luan/Luan.java	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/Luan.java	Wed Jun 08 20:13:54 2022 -0600
@@ -259,9 +259,12 @@
 
 	// static
 
+	public static String[] args = null;
+
 	public static void main(String[] args) throws LuanException {
 		if( ToolProvider.getSystemJavaCompiler()==null )
 			throw new LuanException("java compiler not available");
+		Luan.args = args;
 		Luan luan = new Luan();
 		LuanFunction fn = loadClasspath(luan,"luan/cmd_line.luan");
 		fn.call(luan,(Object[])args);
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/LuanException.java
--- a/src/luan/LuanException.java	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/LuanException.java	Wed Jun 08 20:13:54 2022 -0600
@@ -115,7 +115,7 @@
 		return sb.toString();
 	}
 
-	private StringBuilder luanStackTrace() {
+	StringBuilder luanStackTrace() {
 		StringBuilder sb = new StringBuilder();
 		sb.append( getMessage() );
 		for( StackTraceElement ste : justLuan(getStackTrace()) ) {
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/LuanRuntimeException.java
--- a/src/luan/LuanRuntimeException.java	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/LuanRuntimeException.java	Wed Jun 08 20:13:54 2022 -0600
@@ -1,8 +1,27 @@
 package luan;
 
+import java.io.PrintWriter;
+import java.io.PrintStream;
+
 
 public final class LuanRuntimeException extends RuntimeException {
 	public LuanRuntimeException(LuanException e) {
 		super(e);
 	}
+
+	@Override public void printStackTrace(PrintStream s) {
+		LuanException luanException = (LuanException)getCause();
+		s.print("Luan: ");
+		s.println(luanException.luanStackTrace());
+		s.print("Caused by: ");
+		super.printStackTrace(s);
+	}
+
+	@Override public void printStackTrace(PrintWriter s) {
+		LuanException luanException = (LuanException)getCause();
+		s.print("Luan: ");
+		s.println(luanException.luanStackTrace());
+		s.print("Caused by: ");
+		super.printStackTrace(s);
+	}
 }
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/cmd_line.luan
--- a/src/luan/cmd_line.luan	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/cmd_line.luan	Wed Jun 08 20:13:54 2022 -0600
@@ -15,10 +15,6 @@
 	Io.debug("> ")
 else
 	local file = args[1]
-	Luan.arg = {}
-	for j,v in ipairs(args) do
-		Luan.arg[j-1] = v
-	end
 	try
 		local main_file = load_file(file) or error("file '"..file.."' not found")
 		local rtn = pack( main_file( unpack(Luan.arg) ) )
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/modules/Boot.luan
--- a/src/luan/modules/Boot.luan	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/modules/Boot.luan	Wed Jun 08 20:13:54 2022 -0600
@@ -44,14 +44,8 @@
 
 local local_metatable = {
 	__index = get_local_cloned
+	__new_index = set_local_cloned
 }
-function local_metatable.__new_index(tbl,key,value)
-	if is_immutable(tbl) then
-		set_local_cloned(tbl,key,value)
-	else
-		raw_set(tbl,key,value)
-	end
-end
 Boot.local_metatable = local_metatable
 
 
@@ -104,7 +98,6 @@
 end
 
 local schemes = {}
-set_metatable(schemes,local_metatable)
 --LuanTable.setSecurity(schemes,"schemes")
 
 function schemes.null(path)
@@ -233,6 +226,7 @@
 	return new_LuanFile( IoLuan.LuanFile.new(path) )
 end
 
+set_metatable(schemes,local_metatable)
 Boot.schemes = schemes
 
 
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/modules/Luan.luan
--- a/src/luan/modules/Luan.luan	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/modules/Luan.luan	Wed Jun 08 20:13:54 2022 -0600
@@ -1,5 +1,7 @@
 require "java"
+local JavaLuan = require "java:luan.Luan"
 local BasicLuan = require "java:luan.modules.BasicLuan"
+local TableLuan = require "java:luan.modules.TableLuan"
 local LuanParser = require "java:luan.modules.parsers.LuanParser"
 local Boot = require "luan:Boot.luan"
 
@@ -47,4 +49,10 @@
 	return load( "return "..s, source_name or "eval", env )()
 end
 
+if JavaLuan.args ~= nil then
+	local args = TableLuan.toTable(JavaLuan.args)
+	args[0] = TableLuan.remove(args,1)
+	Luan.arg = args
+end
+
 return Luan
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/modules/http/LuanDomainHandler.java
--- a/src/luan/modules/http/LuanDomainHandler.java	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/modules/http/LuanDomainHandler.java	Wed Jun 08 20:13:54 2022 -0600
@@ -8,17 +8,18 @@
 import luan.LuanTable;
 import luan.LuanFunction;
 import luan.LuanException;
+import luan.LuanRuntimeException;
 import luan.modules.logging.LuanLogger;
 
 
 public class LuanDomainHandler implements Handler, DomainHandler.Factory {
-
-	private final Luan luanInit;
 	private final DomainHandler domainHandler = new DomainHandler(this);
+	private final LuanFunction init;
 
-	public LuanDomainHandler(Luan luanInit) {
+	public LuanDomainHandler(LuanFunction init) throws LuanException {
+		if(init==null) throw new NullPointerException("init required");
 		LuanLogger.initThreadLogging();
-		this.luanInit = new Luan(luanInit);
+		this.init = init;
 	}
 
 	@Override public Handler newHandler(String domain) {
@@ -27,21 +28,22 @@
 	}
 
 	protected Luan newLuan(final String domain) {
-		Luan luan = new Luan(luanInit);
-		LuanFunction reset_luan = new LuanFunction() {
-			@Override public Object call(Luan luan,Object[] args) {
-				domainHandler.removeHandler(domain);
-				return LuanFunction.NOTHING;
-			}
-		};
 		try {
+			Luan luan = new Luan();
+			init.call(luan);
+			LuanFunction reset_luan = new LuanFunction() {
+				@Override public Object call(Luan luan,Object[] args) {
+					domainHandler.removeHandler(domain);
+					return LuanFunction.NOTHING;
+				}
+			};
 			LuanTable Http = (LuanTable)luan.require("luan:http/Http.luan");
 			Http.put( luan, "domain", domain );
 			Http.put( luan, "reset_luan", reset_luan );
+			return luan;
 		} catch(LuanException e) {
-			throw new RuntimeException(e);
+			throw new LuanRuntimeException(e);
 		}
-		return luan;
 	}
 
 	@Override public Response handle(Request request) {
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/modules/http/Server.luan
--- a/src/luan/modules/http/Server.luan	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/modules/http/Server.luan	Wed Jun 08 20:13:54 2022 -0600
@@ -39,7 +39,9 @@
 	Http.is_serving = true
 	function Io.schemes.site(path)
 		local u = uri( dir..path )
-		u.uri_string = "site:"..path
+		if u ~= nil then
+			u.uri_string = "site:"..path
+		end
 		return u
 	end
 end
@@ -82,17 +84,4 @@
 	return server, luan_handler
 end
 
-function Server.serve_for_proxy(dir,port,LuanHandlerClass)
-	port = port or 8080
-	LuanHandlerClass = LuanHandlerClass or LuanHandler
-	Server.init_dir(dir)
-	local luan_handler = LuanHandlerClass.new()
-	local handler = IndexHandler.new(luan_handler)
-	handler = ContentTypeHandler.new(handler)
-	handler = SafeHandler.new(handler)
-	local server = JavaServer.new(port,handler)
-	Server.start(server)
-	return server, luan_handler
-end
-
 return Server
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/modules/lucene/Lucene.luan
--- a/src/luan/modules/lucene/Lucene.luan	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/modules/lucene/Lucene.luan	Wed Jun 08 20:13:54 2022 -0600
@@ -62,13 +62,14 @@
 Lucene.quote = GoodQueryParser.quote
 Lucene.escape = GoodQueryParser.escape
 
-local function get_file(f,name)
-	type(f)=="table" or error(name.." must be table")
-	f.to_uri_string and matches(f.to_uri_string(),"^file:") or error(name.." must be file")
+local function get_file(f)
+	type(f)=="table" or error "index_dir must be table"
+	f.to_uri_string and matches(f.to_uri_string(),"^file:") or error "index_dir must be file"
 	return f.java.file or error()
 end
 
 function Lucene.index(index_dir,options)
+	options = options or {}
 	local index = {}
 	local options_name = options.name
 	index.dir = index_dir
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/modules/lucene/LuceneIndex.java
--- a/src/luan/modules/lucene/LuceneIndex.java	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/modules/lucene/LuceneIndex.java	Wed Jun 08 20:13:54 2022 -0600
@@ -183,7 +183,7 @@
 			analyzer = sfp.analyzer;
 		}
 		this.analyzer = analyzer;
-		this.config = new SupplementingConfig(luceneVersion,mfp,luan,supplementer);
+		this.config = new SupplementingConfig(luceneVersion,mfp,supplementer);
 		wasCreated = reopen();
 		if( postgresSpec == null ) {
 			postgresBackup = null;
diff -r cfbecf7af56f -r 46cf5137cb6b src/luan/modules/lucene/SupplementingConfig.java
--- a/src/luan/modules/lucene/SupplementingConfig.java	Sun Jun 05 18:03:32 2022 -0600
+++ b/src/luan/modules/lucene/SupplementingConfig.java	Wed Jun 08 20:13:54 2022 -0600
@@ -19,12 +19,11 @@
 
 
 final class SupplementingConfig extends MultiFieldParserConfig {
-	private final Luan luan;
+	private final Luan luan = new Luan();
 	private final LuanFunction supplementer;
 
-	SupplementingConfig(Version luceneVersion,MultiFieldParser mfp,Luan luan,LuanFunction supplementer) throws LuanException {
+	SupplementingConfig(Version luceneVersion,MultiFieldParser mfp,LuanFunction supplementer) throws LuanException {
 		super(luceneVersion,mfp);
-		this.luan = new Luan(luan);
 		LuanMutable.makeImmutable(supplementer);
 		this.supplementer = supplementer;
 	}