changeset 296:7ea6dfdf81ba

add env param to load_file() git-svn-id: https://luan-java.googlecode.com/svn/trunk@297 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 15 Dec 2014 08:03:32 +0000
parents 1f4cc8505308
children 899253043270
files core/src/luan/Luan.java core/src/luan/modules/BasicLuan.java core/src/luan/modules/IoLuan.java core/src/luan/modules/PackageLuan.java
diffstat 4 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
diff -r 1f4cc8505308 -r 7ea6dfdf81ba core/src/luan/Luan.java
--- a/core/src/luan/Luan.java	Fri Dec 12 09:45:13 2014 +0000
+++ b/core/src/luan/Luan.java	Mon Dec 15 08:03:32 2014 +0000
@@ -8,7 +8,7 @@
 	public static void main(String[] args) {
 		LuanState luan = LuanState.newStandard();
 		try {
-			LuanFunction standalone = (LuanFunction)BasicLuan.load_file(luan,"classpath:luan/cmd_line.luan");
+			LuanFunction standalone = (LuanFunction)BasicLuan.load_file(luan,"classpath:luan/cmd_line.luan",null);
 			luan.call(standalone,args);
 		} catch(LuanException e) {
 			System.err.println(e.getFullMessage());
diff -r 1f4cc8505308 -r 7ea6dfdf81ba core/src/luan/modules/BasicLuan.java
--- a/core/src/luan/modules/BasicLuan.java	Fri Dec 12 09:45:13 2014 +0000
+++ b/core/src/luan/modules/BasicLuan.java	Mon Dec 15 08:03:32 2014 +0000
@@ -37,7 +37,7 @@
 				add( module, "get_metatable", LuanState.class, Object.class );
 				add( module, "ipairs", LuanState.class, LuanTable.class );
 				add( module, "load", LuanState.class, String.class, String.class, LuanTable.class, Boolean.class );
-				add( module, "load_file", LuanState.class, String.class );
+				add( module, "load_file", LuanState.class, String.class, LuanTable.class );
 				add( module, "pairs", LuanState.class, LuanTable.class );
 				add( module, "range", LuanState.class, Double.TYPE, Double.TYPE, Double.class );
 				add( module, "raw_equal", Object.class, Object.class );
@@ -74,17 +74,17 @@
 		return LuanCompiler.compile(luan,new LuanSource(sourceName,text),env,allowExpr);
 	}
 
-	public static LuanFunction load_file(LuanState luan,String fileName) throws LuanException {
+	public static LuanFunction load_file(LuanState luan,String fileName,LuanTable env) throws LuanException {
 		if( fileName == null )
 			fileName = "stdin:";
-		LuanFunction fn = PackageLuan.loader(luan,fileName,false);
+		LuanFunction fn = PackageLuan.loader(luan,fileName,false,env);
 		if( fn == null )
 			throw luan.exception( "file '"+fileName+"' not found" );
 		return fn;
 	}
 
 	public static Object do_file(LuanState luan,String fileName) throws LuanException {
-		LuanFunction fn = load_file(luan,fileName);
+		LuanFunction fn = load_file(luan,fileName,null);
 		return luan.call(fn);
 	}
 
diff -r 1f4cc8505308 -r 7ea6dfdf81ba core/src/luan/modules/IoLuan.java
--- a/core/src/luan/modules/IoLuan.java	Fri Dec 12 09:45:13 2014 +0000
+++ b/core/src/luan/modules/IoLuan.java	Mon Dec 15 08:03:32 2014 +0000
@@ -207,10 +207,10 @@
 			return blocks(inputStream(),n);
 		}
 
-		public LuanFunction loader(LuanState luan,String name) throws LuanException {
+		public LuanFunction loader(LuanState luan,String name,LuanTable env) throws LuanException {
 			try {
 				String src = read_text();
-				return BasicLuan.load(luan,src,name,null,false);
+				return BasicLuan.load(luan,src,name,env,false);
 			} catch(FileNotFoundException e) {
 				return null;
 			} catch(IOException e) {
@@ -246,7 +246,7 @@
 					LuanIn.class.getMethod( "read_blocks", Integer.class ), this
 				) );
 				tbl.put( "loader", new LuanJavaFunction(
-					LuanIn.class.getMethod( "loader", LuanState.class, String.class ), this
+					LuanIn.class.getMethod( "loader", LuanState.class, String.class, LuanTable.class ), this
 				) );
 				tbl.put( "exists", new LuanJavaFunction(
 					LuanIn.class.getMethod( "exists" ), this
diff -r 1f4cc8505308 -r 7ea6dfdf81ba core/src/luan/modules/PackageLuan.java
--- a/core/src/luan/modules/PackageLuan.java	Fri Dec 12 09:45:13 2014 +0000
+++ b/core/src/luan/modules/PackageLuan.java	Mon Dec 15 08:03:32 2014 +0000
@@ -83,18 +83,18 @@
 		return mod;
 	}
 
-	static LuanFunction loader(LuanState luan,String name,boolean loading) throws LuanException {
+	static LuanFunction loader(LuanState luan,String name,boolean loading,LuanTable env) throws LuanException {
 		LuanTable t = IoLuan.Uri(luan,name,loading);
 		if( t == null )
 			return null;
 		LuanFunction loader = (LuanFunction)t.get("loader");
 		if( loader == null )
 			return null;
-		return (LuanFunction)Luan.first(luan.call(loader,new Object[]{name}));
+		return (LuanFunction)Luan.first(luan.call(loader,new Object[]{name,env}));
 	}
 
 	public static Object[] search(LuanState luan,String modName) throws LuanException {
-		LuanFunction fn = loader(luan,modName,true);
+		LuanFunction fn = loader(luan,modName,true,null);
 		return fn==null ? null : new Object[]{fn,modName};
 	}