Mercurial Hosting > luan
changeset 1353:8d95711f6615
replace java() with require "java"
line wrap: on
line diff
--- a/conv.txt Sun Mar 10 18:25:51 2019 -0600 +++ b/conv.txt Wed Mar 20 17:03:29 2019 -0600 @@ -1,3 +1,5 @@ +java() + luan.webserver indexed_only_field lucene search sort
--- a/src/luan/cmd_line.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/cmd_line.luan Wed Mar 20 17:03:29 2019 -0600 @@ -29,7 +29,7 @@ end end catch = function(e) --- java(); e.java.printStackTrace(); +-- require "java"; e.java.printStackTrace(); Io.print_to(Io.stderr, e ) end }
--- a/src/luan/host/Util.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/host/Util.luan Wed Mar 20 17:03:29 2019 -0600 @@ -11,7 +11,7 @@ local bytes = Binary.byte or error() local Hosting = require "luan:host/Hosting.luan" -java() +require "java" local Base64 = require "java:java.util.Base64" local MessageDigest = require "java:java.security.MessageDigest"
--- a/src/luan/host/init.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/host/init.luan Wed Mar 20 17:03:29 2019 -0600 @@ -11,7 +11,7 @@ -- logging if logging then - java() + require "java" local Log4j = require "java:luan.modules.logging.Log4j" local Level = require "java:org.apache.log4j.Level" local EnhancedPatternLayout = require "java:org.apache.log4j.EnhancedPatternLayout" @@ -71,7 +71,7 @@ -java() +require "java" local WebHandler = require "java:luan.host.WebHandler" local LuanJava = require "java:luan.Luan"
--- a/src/luan/host/main.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/host/main.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local Luan = require "luan:Luan.luan" local error = Luan.error local type = Luan.type or error()
--- a/src/luan/host/run.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/host/run.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local Luan = require "luan:Luan.luan" local error = Luan.error local do_file = Luan.do_file or error()
--- a/src/luan/impl/LuanCompiler.java Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/impl/LuanCompiler.java Wed Mar 20 17:03:29 2019 -0600 @@ -33,10 +33,9 @@ } catch(InvocationTargetException e) { throw new RuntimeException(e); } - closure.upValues[0].o = JavaLuan.javaFn(luan); - closure.upValues[1].o = PackageLuan.requireFn(luan); + closure.upValues[0].o = PackageLuan.requireFn(luan); if( env != null ) { - closure.upValues[2].o = env; + closure.upValues[1].o = env; env.closure = closure; } return closure; @@ -57,7 +56,6 @@ private static Class getClass(String sourceText,String sourceName,LuanTable env) throws LuanException { LuanParser parser = new LuanParser(sourceText,sourceName); - parser.addVar( "java" ); parser.addVar( "require" ); if( env != null ) parser.addVar( "_ENV" ); try { @@ -70,7 +68,6 @@ public static String toJava(String sourceText,String sourceName) throws LuanException { LuanParser parser = new LuanParser(sourceText,sourceName); - parser.addVar( "java" ); parser.addVar( "require" ); try { return parser.RequiredModuleSource();
--- a/src/luan/modules/Binary.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Binary.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local BinaryLuan = require "java:luan.modules.BinaryLuan"
--- a/src/luan/modules/Boot.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Boot.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local System = require "java:java.lang.System" local URL = require "java:java.net.URL" local BasicLuan = require "java:luan.modules.BasicLuan"
--- a/src/luan/modules/Html.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Html.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local HtmlLuan = require "java:luan.modules.HtmlLuan" local HtmlParser = require "java:luan.modules.parsers.Html" local URLEncoder = require "java:java.net.URLEncoder"
--- a/src/luan/modules/Io.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Io.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local IoLuan = require "java:luan.modules.IoLuan" local System = require "java:java.lang.System" local Boot = require "luan:Boot.luan"
--- a/src/luan/modules/JavaLuan.java Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/JavaLuan.java Wed Mar 20 17:03:29 2019 -0600 @@ -32,19 +32,6 @@ luan.peek().javaOk = true; } - public static LuanFunction javaFn(Luan luan) { - LuanFunction fn = (LuanFunction)luan.registry().get("JavaLuan.java"); - if( fn == null ) { - try { - fn = new LuanJavaFunction(luan,JavaLuan.class.getMethod("java",Luan.class),null); - } catch(NoSuchMethodException e) { - throw new RuntimeException(e); - } - luan.registry().put("JavaLuan.java",fn); - } - return fn; - } - private static void checkJava(Luan luan) throws LuanException { if( !luan.peek().javaOk ) throw new LuanException("Java isn't allowed");
--- a/src/luan/modules/Luan.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Luan.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local BasicLuan = require "java:luan.modules.BasicLuan" local Boot = require "luan:Boot.luan"
--- a/src/luan/modules/Math.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Math.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local MathLuan = require "java:luan.modules.MathLuan" local JavaMath = require "java:java.lang.Math" local Integer = require "java:java.lang.Integer"
--- a/src/luan/modules/Number.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Number.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local BasicLuan = require "java:luan.modules.BasicLuan" local MathLuan = require "java:luan.modules.MathLuan"
--- a/src/luan/modules/Package.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Package.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local PackageLuan = require "java:luan.modules.PackageLuan" local Package = {}
--- a/src/luan/modules/PackageLuan.java Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/PackageLuan.java Wed Mar 20 17:03:29 2019 -0600 @@ -38,6 +38,10 @@ } public static Object require(Luan luan,String modName) throws LuanException { + if( "java".equals(modName) ) { + JavaLuan.java(luan); + return true; + } Object mod = load(luan,modName); if( mod.equals(Boolean.FALSE) ) throw new LuanException( "module '"+modName+"' not found" );
--- a/src/luan/modules/Parsers.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Parsers.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local BBCode = require "java:luan.modules.parsers.BBCode" local Csv = require "java:luan.modules.parsers.Csv" local Theme = require "java:luan.modules.parsers.Theme"
--- a/src/luan/modules/Rpc.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Rpc.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local Socket = require "java:java.net.Socket" local ServerSocket = require "java:java.net.ServerSocket" local SSLSocketFactory = require "java:javax.net.ssl.SSLSocketFactory"
--- a/src/luan/modules/String.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/String.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local StringLuan = require "java:luan.modules.StringLuan" local Pattern = require "java:java.util.regex.Pattern"
--- a/src/luan/modules/Table.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Table.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local TableLuan = require "java:luan.modules.TableLuan" local Table = {}
--- a/src/luan/modules/Thread.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Thread.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local ThreadLuan = require "java:luan.modules.ThreadLuan" local Luan = require "luan:Luan.luan" local error = Luan.error
--- a/src/luan/modules/Time.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/Time.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,6 +1,6 @@ -- incomplete, will add as needed -java() +require "java" local Luan = require "luan:Luan.luan" local error = Luan.error local ipairs = Luan.ipairs or error()
--- a/src/luan/modules/http/Http.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/http/Http.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local Luan = require "luan:Luan.luan" local error = Luan.error local ipairs = Luan.ipairs or error()
--- a/src/luan/modules/http/Server.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/http/Server.luan Wed Mar 20 17:03:29 2019 -0600 @@ -14,7 +14,7 @@ local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "http/Server" -java() +require "java" local JavaServer = require "java:luan.lib.webserver.Server" local FileHandler = require "java:luan.lib.webserver.handlers.FileHandler" local DirHandler = require "java:luan.lib.webserver.handlers.DirHandler"
--- a/src/luan/modules/http/tools/Java_threads.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/http/tools/Java_threads.luan Wed Mar 20 17:03:29 2019 -0600 @@ -3,7 +3,7 @@ local Io = require "luan:Io.luan" local Time = require "luan:Time.luan" local Http = require "luan:http/Http.luan" -java() +require "java" local Thread = require "java:java.lang.Thread"
--- a/src/luan/modules/http/tools/Luan_threads.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/http/tools/Luan_threads.luan Wed Mar 20 17:03:29 2019 -0600 @@ -5,7 +5,7 @@ local Io = require "luan:Io.luan" local Time = require "luan:Time.luan" local Http = require "luan:http/Http.luan" -java() +require "java" local Thread = require "java:java.lang.Thread" local LuanException = require "java:luan.LuanException"
--- a/src/luan/modules/logging/Log4j.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/logging/Log4j.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,6 +1,6 @@ local Luan = require "luan:Luan.luan" local error = Luan.error -java() +require "java" local JavaLog4j = require "java:luan.modules.logging.Log4j" local EnhancedPatternLayout = require "java:org.apache.log4j.EnhancedPatternLayout" local ConsoleAppender = require "java:org.apache.log4j.ConsoleAppender"
--- a/src/luan/modules/logging/Logging.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/logging/Logging.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local LuanLogger = require "java:luan.modules.logging.LuanLogger" local Package = require "luan:Package.luan"
--- a/src/luan/modules/luan_to_java.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/luan_to_java.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local LuanCompiler = require "java:luan.impl.LuanCompiler" local Io = require "luan:Io.luan"
--- a/src/luan/modules/lucene/Lucene.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/lucene/Lucene.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local Luan = require "luan:Luan.luan" local error = Luan.error local ipairs = Luan.ipairs or error()
--- a/src/luan/modules/mail/Mail.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/mail/Mail.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local Luan = require "luan:Luan.luan" local error = Luan.error local type = Luan.type or error()
--- a/src/luan/modules/sql/Sql.luan Sun Mar 10 18:25:51 2019 -0600 +++ b/src/luan/modules/sql/Sql.luan Wed Mar 20 17:03:29 2019 -0600 @@ -1,4 +1,4 @@ -java() +require "java" local Luan = require "luan:Luan.luan" local error = Luan.error local new_error = Luan.new_error or error()
--- a/website/src/manual.html Sun Mar 10 18:25:51 2019 -0600 +++ b/website/src/manual.html Wed Mar 20 17:03:29 2019 -0600 @@ -229,7 +229,7 @@ <h3 heading><a name="env" href="#env">Environments</a></h3> <p> -The environment of a chunk starts with only two local variables: <code><a href="#require">require</a></code> and <code><a href="#java">java</a></code>. These are functions are used to load and access libraries and other modules. All other variables must be added to the environment using <a href="http://localhost:8080/manual.html#local_stmt">local declarations</a>. +The environment of a chunk starts with only one local variable: <code><a href="#require">require</a></code>. This function is used to load and access libraries and other modules. All other variables must be added to the environment using <a href="http://localhost:8080/manual.html#local_stmt">local declarations</a>. <p> As will be discussed in <a href="#vars">Variables</a> and <a href=#assignment">Assignment</a>, @@ -1761,13 +1761,7 @@ <h3 heading><a name="default_lib" href="#default_lib">Default Environment</a></h3> <p> -These are provided by default as local variables for any Luan code as described in <a href="#env">Environments</a>. - - -<h4 heading><a name="java" href="#java"><code>java ()</code></a></h4> - -<p> -This function enables Java in the current chunk if that chunk has permission to use Java. If the chunk doesn't have permission to use Java, then an error is thrown. +This is provided by default as a local variable for any Luan code as described in <a href="#env">Environments</a>. <h4 heading><a name="require" href="#require"><code>require (mod_uri)</code></a></h4> @@ -1788,6 +1782,16 @@ end </pre> +<p> +A special case is: + +<pre> + require "java" +</pre> + +<p> +This enables Java in the current chunk if that chunk has permission to use Java. If the chunk doesn't have permission to use Java, then an error is thrown. + <h3 heading><a name="luan_lib" href="#luan_lib">Basic Functions</a></h3>