Refactor API's related to compiling and loading scripts and character encoding handling.
This commit is contained in:
@@ -24,11 +24,13 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.Lua;
|
||||
import org.luaj.vm2.lib.jse.JsePlatform;
|
||||
import org.luaj.vm2.luajc.LuaJC;
|
||||
@@ -49,6 +51,7 @@ public class luajc {
|
||||
" -m generate main(String[]) function for JSE\n" +
|
||||
" -r recursively compile all\n" +
|
||||
" -l load classes to verify generated bytecode\n" +
|
||||
" -c enc use the supplied encoding 'enc' for input files\n" +
|
||||
" -v verbose\n";
|
||||
|
||||
private static void usageExit() {
|
||||
@@ -62,8 +65,10 @@ public class luajc {
|
||||
private boolean recurse = false;
|
||||
private boolean verbose = false;
|
||||
private boolean loadclasses = false;
|
||||
private String encoding = null;
|
||||
private String pkgprefix = null;
|
||||
private List files = new ArrayList();
|
||||
private Globals globals;
|
||||
|
||||
public static void main( String[] args ) throws IOException {
|
||||
new luajc( args );
|
||||
@@ -104,6 +109,11 @@ public class luajc {
|
||||
case 'r':
|
||||
recurse = true;
|
||||
break;
|
||||
case 'c':
|
||||
if ( ++i >= args.length )
|
||||
usageExit();
|
||||
encoding = args[i];
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
@@ -140,7 +150,7 @@ public class luajc {
|
||||
}
|
||||
|
||||
// process input files
|
||||
JsePlatform.standardGlobals();
|
||||
globals = JsePlatform.standardGlobals();
|
||||
for ( int i=0,n=files.size(); i<n; i++ )
|
||||
processFile( (InputFile) files.get(i) );
|
||||
}
|
||||
@@ -197,7 +207,9 @@ public class luajc {
|
||||
|
||||
// create the chunk
|
||||
FileInputStream fis = new FileInputStream( inf.infile );
|
||||
final Hashtable t = LuaJC.getInstance().compileAll(fis, inf.luachunkname, inf.srcfilename, genmain);
|
||||
final Hashtable t = encoding != null?
|
||||
LuaJC.instance.compileAll( new InputStreamReader(fis, encoding), inf.luachunkname, inf.srcfilename, globals, genmain):
|
||||
LuaJC.instance.compileAll( fis, inf.luachunkname, inf.srcfilename, globals, genmain);
|
||||
fis.close();
|
||||
|
||||
// write out the chunk
|
||||
|
||||
Reference in New Issue
Block a user