Mercurial Hosting > luan
comparison src/luan/Luan.java @ 1424:9ab267b9427c
better load_file()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 22 Nov 2019 22:58:39 -0700 |
parents | 27efb1fcbcb5 |
children | d7644b21b128 |
comparison
equal
deleted
inserted
replaced
1423:2c06a7ff4173 | 1424:9ab267b9427c |
---|---|
1 package luan; | 1 package luan; |
2 | 2 |
3 import java.lang.reflect.Array; | 3 import java.lang.reflect.Array; |
4 import java.io.IOException; | |
4 import java.util.List; | 5 import java.util.List; |
5 import java.util.ArrayList; | 6 import java.util.ArrayList; |
6 import java.util.Map; | 7 import java.util.Map; |
7 import java.util.HashMap; | 8 import java.util.HashMap; |
8 import java.util.LinkedHashMap; | 9 import java.util.LinkedHashMap; |
9 import java.util.Iterator; | 10 import java.util.Iterator; |
10 import java.util.Arrays; | 11 import java.util.Arrays; |
11 import java.util.Set; | 12 import java.util.Set; |
12 import goodjava.logging.Logger; | 13 import goodjava.logging.Logger; |
13 import goodjava.logging.LoggerFactory; | 14 import goodjava.logging.LoggerFactory; |
14 import luan.modules.BasicLuan; | |
15 import luan.modules.JavaLuan; | 15 import luan.modules.JavaLuan; |
16 import luan.modules.PackageLuan; | 16 import luan.modules.PackageLuan; |
17 import luan.modules.IoLuan; | |
17 import luan.modules.logging.LuanLogger; | 18 import luan.modules.logging.LuanLogger; |
18 import luan.impl.LuanCompiler; | 19 import luan.impl.LuanCompiler; |
19 | 20 |
20 | 21 |
21 public final class Luan implements LuanCloneable { | 22 public final class Luan implements LuanCloneable { |
169 | 170 |
170 | 171 |
171 // static | 172 // static |
172 | 173 |
173 public static void main(String[] args) throws LuanException { | 174 public static void main(String[] args) throws LuanException { |
174 doFile( "classpath:luan/cmd_line.luan", args ); | |
175 } | |
176 | |
177 public static void doFile(String uri,String... args) throws LuanException { | |
178 Luan luan = new Luan(); | 175 Luan luan = new Luan(); |
179 LuanFunction fn = (LuanFunction)BasicLuan.load_file(luan,uri); | 176 LuanFunction fn = loadClasspath(luan,"luan/cmd_line.luan"); |
180 fn.call((Object[])args); | 177 fn.call((Object[])args); |
178 } | |
179 | |
180 public static LuanFunction loadClasspath(Luan luan,String classpath) | |
181 throws LuanException | |
182 { | |
183 try { | |
184 String src = IoLuan.classpath(luan,classpath).read_text(); | |
185 return luan.load(src,"classpath:"+classpath); | |
186 } catch(IOException e) { | |
187 throw new RuntimeException(e); | |
188 } | |
181 } | 189 } |
182 | 190 |
183 public static Object first(Object obj) { | 191 public static Object first(Object obj) { |
184 if( !(obj instanceof Object[]) ) | 192 if( !(obj instanceof Object[]) ) |
185 return obj; | 193 return obj; |