Fixed LuaJC not writing java package to bytecode correctly

This commit is contained in:
UnlegitDqrk
2026-03-01 13:11:33 +01:00
parent 01739d4e77
commit 7338475ae4
4 changed files with 185 additions and 167 deletions

View File

@@ -189,8 +189,10 @@ public class luajc {
public Class findClass(String classname) throws ClassNotFoundException {
byte[] bytes = (byte[]) t.get(classname);
if ( bytes != null )
if ( bytes != null ) {
classname = classname.replace('/', '.');
return defineClass(classname, bytes, 0, bytes.length);
}
return super.findClass(classname);
}
}

View File

@@ -77,7 +77,7 @@ public class JavaBuilder {
private static final String STR_LUATABLE = LuaTable.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_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_LUAVALUE = new ObjectType(STR_LUAVALUE);

View File

@@ -32,13 +32,12 @@ import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Prototype;
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.
* <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}
* 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}.
@@ -60,7 +59,7 @@ import org.luaj.vm2.libs.jse.JsePlatform;
*
* @see Globals#compiler
* @see #install(Globals)
* @see LuaC
* @see org.luaj.vm2.compiler.LuaC
* @see LuaValue
*/
public class LuaJC implements Globals.Loader {
@@ -115,7 +114,24 @@ public class LuaJC implements Globals.Loader {
StringBuffer classname = new StringBuffer();
for (int i = 0, n = stub.length(); i < n; ++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();
}

View File

@@ -61,7 +61,7 @@ public class LuajavaAccessibleMembersTest extends TestCase {
}
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()+"');" +
"return b.SomeEnum"));
}