Mercurial Hosting > luan
changeset 321:7f7708e8fdd4
remove import statement
git-svn-id: https://luan-java.googlecode.com/svn/trunk@322 21e917c8-12df-6dd8-5cb6-c86387c605b9
line wrap: on
line diff
--- a/core/src/luan/cmd_line.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/cmd_line.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,12 +1,11 @@ -import "luan:Luan" -import "luan:String" -import "luan:Table" -import "luan:Io" -import "luan:Debug" - +local Luan = require "luan:Luan" local ipairs = Luan.ipairs local load = Luan.load local load_file = Luan.load_file +require "luan:String" -- for String methods +local Table = require "luan:Table" +local Io = require "luan:Io" +local Debug = require "luan:Debug" local standalone_usage = [=[
--- a/core/src/luan/impl/JavaStmt.java Fri Feb 06 21:54:41 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package luan.impl; - -import luan.LuanException; -import luan.modules.JavaLuan; - - -final class JavaStmt implements Stmt { - - @Override public void eval(LuanStateImpl luan) throws LuanException { - JavaLuan.java(luan); - } -}
--- a/core/src/luan/impl/LuanCompiler.java Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/impl/LuanCompiler.java Sun Feb 08 07:26:20 2015 +0000 @@ -7,6 +7,8 @@ import luan.LuanElement; import luan.LuanTable; import luan.Luan; +import luan.modules.JavaLuan; +import luan.modules.PackageLuan; import java.util.Map; @@ -19,6 +21,8 @@ env = Luan.newTable(); UpValue.Getter envGetter = new UpValue.ValueGetter(env); LuanParser parser = new LuanParser(src,envGetter); + parser.addVar( "java", JavaLuan.javaFn ); + parser.addVar( "require", PackageLuan.requireFn ); FnDef fnDef = parse(luan,parser,allowExpr); final LuanStateImpl luanImpl = (LuanStateImpl)luan; final Closure c = new Closure(luanImpl,fnDef);
--- a/core/src/luan/impl/LuanParser.java Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/impl/LuanParser.java Sun Feb 08 07:26:20 2015 +0000 @@ -249,8 +249,6 @@ if( (stmt=ReturnStmt()) != null || (stmt=FunctionStmt()) != null || (stmt=LocalFunctionStmt()) != null - || (stmt=ImportStmt()) != null - || (stmt=JavaStmt()) != null || (stmt=BreakStmt()) != null || (stmt=ForStmt()) != null || (stmt=TryStmt()) != null @@ -348,53 +346,6 @@ return parser.success( new SetStmt( new SetLocalVar(symbolsSize()-1), fnDef ) ); } - private Stmt ImportStmt() throws ParseException { - int start = parser.begin(); - if( !Keyword("import",In.NOTHING) ) - return parser.failure(null); - String modName = StringLiteral(In.NOTHING); - if( modName==null ) - return parser.failure(null); - int i = modName.lastIndexOf('/'); - if( i == -1 ) - i = modName.lastIndexOf('.'); - if( i == -1 ) - i = modName.lastIndexOf(':'); - String varName = modName.substring(i+1); - if( !isValidName(varName) ) - throw parser.exception("invalid variable name '"+varName+"' in import"); - LuanSource.Element se = se(start); - FnCall require = new FnCall( se, new ConstExpr(se,PackageLuan.requireFn), new ConstExpr(se(start,modName),modName) ); - Settable settable; - if( interactive ) { - settable = nameVar(se,varName).settable(); - } else { - addSymbol( varName ); - settable = new SetLocalVar(symbolsSize()-1); - } - return parser.success( new SetStmt( settable, expr(require) ) ); - } - - private boolean isValidName(String s) { - if( s.length() == 0 ) - return false; - char c = s.charAt(0); - if( !('a'<=c && c<='z' || 'A'<=c && c<='Z' || c=='_') ) - return false; - for( int i=1; i<s.length() ; i++ ) { - if( !('a'<=c && c<='z' || 'A'<=c && c<='Z' || c=='_' || '0'<=c && c<='9') ) - return false; - } - return true; - } - - private Stmt JavaStmt() throws ParseException { - parser.begin(); - if( !Keyword("java",In.NOTHING) ) - return parser.failure(null); - return parser.success( new JavaStmt() ); - } - private Stmt BreakStmt() throws ParseException { parser.begin(); if( !Keyword("break",In.NOTHING) ) @@ -1154,9 +1105,7 @@ "function", "goto", "if", - "import", "in", - "java", "local", "nil", "not",
--- a/core/src/luan/modules/Binary.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Binary.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,5 +1,5 @@ -java -import "java:luan.modules.BinaryLuan" +java() +local BinaryLuan = require "java:luan.modules.BinaryLuan" byte = BinaryLuan.byte_ binary = BinaryLuan.binary
--- a/core/src/luan/modules/Debug.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Debug.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,5 +1,6 @@ -import "luan:Table" -import "luan:Io" +local Table = require "luan:Table" +local Io = require "luan:Io" +local print = Io.print function print_if_something(...)
--- a/core/src/luan/modules/Hosting.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Hosting.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,6 +1,6 @@ -- Hosting -import "luan:Io" +local Io = require "luan:Io" port = 9101 @@ -9,7 +9,7 @@ local pc = Io.Uri(socket).Pickle_client() local pickle = pc.pickle pc.call(%> - import "luan:Hosting" + local Hosting = require "luan:Hosting" Hosting.do_put_site(<%=pickle(domain)%>,<%=pickle(password)%>,<%=pickle(dir)%>) <%) pc.close() @@ -20,7 +20,7 @@ local pc = Io.Uri(socket).Pickle_client() local pickle = pc.pickle pc.call(%> - import "luan:Hosting" + local Hosting = require "luan:Hosting" Hosting.do_delete_site(<%=pickle(domain)%>,<%=pickle(password)%>) <%) pc.close()
--- a/core/src/luan/modules/Html.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Html.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,5 +1,5 @@ -java -import "java:luan.modules.HtmlLuan" +java() +local HtmlLuan = require "java:luan.modules.HtmlLuan" encode = HtmlLuan.encode parse = HtmlLuan.parse @@ -9,8 +9,7 @@ -- extras -import "luan:Luan" - +local Luan = require "luan:Luan" local ipairs = Luan.ipairs local type = Luan.type
--- a/core/src/luan/modules/Io.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Io.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,6 +1,6 @@ -java -import "java:luan.modules.IoLuan" -import "java:java.lang.System" +java() +local IoLuan = require "java:luan.modules.IoLuan" +local System = require "java:java.lang.System" read_console_line = IoLuan.read_console_line schemes = IoLuan.newSchemes() @@ -11,10 +11,9 @@ stderr = IoLuan.textWriter(System.err) -import "luan:Luan" -import "luan:Table" - +local Luan = require "luan:Luan" local to_string = Luan.to_string +local Table = require "luan:Table" function print_to(out,...) local list = {}
--- a/core/src/luan/modules/JavaLuan.java Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/JavaLuan.java Sun Feb 08 07:26:20 2015 +0000 @@ -32,6 +32,15 @@ luan.currentEnvironment().setJava(); } + public static final LuanFunction javaFn; + static { + try { + javaFn = new LuanJavaFunction(JavaLuan.class.getMethod("java",LuanState.class),null); + } catch(NoSuchMethodException e) { + throw new RuntimeException(e); + } + } + private static void checkJava(LuanState luan) throws LuanException { if( !luan.currentEnvironment().hasJava() ) throw luan.exception("Java isn't allowed");
--- a/core/src/luan/modules/Luan.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Luan.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,5 +1,5 @@ -java -import "java:luan.modules.BasicLuan" +java() +local BasicLuan = require "java:luan.modules.BasicLuan" assert = BasicLuan.assert_ assert_boolean = BasicLuan.assert_boolean @@ -29,5 +29,4 @@ type = BasicLuan.type values = BasicLuan.values -import "classpath:luan/Version" -VERSION = Version.VERSION +VERSION = require("classpath:luan/Version").VERSION
--- a/core/src/luan/modules/Math.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Math.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,8 +1,5 @@ -java -import "luan:Package" -import "java:luan.modules.MathLuan" - -local require = Package.require +java() +local MathLuan = require "java:luan.modules.MathLuan" local JavaMath = require "java:java.lang.Math" abs = MathLuan.abs
--- a/core/src/luan/modules/Package.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Package.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,6 +1,5 @@ -java -import "java:luan.modules.PackageLuan" +java() +local PackageLuan = require "java:luan.modules.PackageLuan" loaded = PackageLuan.loaded() -require = PackageLuan.requireFn load = PackageLuan.load
--- a/core/src/luan/modules/String.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/String.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,5 +1,5 @@ -java -import "java:luan.modules.StringLuan" +java() +local StringLuan = require "java:luan.modules.StringLuan" unicode = StringLuan.unicode char = StringLuan.char_
--- a/core/src/luan/modules/Table.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Table.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,5 +1,5 @@ -java -import "java:luan.modules.TableLuan" +java() +local TableLuan = require "java:luan.modules.TableLuan" clone = TableLuan.clone concat = TableLuan.concat
--- a/core/src/luan/modules/Thread.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Thread.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,4 +1,4 @@ -java -import "java:luan.modules.ThreadLuan" +java() +local ThreadLuan = require "java:luan.modules.ThreadLuan" fork = ThreadLuan.fork
--- a/core/src/luan/modules/Time.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/core/src/luan/modules/Time.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,13 +1,13 @@ -- incomplete, will add as needed -java -import "luan:String" -import "luan:Table" -import "java:java.lang.System" -import "java:java.util.Calendar" -import "java:java.util.Date" -import "java:java.util.TimeZone" -import "java:java.text.SimpleDateFormat" +java() +require "luan:String" +local Table = require "luan:Table" +local System = require "java:java.lang.System" +local Calendar = require "java:java.util.Calendar" +local Date = require "java:java.util.Date" +local TimeZone = require "java:java.util.TimeZone" +local SimpleDateFormat = require "java:java.text.SimpleDateFormat" function now()
--- a/logging/src/luan/modules/logging/Logging.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/logging/src/luan/modules/logging/Logging.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,10 +1,10 @@ -java -import "java:org.apache.log4j.Logger" -import "java:org.apache.log4j.EnhancedPatternLayout" -import "java:org.apache.log4j.ConsoleAppender" -import "java:org.apache.log4j.Level" -import "java:org.apache.log4j.RollingFileAppender" -import "java:luan.modules.logging.LuanLogger" +java() +local Logger = require "java:org.apache.log4j.Logger" +local EnhancedPatternLayout = require "java:org.apache.log4j.EnhancedPatternLayout" +local ConsoleAppender = require "java:org.apache.log4j.ConsoleAppender" +local Level = require "java:org.apache.log4j.Level" +local RollingFileAppender = require "java:org.apache.log4j.RollingFileAppender" +local LuanLogger = require "java:luan.modules.logging.LuanLogger" layout = "%d %-5p %c - %m%n"
--- a/lucene/src/luan/modules/lucene/Ab_testing.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/lucene/src/luan/modules/lucene/Ab_testing.luan Sun Feb 08 07:26:20 2015 +0000 @@ -258,4 +258,4 @@ %> </body> </html> -<% end \ No newline at end of file +<% end
--- a/lucene/src/luan/modules/lucene/Lucene.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/lucene/src/luan/modules/lucene/Lucene.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,16 +1,15 @@ -java -import "luan:Luan" -import "luan:Table" -import "java:luan.modules.lucene.LuceneIndex" -import "java:org.apache.lucene.index.Term" -import "java:org.apache.lucene.search.TermQuery" -import "java:org.apache.lucene.search.MatchAllDocsQuery" -import "java:org.apache.lucene.search.BooleanQuery" -import "java:org.apache.lucene.search.BooleanClause" -import "java:org.apache.lucene.search.Sort" -import "java:org.apache.lucene.search.SortField" - +java() +local Luan = require "luan:Luan" local pairs = Luan.pairs +local Table = require "luan:Table" +local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex" +local Term = require "java:org.apache.lucene.index.Term" +local TermQuery = require "java:org.apache.lucene.search.TermQuery" +local MatchAllDocsQuery = require "java:org.apache.lucene.search.MatchAllDocsQuery" +local BooleanQuery = require "java:org.apache.lucene.search.BooleanQuery" +local BooleanClause = require "java:org.apache.lucene.search.BooleanClause" +local Sort = require "java:org.apache.lucene.search.Sort" +local SortField = require "java:org.apache.lucene.search.SortField" function Index(indexDir)
--- a/lucene/src/luan/modules/lucene/Web_search.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/lucene/src/luan/modules/lucene/Web_search.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,6 +1,12 @@ -import "luan:Io" -import "luan:web/Http" -import "luan:String" +local Luan = require "luan:Luan" +local load = Luan.load +local to_number = Luan.to_number +local pairs = Luan.pairs +local ipairs = Luan.ipairs +local range = Luan.range +local Io = require "luan:Io" +local Http = require "luan:web/Http" +local String = require "luan:String" local function basic_style() %>
--- a/mail/src/luan/modules/mail/Mail.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/mail/src/luan/modules/mail/Mail.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,9 +1,8 @@ -java -import "luan:Luan" -import "java:java.lang.System" -import "java:luan.modules.mail.SmtpCon" - +java() +local Luan = require "luan:Luan" local assert_table = Luan.assert_table +local System = require "java:java.lang.System" +local SmtpCon = require "java:luan.modules.mail.SmtpCon" System.setProperty( "mail.mime.charset", "UTF-8" )
--- a/scripts/mmake.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/scripts/mmake.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,11 +1,10 @@ -import "luan:Luan" -import "luan:Table" -import "luan:Io" -import "luan:String" -import "luan:Time" - +local Luan = require "luan:Luan" local ipairs = Luan.ipairs +local Table = require "luan:Table" +local Io = require "luan:Io" local print = Io.print +local String = require "luan:String" +local Time = require "luan:Time" compiler = Table.concat( { "javac -g -encoding UTF8", ... }, " " )
--- a/scripts/test.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/scripts/test.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,1 +1,3 @@ +local do_file = require("luan:Luan").do_file + do_file "luan:web/test.luan"
--- a/web/src/luan/modules/web/Http.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/web/src/luan/modules/web/Http.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,12 +1,9 @@ -java -import "luan:Package" -import "luan:Luan" -import "luan:Table" -import "java:luan.modules.web.LuanHandler" - -local require = Package.require +java() +local Luan = require "luan:Luan" local ipairs = Luan.ipairs local to_string = Luan.to_string +local Table = require "luan:Table" +local LuanHandler = require "java:luan.modules.web.LuanHandler" function new_luan_handler()
--- a/web/src/luan/modules/web/Web_server.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/web/src/luan/modules/web/Web_server.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,22 +1,22 @@ -import "luan:String" -import "luan:Io" -import "luan:Package" -import "luan:logging/Logging" -- initialize logging -import "luan:web/Http" +require "luan:String" +local Io = require "luan:Io" +local Package = require "luan:Package" +require "luan:logging/Logging" -- initialize logging +local Http = require "luan:web/Http" -java -import "java:org.eclipse.jetty.server.Server" -import "java:org.eclipse.jetty.server.NCSARequestLog" -import "java:org.eclipse.jetty.server.handler.DefaultHandler" -import "java:org.eclipse.jetty.server.handler.HandlerList" -import "java:org.eclipse.jetty.server.handler.HandlerCollection" -import "java:org.eclipse.jetty.server.handler.ResourceHandler" -import "java:org.eclipse.jetty.server.handler.RequestLogHandler" -import "java:org.eclipse.jetty.server.handler.ContextHandler" -import "java:org.eclipse.jetty.server.handler.GzipHandler" -import "java:org.eclipse.jetty.server.handler.HandlerWrapper" -import "java:org.eclipse.jetty.server.session.SessionHandler" -import "java:luan.modules.web.AuthenticationHandler" +java() +local Server = require "java:org.eclipse.jetty.server.Server" +local NCSARequestLog = require "java:org.eclipse.jetty.server.NCSARequestLog" +local DefaultHandler = require "java:org.eclipse.jetty.server.handler.DefaultHandler" +local HandlerList = require "java:org.eclipse.jetty.server.handler.HandlerList" +local HandlerCollection = require "java:org.eclipse.jetty.server.handler.HandlerCollection" +local ResourceHandler = require "java:org.eclipse.jetty.server.handler.ResourceHandler" +local RequestLogHandler = require "java:org.eclipse.jetty.server.handler.RequestLogHandler" +local ContextHandler = require "java:org.eclipse.jetty.server.handler.ContextHandler" +local GzipHandler = require "java:org.eclipse.jetty.server.handler.GzipHandler" +local HandlerWrapper = require "java:org.eclipse.jetty.server.handler.HandlerWrapper" +local SessionHandler = require "java:org.eclipse.jetty.server.session.SessionHandler" +local AuthenticationHandler = require "java:luan.modules.web.AuthenticationHandler" port = 8080
--- a/web/src/luan/modules/web/test.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/web/src/luan/modules/web/test.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,5 +1,7 @@ -import "luan:Io" -import "luan:web/Http" +local Luan = require "luan:Luan" +local assert = Luan.assert +local Io = require "luan:Io" +local Http = require "luan:web/Http" local function print(...) @@ -12,7 +14,7 @@ Http.init_for_test() -Http.request.parameters.code = "print 'hi'" +Http.request.parameters.code = "require('luan:Io').print 'hi'" page = Http.get_page "/web_run" assert( page.trim() == "hi" )
--- a/web/src/luan/modules/web/web_run.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/web/src/luan/modules/web/web_run.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,6 +1,9 @@ -import "luan:Io" -import "luan:web/Http" -import "luan:String" +local Luan = require "luan:Luan" +local load = Luan.load +local Io = require "luan:Io" +local print = Io.print +local Http = require "luan:web/Http" +local String = require "luan:String" local function lines(s) local matcher = s.gmatch "([^\n]*)\n|([^\n])+$"
--- a/web/src/luan/modules/web/web_shell.luan Fri Feb 06 21:54:41 2015 +0000 +++ b/web/src/luan/modules/web/web_shell.luan Sun Feb 08 07:26:20 2015 +0000 @@ -1,7 +1,10 @@ -import "luan:Basic" -import "luan:Io" -import "luan:Debug" -import "luan:web/Http" +local Luan = require "luan:Luan" +local ipairs = Luan.ipairs +local load = Luan.load +local Io = require "luan:Io" +local print = Io.print +local Debug = require "luan:Debug" +local Http = require "luan:web/Http" per_session = true @@ -10,7 +13,7 @@ Io.stdout = {} function Io.stdout.write(...) - for _,v in Basic.values(...) do + for _,v in Luan.values(...) do history[#history+1] = v end end