Mercurial Hosting > luan
diff core/src/luan/impl/LuanCompiler.java @ 672:d3e5414bdf4c
better java permission handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 12 Apr 2016 17:03:30 -0600 |
parents | 58ebfec6178b |
children | d95caff8ba8c |
line wrap: on
line diff
--- a/core/src/luan/impl/LuanCompiler.java Tue Apr 12 14:44:10 2016 -0600 +++ b/core/src/luan/impl/LuanCompiler.java Tue Apr 12 17:03:30 2016 -0600 @@ -6,6 +6,7 @@ import luan.LuanState; import luan.LuanException; import luan.LuanTable; +import luan.LuanJava; import luan.modules.JavaLuan; import luan.modules.PackageLuan; @@ -15,14 +16,23 @@ public static LuanFunction compile(LuanState luan,String sourceName,String sourceText,LuanTable env,boolean allowExpr) throws LuanException { LuanParser parser = new LuanParser(sourceName,sourceText); - parser.addVar( env!=null ? "_ENV" : null ); parser.addVar( "java" ); parser.addVar( "require" ); + if( env != null ) parser.addVar( "_ENV" ); Class fnClass = parse(parser,allowExpr); - final LuanStateImpl luanImpl = (LuanStateImpl)luan; + LuanJava java; + if( env == null ) { + java = new LuanJava(); + } else { + java = env.java; + if( java == null ) { + java = new LuanJava(); + env.java = java; + } + } Closure closure; try { - closure = (Closure)fnClass.getConstructor(LuanState.class).newInstance(luanImpl); + closure = (Closure)fnClass.getConstructor(LuanState.class,LuanJava.class).newInstance(luan,java); } catch(NoSuchMethodException e) { throw new RuntimeException(e); } catch(InstantiationException e) { @@ -32,9 +42,9 @@ } catch(InvocationTargetException e) { throw new RuntimeException(e); } - closure.upValues[0].o = env!=null ? env : new LuanTable(); - closure.upValues[1].o = JavaLuan.javaFn; - closure.upValues[2].o = PackageLuan.requireFn; + closure.upValues[0].o = JavaLuan.javaFn; + closure.upValues[1].o = PackageLuan.requireFn; + if( env != null ) closure.upValues[2].o = env; return closure; } @@ -51,8 +61,4 @@ throw new LuanException( e.getFancyMessage() ); } } - - public static LuanState newLuanState() { - return new LuanStateImpl(); - } }