Mercurial Hosting > luan
comparison src/luan/lib/BasicLib.java @ 149:f99fd64291b3
change load() to take env instead of using global
git-svn-id: https://luan-java.googlecode.com/svn/trunk@150 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 16 Jun 2014 05:47:54 +0000 |
parents | fcb81fa2df0d |
children | 3c95a2291d64 |
comparison
equal
deleted
inserted
replaced
148:dfd0f33b584e | 149:f99fd64291b3 |
---|---|
34 add( global, "assert_table", LuanState.class, LuanTable.class ); | 34 add( global, "assert_table", LuanState.class, LuanTable.class ); |
35 add( global, "do_file", LuanState.class, String.class ); | 35 add( global, "do_file", LuanState.class, String.class ); |
36 add( global, "error", LuanState.class, Object.class ); | 36 add( global, "error", LuanState.class, Object.class ); |
37 add( global, "get_metatable", LuanState.class, Object.class ); | 37 add( global, "get_metatable", LuanState.class, Object.class ); |
38 add( global, "ipairs", LuanState.class, LuanTable.class ); | 38 add( global, "ipairs", LuanState.class, LuanTable.class ); |
39 add( global, "load", LuanState.class, String.class, String.class, Boolean.class, Boolean.class ); | 39 add( global, "load", LuanState.class, String.class, String.class, LuanTable.class, Boolean.class ); |
40 add( global, "load_file", LuanState.class, String.class ); | 40 add( global, "load_file", LuanState.class, String.class ); |
41 add( global, "pairs", LuanState.class, LuanTable.class ); | 41 add( global, "pairs", LuanState.class, LuanTable.class ); |
42 add( global, "range", LuanState.class, Double.TYPE, Double.TYPE, Double.class ); | 42 add( global, "range", LuanState.class, Double.TYPE, Double.TYPE, Double.class ); |
43 add( global, "raw_equal", Object.class, Object.class ); | 43 add( global, "raw_equal", Object.class, Object.class ); |
44 add( global, "raw_get", LuanTable.class, Object.class ); | 44 add( global, "raw_get", LuanTable.class, Object.class ); |
64 | 64 |
65 public static String type(Object obj) { | 65 public static String type(Object obj) { |
66 return Luan.type(obj); | 66 return Luan.type(obj); |
67 } | 67 } |
68 | 68 |
69 public static LuanFunction load(LuanState luan,String text,String sourceName,Boolean useGlobal,Boolean allowExpr) | 69 public static LuanFunction load(LuanState luan,String text,String sourceName,LuanTable env,Boolean allowExpr) |
70 throws LuanException | 70 throws LuanException |
71 { | 71 { |
72 if( allowExpr==null ) | 72 if( allowExpr==null ) |
73 allowExpr = false; | 73 allowExpr = false; |
74 if( useGlobal!=null && useGlobal ) | 74 return LuanCompiler.compile(luan,new LuanSource(sourceName,text),env,allowExpr); |
75 return LuanCompiler.compileGlobal(luan,new LuanSource(sourceName,text),allowExpr); | |
76 else | |
77 return LuanCompiler.compileModule(luan,new LuanSource(sourceName,text),allowExpr); | |
78 } | 75 } |
79 | 76 |
80 public static LuanFunction load_file(LuanState luan,String fileName) throws LuanException { | 77 public static LuanFunction load_file(LuanState luan,String fileName) throws LuanException { |
81 try { | 78 try { |
82 String src = fileName==null ? Utils.readAll(new InputStreamReader(System.in)) : IoLib.luanIo(luan,fileName).read_text(); | 79 String src = fileName==null ? Utils.readAll(new InputStreamReader(System.in)) : IoLib.luanIo(luan,fileName).read_text(); |
83 return load(luan,src,fileName,false,false); | 80 return load(luan,src,fileName,null,false); |
84 } catch(IOException e) { | 81 } catch(IOException e) { |
85 throw luan.exception(e); | 82 throw luan.exception(e); |
86 } | 83 } |
87 } | 84 } |
88 | 85 |