Add options to load to prototype

This commit is contained in:
James Roseborough
2009-11-03 01:16:46 +00:00
parent c78d789cdc
commit ac91de7794
2 changed files with 28 additions and 10 deletions

View File

@@ -23,11 +23,11 @@ package org.luaj.vm2.luajc;
import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;
import org.luaj.vm2.LoadState;
import org.luaj.vm2.LuaClosure;
import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Prototype;
import org.luaj.vm2.LoadState.LuaCompiler;
@@ -92,7 +92,21 @@ public class JavaBytecodeCompiler implements LuaCompiler {
return gen.generateBytecode(p, toClassname(filename), toSourcename(filename));
}
/** Compile all classes produced by a prototype, and put results in a hashtable */
public static Hashtable loadClasses( InputStream stream, String filename ) throws IOException {
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<n; i++ ) {
String name = className + "$" + i;
t.put( name, gen.generateBytecode( p.p[i], name, sourceName ) );
}
}
public LuaFunction load(Prototype p, String filename, LuaValue env) {
try {
Class c = gen.toJavaBytecode(p, toClassname(filename), toSourcename(filename));