Fixes to class generation logic.

This commit is contained in:
James Roseborough
2009-11-03 02:13:45 +00:00
parent ac91de7794
commit 3d4a29f1bc
3 changed files with 26 additions and 10 deletions

View File

@@ -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 ) {