Mercurial Hosting > luan
changeset 462:2e79b47d02a2
remove all command line options;
add add_extension boolean arg to scheme fns;
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 06 May 2015 16:54:20 -0600 |
parents | e12841f7edef |
children | 895afcd2b281 |
files | core/src/luan/cmd_line.luan core/src/luan/modules/BasicLuan.java core/src/luan/modules/IoLuan.java core/src/luan/modules/PackageLuan.java web/src/luan/modules/web/Server.luan |
diffstat | 5 files changed, 37 insertions(+), 89 deletions(-) [+] |
line wrap: on
line diff
diff -r e12841f7edef -r 2e79b47d02a2 core/src/luan/cmd_line.luan --- a/core/src/luan/cmd_line.luan Wed May 06 14:51:23 2015 -0600 +++ b/core/src/luan/cmd_line.luan Wed May 06 16:54:20 2015 -0600 @@ -1,82 +1,27 @@ local Luan = require "luan:Luan" local ipairs = Luan.ipairs -local load = Luan.load local load_file = Luan.load_file local try = Luan.try -require "luan:String" -- for String methods local Table = require "luan:Table" local Io = require "luan:Io" local print = Io.print local Debug = require "luan:Debug" -local standalone_usage = [=[ -usage: java luan.Luan [options] [script-URI [args]] -Available options are: - -e stat execute string 'stat' - -i enter interactive mode after executing 'script' - -v show version information - -- stop handling options - - stop handling options and execute stdin -]=] - -local function standalone_error(msg) - Io.stderr.write( msg, "\n", standalone_usage ) -end - - local args = {...} -local interactive = false -local showVersion = false -local i = 1 if #args == 0 then - interactive = true - showVersion = true + print(Luan.VERSION) + Debug.debug("> ") else - while i <= #args do - local arg = args[i] - if arg.sub(1,1) ~= "-" or arg == "--" then - break - end - if arg == "-i" then - interactive = true - elseif arg == "-v" then - showVersion = true - elseif arg == "-e" then - i = i + 1 - if i > #args then - standalone_error "'-e' needs argument" - return - end - local cmd = args[i] - local stat = load(cmd,"(command line)",{},true) - local result = Table.pack( stat() ) - if result.n > 0 then - print( Table.unpack(result,1,result.n) ) - end - elseif arg == "-" then - local src = Io.stdin.read_text() - local stdin = load(src,"stdin") - stdin() - return - else - standalone_error( "unrecognized option '"..arg.."'" ) - return - end - i = i + 1 - end -end -if showVersion then print(Luan.VERSION) end -if i <= #args then - local file = args[i] + local file = args[1] Luan.arg = {} for j,v in ipairs(args) do - Luan.arg[j-i] = v + Luan.arg[j-1] = v end try { function() - local main_file = load_file(file..".luan") - main_file( Table.unpack(Luan.arg) ) + local main_file = load_file(file,true) + Debug.print_if_something( main_file( Table.unpack(Luan.arg) ) ) end; catch = function(e) -- java(); e.printStackTrace(); return @@ -84,6 +29,3 @@ end; } end -if interactive then - Debug.debug("> ") -end
diff -r e12841f7edef -r 2e79b47d02a2 core/src/luan/modules/BasicLuan.java --- a/core/src/luan/modules/BasicLuan.java Wed May 06 14:51:23 2015 -0600 +++ b/core/src/luan/modules/BasicLuan.java Wed May 06 16:54:20 2015 -0600 @@ -34,13 +34,13 @@ return LuanCompiler.compile(luan,new LuanSource(sourceName,text),env,allowExpr); } - public static LuanFunction load_file(LuanState luan,String fileName,LuanTable env) throws LuanException { + public static LuanFunction load_file(LuanState luan,String fileName,Boolean addExtension) throws LuanException { if( fileName == null ) fileName = "stdin:"; - String src = PackageLuan.read(luan,fileName); + String src = PackageLuan.read(luan,fileName,addExtension); if( src == null ) throw luan.exception( "file '"+fileName+"' not found" ); - return load(luan,src,fileName,env,false); + return load(luan,src,fileName,null,false); } public static Object do_file(LuanState luan,String fileName) throws LuanException {
diff -r e12841f7edef -r 2e79b47d02a2 core/src/luan/modules/IoLuan.java --- a/core/src/luan/modules/IoLuan.java Wed May 06 14:51:23 2015 -0600 +++ b/core/src/luan/modules/IoLuan.java Wed May 06 16:54:20 2015 -0600 @@ -492,14 +492,18 @@ return new LuanString(s).table(); } - public static LuanTable file(LuanState luan,String name) throws LuanException { + public static LuanTable file(LuanState luan,String name,Boolean addExtension) throws LuanException { + if( addExtension != null && addExtension ) + name += ".luan"; File file = new File(name); return new LuanFile(file).table(); } - public static LuanTable classpath(LuanState luan,String name) throws LuanException { + public static LuanTable classpath(LuanState luan,String name,Boolean addExtension) throws LuanException { if( name.contains("//") ) return null; + if( addExtension != null && addExtension ) + name += ".luan"; String path = name; check(luan,"classpath:"+path); URL url; @@ -528,20 +532,22 @@ return null; } - private static LuanTable url(String url) throws IOException { + private static LuanTable url(String url,Boolean addExtension) throws IOException { + if( addExtension != null && addExtension ) + url += ".luan"; return new LuanUrl(new URL(url)).table(); } - public static LuanTable http(String path) throws IOException { - return url("http:"+path); + public static LuanTable http(String path,Boolean addExtension) throws IOException { + return url("http:"+path,addExtension); } - public static LuanTable https(String path) throws IOException { - return url("https:"+path); + public static LuanTable https(String path,Boolean addExtension) throws IOException { + return url("https:"+path,addExtension); } - public static LuanTable luan(LuanState luan,String path) throws LuanException { - return classpath( luan, "luan/modules/" + path ); + public static LuanTable luan(LuanState luan,String path,Boolean addExtension) throws LuanException { + return classpath( luan, "luan/modules/" + path, addExtension ); } public static LuanTable stdin(LuanState luan) throws LuanException { @@ -553,12 +559,12 @@ LuanTable schemes = new LuanTable(); try { add( schemes, "string", LuanState.class, String.class ); - add( schemes, "file", LuanState.class, String.class ); - add( schemes, "classpath", LuanState.class, String.class ); + add( schemes, "file", LuanState.class, String.class, Boolean.class ); + add( schemes, "classpath", LuanState.class, String.class, Boolean.class ); add( schemes, "socket", LuanState.class, String.class ); - add( schemes, "http", String.class ); - add( schemes, "https", String.class ); - add( schemes, "luan", LuanState.class, String.class ); + add( schemes, "http", String.class, Boolean.class ); + add( schemes, "https", String.class, Boolean.class ); + add( schemes, "luan", LuanState.class, String.class, Boolean.class ); add( schemes, "stdin", LuanState.class ); } catch(NoSuchMethodException e) { throw new RuntimeException(e); @@ -576,17 +582,17 @@ return t; } - public static LuanTable uri(LuanState luan,String name) throws LuanException { + public static LuanTable uri(LuanState luan,String name,Boolean addExtension) throws LuanException { int i = name.indexOf(':'); if( i == -1 ) - throw luan.exception( "invalid Io name '"+name+"', missing scheme" ); + throw luan.exception( "invalid Io.uri name '"+name+"', missing scheme" ); String scheme = name.substring(0,i); String location = name.substring(i+1); LuanTable schemes = schemes(luan); LuanFunction opener = (LuanFunction)schemes.get(luan,scheme); if( opener == null ) throw luan.exception( "invalid scheme '"+scheme+"' in '"+name+"'" ); - return (LuanTable)Luan.first(luan.call(opener,"<open \""+name+"\">",new Object[]{location})); + return (LuanTable)Luan.first(luan.call(opener,"<open \""+name+"\">",new Object[]{location,addExtension})); } public static final class LuanSocket extends LuanIO {
diff -r e12841f7edef -r 2e79b47d02a2 core/src/luan/modules/PackageLuan.java --- a/core/src/luan/modules/PackageLuan.java Wed May 06 14:51:23 2015 -0600 +++ b/core/src/luan/modules/PackageLuan.java Wed May 06 16:54:20 2015 -0600 @@ -46,7 +46,7 @@ if( modName.startsWith("java:") ) { mod = JavaLuan.load(luan,modName.substring(5)); } else { - String src = read(luan,modName+".luan"); + String src = read(luan,modName,true); if( src == null ) return null; LuanTable env = new LuanTable(); @@ -61,8 +61,8 @@ return mod; } - static String read(LuanState luan,String uri) throws LuanException { - LuanTable t = IoLuan.uri(luan,uri); + static String read(LuanState luan,String uri,Boolean addExtension) throws LuanException { + LuanTable t = IoLuan.uri(luan,uri,addExtension); if( t == null ) return null; LuanFunction existsFn = (LuanFunction)t.get(luan,"exists");
diff -r e12841f7edef -r 2e79b47d02a2 web/src/luan/modules/web/Server.luan --- a/web/src/luan/modules/web/Server.luan Wed May 06 14:51:23 2015 -0600 +++ b/web/src/luan/modules/web/Server.luan Wed May 06 16:54:20 2015 -0600 @@ -72,8 +72,8 @@ function init(dir) dir = dir.gsub("/$","") -- remove trailing '/' if any Http.dir = dir - function Io.schemes.site(path) - return Io.uri( dir..path ) + function Io.schemes.site(path,add_extension) + return Io.uri( dir..path, add_extension ) end authentication_handler.setPassword(private_password) local base = dir