changeset 1580:2975c932864d

require options
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 10 Feb 2021 23:56:59 -0700
parents dd881eb03d87
children dbf63bef4b86
files src/luan/Luan.java src/luan/impl/Compiled.java src/luan/impl/LuanParser.java src/luan/modules/Boot.luan src/luan/modules/PackageLuan.java src/luan/modules/http/LuanHandler.java
diffstat 6 files changed, 18 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
diff -r dd881eb03d87 -r 2975c932864d src/luan/Luan.java
--- a/src/luan/Luan.java	Wed Feb 10 22:49:47 2021 -0700
+++ b/src/luan/Luan.java	Wed Feb 10 23:56:59 2021 -0700
@@ -158,7 +158,11 @@
 	}
 
 	public Object require(String modName) throws LuanException {
-		return PackageLuan.require(this,modName);
+		return require(modName,null);
+	}
+
+	public Object require(String modName,LuanTable options) throws LuanException {
+		return PackageLuan.require(this,modName,options);
 	}
 
 	public String luanToString(Object obj) throws LuanException {
diff -r dd881eb03d87 -r 2975c932864d src/luan/impl/Compiled.java
--- a/src/luan/impl/Compiled.java	Wed Feb 10 22:49:47 2021 -0700
+++ b/src/luan/impl/Compiled.java	Wed Feb 10 23:56:59 2021 -0700
@@ -133,7 +133,7 @@
 	}
 
 
-	private static final int VERSION = 6;
+	private static final int VERSION = 7;
 	private static final File tmpDir;
 	static {
 		File f = new File(System.getProperty("java.io.tmpdir"));
diff -r dd881eb03d87 -r 2975c932864d src/luan/impl/LuanParser.java
--- a/src/luan/impl/LuanParser.java	Wed Feb 10 22:49:47 2021 -0700
+++ b/src/luan/impl/LuanParser.java	Wed Feb 10 23:56:59 2021 -0700
@@ -387,7 +387,7 @@
 		if( exprs == null )
 			return null;
 		Stmts stmt = new Stmts();
-		stmt.add( "Luan.checkFunction(luan.index(PackageLuan.require(luan,\"luan:Io.luan\"),\"template_write\")).call(luan," );
+		stmt.add( "Luan.checkFunction(luan.index(luan.require(\"luan:Io.luan\"),\"template_write\")).call(luan," );
 		stmt.addAll( exprs.array() );
 		stmt.add( ");  " );
 		return stmt;
diff -r dd881eb03d87 -r 2975c932864d src/luan/modules/Boot.luan
--- a/src/luan/modules/Boot.luan	Wed Feb 10 22:49:47 2021 -0700
+++ b/src/luan/modules/Boot.luan	Wed Feb 10 23:56:59 2021 -0700
@@ -244,8 +244,8 @@
 Boot.uri = uri
 
 
-function Boot.read(uri_str)  -- for PackageLuan.java
-	local u = uri(uri_str)
+function Boot.read(uri_str,options)  -- for PackageLuan.java
+	local u = uri(uri_str,options)
 	if u==nil or not u.exists() then
 		return nil
 	end
diff -r dd881eb03d87 -r 2975c932864d src/luan/modules/PackageLuan.java
--- a/src/luan/modules/PackageLuan.java	Wed Feb 10 22:49:47 2021 -0700
+++ b/src/luan/modules/PackageLuan.java	Wed Feb 10 23:56:59 2021 -0700
@@ -21,7 +21,7 @@
 		LuanFunction fn = (LuanFunction)luan.registry().get("Package.require");
 		if( fn == null ) {
 			try {
-				fn = new LuanJavaFunction(PackageLuan.class.getMethod("require",Luan.class,String.class),null);
+				fn = new LuanJavaFunction(PackageLuan.class.getMethod("require",Luan.class,String.class,LuanTable.class),null);
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
 			}
@@ -39,18 +39,18 @@
 		return map;
 	}
 
-	public static Object require(Luan luan,String modName) throws LuanException {
+	public static Object require(Luan luan,String modName,LuanTable options) throws LuanException {
 		if( "java".equals(modName) ) {
 			JavaLuan.java(luan);
 			return true;
 		}
-		Object mod = load(luan,modName);
+		Object mod = load(luan,modName,options);
 		if( mod.equals(Boolean.FALSE) )
 			throw new LuanException( "module '"+modName+"' not found" );
 		return mod;
 	}
 
-	public static Object load(Luan luan,String modName) throws LuanException {
+	public static Object load(Luan luan,String modName,LuanTable options) throws LuanException {
 		Map loaded = loaded(luan);
 		Object mod = loaded.get(modName);
 		if( mod == null ) {
@@ -74,7 +74,7 @@
 				if( mod == null )
 					mod = Boolean.FALSE;
 			} else {
-				String src = read(luan,modName);
+				String src = read(luan,modName,options);
 				if( src == null ) {
 					mod = Boolean.FALSE;
 				} else {
@@ -95,7 +95,7 @@
 		return mod;
 	}
 
-	static String read(Luan luan,String uri) {
+	static String read(Luan luan,String uri,LuanTable options) {
 		LuanTable boot;
 		try {
 			boot = (LuanTable)luan.require("luan:Boot.luan");
@@ -104,7 +104,7 @@
 		}
 		Luan.Security security = Luan.setSecurity(luan,null);
 		try {
-			return (String)Luan.first(boot.fn("read").call(luan,uri));
+			return (String)Luan.first(boot.fn("read").call(luan,uri,options));
 		} catch(LuanException e) {
 			return null;
 		} finally {
diff -r dd881eb03d87 -r 2975c932864d src/luan/modules/http/LuanHandler.java
--- a/src/luan/modules/http/LuanHandler.java	Wed Feb 10 22:49:47 2021 -0700
+++ b/src/luan/modules/http/LuanHandler.java	Wed Feb 10 23:56:59 2021 -0700
@@ -90,7 +90,7 @@
 		}
 		LuanLogger.startThreadLogging(luan);
 		try {
-			PackageLuan.load(luan,"site:/init.luan");
+			PackageLuan.load(luan,"site:/init.luan",null);
 		} catch(LuanException e) {
 			//e.printStackTrace();
 			String err = e.getLuanStackTraceString();
@@ -259,7 +259,7 @@
 		Luan luan;
 		synchronized(currentLuan) {
  			currentLuan.require("luan:http/Http.luan");
-			Object mod = PackageLuan.load(currentLuan,modName);
+			Object mod = PackageLuan.load(currentLuan,modName,null);
 			if( mod.equals(Boolean.FALSE) )
 				return null;
 			if( !(mod instanceof LuanFunction) )