Expose class name normalization.
This commit is contained in:
@@ -32,6 +32,7 @@ import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Prototype;
|
||||
import org.luaj.vm2.LoadState.LuaCompiler;
|
||||
import org.luaj.vm2.compiler.LuaC;
|
||||
import org.luaj.vm2.lib.PackageLib;
|
||||
|
||||
public class JavaBytecodeCompiler implements LuaCompiler {
|
||||
|
||||
@@ -89,7 +90,7 @@ public class JavaBytecodeCompiler implements LuaCompiler {
|
||||
/** Compile into a class */
|
||||
private byte[] loadClass(int firstByte, InputStream stream, String filename) throws IOException {
|
||||
Prototype p = compile(firstByte, stream, filename);
|
||||
return gen.generateBytecode(p, toClassname(filename), toSourcename(filename));
|
||||
return gen.generateBytecode(p, PackageLib.toClassname(filename), toSourcename(filename));
|
||||
}
|
||||
|
||||
/** Compile all classes produced by a prototype, and put results in a hashtable */
|
||||
@@ -98,7 +99,7 @@ public class JavaBytecodeCompiler implements LuaCompiler {
|
||||
install();
|
||||
Prototype p = LoadState.compile( stream, filename );
|
||||
Hashtable t = new Hashtable();
|
||||
getInstance().genClass(t, p, toClassname(filename), toSourcename(filename));
|
||||
getInstance().genClass(t, p, PackageLib.toClassname(filename), toSourcename(filename));
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -110,7 +111,7 @@ public class JavaBytecodeCompiler implements LuaCompiler {
|
||||
|
||||
public LuaFunction load(Prototype p, String filename, LuaValue env) {
|
||||
try {
|
||||
Class c = gen.toJavaBytecode(p, toClassname(filename), toSourcename(filename));
|
||||
Class c = gen.toJavaBytecode(p, PackageLib.toClassname(filename), toSourcename(filename));
|
||||
Object o = c.newInstance();
|
||||
LuaFunction f = (LuaFunction) o;
|
||||
f.setfenv(env);
|
||||
@@ -121,16 +122,6 @@ public class JavaBytecodeCompiler implements LuaCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Convert filename to class name */
|
||||
private static final String toClassname( String filename ) {
|
||||
String classname = filename.endsWith(".lua")? filename.substring(0,filename.length()-4): filename;
|
||||
classname = classname.replace('/', '.');
|
||||
classname = classname.replace('\\', '.');
|
||||
classname = classname.replaceAll("[^\\w\\.]", "_");
|
||||
return classname;
|
||||
}
|
||||
|
||||
private static final String toSourcename( String filename ) {
|
||||
return filename.substring( filename.lastIndexOf('/')+1 );
|
||||
}
|
||||
|
||||
@@ -65,7 +65,9 @@ import org.luaj.vm2.lib.VarArgFunction;
|
||||
|
||||
public class JavaBytecodeGenerator {
|
||||
public static boolean DUMPCLASSES = "true".equals(System.getProperty("DUMPCLASSES"));
|
||||
|
||||
|
||||
public static boolean gendebuginfo = true;
|
||||
|
||||
private static final String STR_FUNCV = VarArgFunction.class.getName();
|
||||
private static final String STR_VARARGS = Varargs.class.getName();
|
||||
private static final String STR_LUAVALUE = LuaValue.class.getName();
|
||||
@@ -928,10 +930,12 @@ public class JavaBytecodeGenerator {
|
||||
}
|
||||
|
||||
// add line numbers
|
||||
if ( p.lineinfo != null && p.lineinfo.length >= nc) {
|
||||
for ( pc=0; pc<nc; pc++ ) {
|
||||
if ( ih[pc] != null )
|
||||
mg.addLineNumber( ih[pc], p.lineinfo[pc] );
|
||||
if ( gendebuginfo ) {
|
||||
if ( p.lineinfo != null && p.lineinfo.length >= nc) {
|
||||
for ( pc=0; pc<nc; pc++ ) {
|
||||
if ( ih[pc] != null )
|
||||
mg.addLineNumber( ih[pc], p.lineinfo[pc] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1199,10 +1203,12 @@ public class JavaBytecodeGenerator {
|
||||
|
||||
private String getlocalname(LocVars[] locvars, int j) {
|
||||
int number = j+1;
|
||||
for (int i = 0; i < locvars.length; i++) {
|
||||
if (pc < locvars[i].endpc) { /* is variable active? */
|
||||
if (--number == 0)
|
||||
return locvars[i].varname.toString();
|
||||
if ( gendebuginfo ) {
|
||||
for (int i = 0; i < locvars.length; i++) {
|
||||
if (pc < locvars[i].endpc) { /* is variable active? */
|
||||
if (--number == 0)
|
||||
return locvars[i].varname.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "$"+j;
|
||||
|
||||
Reference in New Issue
Block a user