Mercurial Hosting > luan
changeset 179:bf9c7111a371
minor
git-svn-id: https://luan-java.googlecode.com/svn/trunk@180 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 24 Jun 2014 00:05:53 +0000 |
parents | 2c08e7e27a70 |
children | 5351374efb6d |
files | core/src/luan/impl/LuanParser.java core/src/luan/init.luan |
diffstat | 2 files changed, 24 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
diff -r 2c08e7e27a70 -r bf9c7111a371 core/src/luan/impl/LuanParser.java --- a/core/src/luan/impl/LuanParser.java Mon Jun 23 20:41:08 2014 +0000 +++ b/core/src/luan/impl/LuanParser.java Tue Jun 24 00:05:53 2014 +0000 @@ -345,7 +345,21 @@ int start = parser.begin(); if( !Keyword("import",In.NOTHING) ) return parser.failure(null); - Expr importExpr = (Expr)nameVar(start,"require").expr(); + Expr importExpr; + { + LuanSource.Element se = se(start); + int index = stackIndex("require"); + if( index != -1 ) { + importExpr = new GetLocalVar(se,index); + } else { + index = upValueIndex("require"); + if( index != -1 ) { + importExpr = new GetUpVar(se,index); + } else { + throw parser.exception("no local 'require' function, needed for import"); + } + } + } String modName = StringLiteral(In.NOTHING); if( modName==null ) return parser.failure(null);
diff -r 2c08e7e27a70 -r bf9c7111a371 core/src/luan/init.luan --- a/core/src/luan/init.luan Mon Jun 23 20:41:08 2014 +0000 +++ b/core/src/luan/init.luan Tue Jun 24 00:05:53 2014 +0000 @@ -8,13 +8,16 @@ local require = Package.global(Package,"require") -function Package.global_import(name) - local mod = require(name) - _G[name] = mod - return mod -end +import "Basic"; _G.Basic = Basic +import "String"; _G.String = String +import "Table"; _G.Table = Table +import "Io"; _G.Io = Io +import "Math"; _G.Math = Basic +import "Html"; _G.Html = Html +import "Thread"; _G.Thread = Thread +import "Binary"; _G.Binary = Binary -local Basic = Package.global_import("Basic","luan.lib.BasicLib.LOADER") + Package.global(Basic,"assert") Package.global(Basic,"assert_boolean") Package.global(Basic,"assert_nil") @@ -41,22 +44,6 @@ do_file "java:luan/version.luan" -local String = Package.global_import("String","luan.lib.StringLib.LOADER") - --- improved global_import -function Package.global_import(name) - local short = name.match("\.([^.]+)$") or name - local mod = require(name) - _G[short] = mod - return mod -end - -local Table = Package.global_import("Table","luan.lib.TableLib.LOADER") -local Io = Package.global_import("Io","luan.lib.IoLib.LOADER") -Package.global_import("Math","luan.lib.MathLib.LOADER") -Package.global_import("Html","luan.lib.HtmlLib.LOADER") -Package.global_import("Thread","luan.lib.ThreadLib.LOADER") -Package.global_import("Binary","luan.lib.BinaryLib.LOADER") function Io.print_to(out,...)