diff src/luan/modules/http/LuanDomainHandler.java @ 1685:46cf5137cb6b

misc fixes
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 08 Jun 2022 20:13:54 -0600
parents c922446f53aa
children 357daf580951
line wrap: on
line diff
--- 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) {