diff --git a/src/jse/luajc.java b/src/jse/luajc.java index 24ab4779..9f89404f 100644 --- a/src/jse/luajc.java +++ b/src/jse/luajc.java @@ -25,12 +25,15 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.Enumeration; +import java.util.Hashtable; import org.luaj.vm2.Lua; import org.luaj.vm2.compiler.DumpState; import org.luaj.vm2.luajc.JavaBytecodeCompiler; + /** * Compiler for lua files to compile lua sources into java sources. */ @@ -152,13 +155,20 @@ public class luajc { private void processScript( InputStream script, String chunkname, OutputStream out ) throws IOException { try { // create the chunk - byte[] bytes = JavaBytecodeCompiler.loadClass(script, chunkname); + Hashtable t = JavaBytecodeCompiler.loadClasses(script, chunkname); // write out the chunk if (!parseonly) { - FileOutputStream fos = new FileOutputStream( chunkname+".java" ); - fos.write( bytes ); - fos.close(); + for ( Enumeration e = t.keys(); e.hasMoreElements(); ) { + String key = (String) e.nextElement(); + byte[] bytes = (byte[]) t.get(key); + String filename = key + ".class"; + if ( versioninfo ) + System.out.println(filename+": "+bytes.length+" bytes"); + FileOutputStream fos = new FileOutputStream( filename ); + fos.write( bytes ); + fos.close(); + } } } catch ( Throwable t ) { diff --git a/src/jse/org/luaj/vm2/luajc/JavaBytecodeCompiler.java b/src/jse/org/luaj/vm2/luajc/JavaBytecodeCompiler.java index c9abb865..9f32336b 100644 --- a/src/jse/org/luaj/vm2/luajc/JavaBytecodeCompiler.java +++ b/src/jse/org/luaj/vm2/luajc/JavaBytecodeCompiler.java @@ -94,17 +94,18 @@ public class JavaBytecodeCompiler implements LuaCompiler { /** Compile all classes produced by a prototype, and put results in a hashtable */ public static Hashtable loadClasses( InputStream stream, String filename ) throws IOException { + if ( LoadState.compiler == null ) + install(); Prototype p = LoadState.compile( stream, filename ); Hashtable t = new Hashtable(); getInstance().genClass(t, p, toClassname(filename), toSourcename(filename)); return t; } - private void genClass( Hashtable t, Prototype p, String className, String sourceName ) throws IOException { - for ( int i=0, n=p.p!=null? p.p.length: 0; i