Mercurial Hosting > luan
comparison src/luan/lib/BasicLib.java @ 128:f0a4abe58593
minor
git-svn-id: https://luan-java.googlecode.com/svn/trunk@129 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 08 Jun 2014 03:38:25 +0000 |
parents | 0cd559a16758 |
children | 0594c132888b |
comparison
equal
deleted
inserted
replaced
127:bcb3a09d0caf | 128:f0a4abe58593 |
---|---|
38 add( global, "assert_table", LuanState.class, LuanTable.class ); | 38 add( global, "assert_table", LuanState.class, LuanTable.class ); |
39 add( global, "do_file", LuanState.class, String.class ); | 39 add( global, "do_file", LuanState.class, String.class ); |
40 add( global, "error", LuanState.class, Object.class ); | 40 add( global, "error", LuanState.class, Object.class ); |
41 add( global, "get_metatable", LuanState.class, Object.class ); | 41 add( global, "get_metatable", LuanState.class, Object.class ); |
42 add( global, "ipairs", LuanState.class, LuanTable.class ); | 42 add( global, "ipairs", LuanState.class, LuanTable.class ); |
43 add( global, "load", LuanState.class, String.class, String.class, Boolean.class ); | 43 add( global, "load", LuanState.class, String.class, String.class, Boolean.class, Boolean.class ); |
44 add( global, "load_file", LuanState.class, String.class ); | 44 add( global, "load_file", LuanState.class, String.class ); |
45 add( global, "pairs", LuanState.class, LuanTable.class ); | 45 add( global, "pairs", LuanState.class, LuanTable.class ); |
46 // add( global, "print", LuanState.class, new Object[0].getClass() ); | 46 // add( global, "print", LuanState.class, new Object[0].getClass() ); |
47 add( global, "range", LuanState.class, Double.TYPE, Double.TYPE, Double.class ); | 47 add( global, "range", LuanState.class, Double.TYPE, Double.TYPE, Double.class ); |
48 add( global, "raw_equal", Object.class, Object.class ); | 48 add( global, "raw_equal", Object.class, Object.class ); |
81 */ | 81 */ |
82 public static String type(Object obj) { | 82 public static String type(Object obj) { |
83 return Luan.type(obj); | 83 return Luan.type(obj); |
84 } | 84 } |
85 | 85 |
86 public static LuanFunction load(LuanState luan,String text,String sourceName,Boolean interactive) throws LuanException { | 86 public static LuanFunction load(LuanState luan,String text,String sourceName,Boolean useGlobal,Boolean allowExpr) |
87 if( interactive!=null && interactive ) | 87 throws LuanException |
88 return LuanCompiler.compileInteractive(luan,new LuanSource(sourceName,text)); | 88 { |
89 if( allowExpr==null ) | |
90 allowExpr = false; | |
91 if( useGlobal!=null && useGlobal ) | |
92 return LuanCompiler.compileGlobal(luan,new LuanSource(sourceName,text),allowExpr); | |
89 else | 93 else |
90 return LuanCompiler.compileModule(luan,new LuanSource(sourceName,text)); | 94 return LuanCompiler.compileModule(luan,new LuanSource(sourceName,text),allowExpr); |
91 } | 95 } |
92 | 96 |
93 public static LuanFunction load_file(LuanState luan,String fileName) throws LuanException { | 97 public static LuanFunction load_file(LuanState luan,String fileName) throws LuanException { |
94 try { | 98 try { |
95 String src = fileName==null ? Utils.readAll(new InputStreamReader(System.in)) : new IoLib.LuanFile(fileName).read_text(); | 99 String src = fileName==null ? Utils.readAll(new InputStreamReader(System.in)) : new IoLib.LuanFile(fileName).read_text(); |
96 return load(luan,src,fileName,false); | 100 return load(luan,src,fileName,false,false); |
97 } catch(IOException e) { | 101 } catch(IOException e) { |
98 throw luan.JAVA.exception(e); | 102 throw luan.JAVA.exception(e); |
99 } | 103 } |
100 } | 104 } |
101 | 105 |
102 public static LuanFunction load_java_resource(LuanState luan,String path) throws LuanException { | 106 public static LuanFunction load_java_resource(LuanState luan,String path) throws LuanException { |
103 try { | 107 try { |
104 String src = new IoLib.LuanUrl(IoLib.java_resource_to_url(path)).read_text(); | 108 String src = new IoLib.LuanUrl(IoLib.java_resource_to_url(path)).read_text(); |
105 return load(luan,src,path,false); | 109 return load(luan,src,path,false,false); |
106 } catch(IOException e) { | 110 } catch(IOException e) { |
107 throw luan.JAVA.exception(e); | 111 throw luan.JAVA.exception(e); |
108 } | 112 } |
109 } | 113 } |
110 | 114 |
242 public static LuanFunction values(final Object... args) throws LuanException { | 246 public static LuanFunction values(final Object... args) throws LuanException { |
243 return new LuanFunction() { | 247 return new LuanFunction() { |
244 int i = 0; | 248 int i = 0; |
245 | 249 |
246 @Override public Object call(LuanState luan,Object[] unused) { | 250 @Override public Object call(LuanState luan,Object[] unused) { |
247 return i < args.length ? args[i++] : null; | 251 if( ++i > args.length ) |
252 return LuanFunction.NOTHING; | |
253 return new Object[]{i,args[i-1]}; | |
248 } | 254 } |
249 }; | 255 }; |
250 } | 256 } |
251 | 257 |
252 } | 258 } |