Fixed LuaJC not writing java package to bytecode correctly
This commit is contained in:
@@ -189,8 +189,10 @@ public class luajc {
|
|||||||
|
|
||||||
public Class findClass(String classname) throws ClassNotFoundException {
|
public Class findClass(String classname) throws ClassNotFoundException {
|
||||||
byte[] bytes = (byte[]) t.get(classname);
|
byte[] bytes = (byte[]) t.get(classname);
|
||||||
if ( bytes != null )
|
if ( bytes != null ) {
|
||||||
|
classname = classname.replace('/', '.');
|
||||||
return defineClass(classname, bytes, 0, bytes.length);
|
return defineClass(classname, bytes, 0, bytes.length);
|
||||||
|
}
|
||||||
return super.findClass(classname);
|
return super.findClass(classname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class JavaBuilder {
|
|||||||
private static final String STR_LUATABLE = LuaTable.class.getName();
|
private static final String STR_LUATABLE = LuaTable.class.getName();
|
||||||
private static final String STR_BUFFER = Buffer.class.getName();
|
private static final String STR_BUFFER = Buffer.class.getName();
|
||||||
private static final String STR_STRING = String.class.getName();
|
private static final String STR_STRING = String.class.getName();
|
||||||
private static final String STR_JSEPLATFORM = "org.luaj.vm2.lib.jse.JsePlatform";
|
private static final String STR_JSEPLATFORM = "org.luaj.vm2.libs.jse.JsePlatform";
|
||||||
|
|
||||||
private static final ObjectType TYPE_VARARGS = new ObjectType(STR_VARARGS);
|
private static final ObjectType TYPE_VARARGS = new ObjectType(STR_VARARGS);
|
||||||
private static final ObjectType TYPE_LUAVALUE = new ObjectType(STR_LUAVALUE);
|
private static final ObjectType TYPE_LUAVALUE = new ObjectType(STR_LUAVALUE);
|
||||||
|
|||||||
@@ -32,13 +32,12 @@ import org.luaj.vm2.LuaFunction;
|
|||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
import org.luaj.vm2.Prototype;
|
import org.luaj.vm2.Prototype;
|
||||||
import org.luaj.vm2.compiler.LuaC;
|
import org.luaj.vm2.compiler.LuaC;
|
||||||
import org.luaj.vm2.libs.jse.JsePlatform;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link Globals.Compiler} which does direct
|
* Implementation of {@link org.luaj.vm2.Globals.Compiler} which does direct
|
||||||
* lua-to-java-bytecode compiling.
|
* lua-to-java-bytecode compiling.
|
||||||
* <p>
|
* <p>
|
||||||
* By default, when using {@link JsePlatform} or
|
* By default, when using {@link org.luaj.vm2.libs.jse.JsePlatform} or
|
||||||
* {@link org.luaj.vm2.libs.jme.JmePlatform}
|
* {@link org.luaj.vm2.libs.jme.JmePlatform}
|
||||||
* to construct globals, the plain compiler {@link LuaC} is installed and lua code
|
* to construct globals, the plain compiler {@link LuaC} is installed and lua code
|
||||||
* will only be compiled into lua bytecode and execute as {@link LuaClosure}.
|
* will only be compiled into lua bytecode and execute as {@link LuaClosure}.
|
||||||
@@ -60,7 +59,7 @@ import org.luaj.vm2.libs.jse.JsePlatform;
|
|||||||
*
|
*
|
||||||
* @see Globals#compiler
|
* @see Globals#compiler
|
||||||
* @see #install(Globals)
|
* @see #install(Globals)
|
||||||
* @see LuaC
|
* @see org.luaj.vm2.compiler.LuaC
|
||||||
* @see LuaValue
|
* @see LuaValue
|
||||||
*/
|
*/
|
||||||
public class LuaJC implements Globals.Loader {
|
public class LuaJC implements Globals.Loader {
|
||||||
@@ -115,7 +114,24 @@ public class LuaJC implements Globals.Loader {
|
|||||||
StringBuffer classname = new StringBuffer();
|
StringBuffer classname = new StringBuffer();
|
||||||
for (int i = 0, n = stub.length(); i < n; ++i) {
|
for (int i = 0, n = stub.length(); i < n; ++i) {
|
||||||
final char c = stub.charAt(i);
|
final char c = stub.charAt(i);
|
||||||
classname.append((((i == 0) && Character.isJavaIdentifierStart(c)) || ((i > 0) && Character.isJavaIdentifierPart(c)))? c: '_');
|
switch(i) {
|
||||||
|
case 0:
|
||||||
|
if(Character.isJavaIdentifierStart(c)) {
|
||||||
|
classname.append(c);
|
||||||
|
} else {
|
||||||
|
classname.append('_');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if(c == '/') {
|
||||||
|
classname.append(c);
|
||||||
|
} else if(Character.isJavaIdentifierPart(c)) {
|
||||||
|
classname.append(c);
|
||||||
|
} else {
|
||||||
|
classname.append('_');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return classname.toString();
|
return classname.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class LuajavaAccessibleMembersTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAccessPublicEnum() {
|
public void testAccessPublicEnum() {
|
||||||
assertEquals("class org.luaj.vm2.lib.jse.TestClass$SomeEnum", invokeScript(
|
assertEquals("class org.luaj.vm2.libs.jse.TestClass$SomeEnum", invokeScript(
|
||||||
"b = luajava.newInstance('"+TestClass.class.getName()+"');" +
|
"b = luajava.newInstance('"+TestClass.class.getName()+"');" +
|
||||||
"return b.SomeEnum"));
|
"return b.SomeEnum"));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user