comparison src/luan/interp/LuanCompiler.java @ 149:f99fd64291b3

change load() to take env instead of using global git-svn-id: https://luan-java.googlecode.com/svn/trunk@150 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 16 Jun 2014 05:47:54 +0000
parents f0a4abe58593
children f35c50027985
comparison
equal deleted inserted replaced
148:dfd0f33b584e 149:f99fd64291b3
11 11
12 12
13 public final class LuanCompiler { 13 public final class LuanCompiler {
14 private LuanCompiler() {} // never 14 private LuanCompiler() {} // never
15 15
16 public static LuanFunction compileModule(LuanState luan,LuanSource src,boolean allowExpr) throws LuanException { 16 private static LuanFunction compile(LuanState luan,LuanSource src,boolean allowExpr) throws LuanException {
17 UpValue.Getter envGetter = new UpValue.EnvGetter(); 17 UpValue.Getter envGetter = new UpValue.EnvGetter();
18 LuanParser parser = new LuanParser(src,envGetter); 18 LuanParser parser = new LuanParser(src,envGetter);
19 for( Map.Entry<Object,Object> entry : luan.global() ) { 19 for( Map.Entry<Object,Object> entry : luan.global() ) {
20 Object key = entry.getKey(); 20 Object key = entry.getKey();
21 if( key instanceof String ) 21 if( key instanceof String )
31 return rtn; 31 return rtn;
32 } 32 }
33 }; 33 };
34 } 34 }
35 35
36 public static LuanFunction compileGlobal(LuanState luan,LuanSource src,boolean allowExpr) throws LuanException { 36 public static LuanFunction compile(LuanState luan,LuanSource src,LuanTable env,boolean allowExpr) throws LuanException {
37 UpValue.Getter envGetter = UpValue.globalGetter; 37 if( env==null )
38 return compile(luan,src,allowExpr);
39 UpValue.Getter envGetter = new UpValue.ValueGetter(env);
38 LuanParser parser = new LuanParser(src,envGetter); 40 LuanParser parser = new LuanParser(src,envGetter);
39 FnDef fnDef = parse(luan,parser,allowExpr); 41 FnDef fnDef = parse(luan,parser,allowExpr);
40 return new Closure((LuanStateImpl)luan,fnDef); 42 return new Closure((LuanStateImpl)luan,fnDef);
41 } 43 }
42 44